Skip to content

Commit

Permalink
Merge pull request #949 from tfendin/git-ignore-ensure-newline
Browse files Browse the repository at this point in the history
  • Loading branch information
spacewander authored Jan 3, 2022
2 parents e370b19 + fff5fde commit b772251
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bin/git-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ function add_private {
function add_patterns {
echo "Adding pattern(s) to: $1"
local file="${1/#~/$HOME}"
if [ -s "$file" ]; then
# If the content of $file doesn't end with a newline, add one
test "$(tail -c 1 "$file")" != "" && echo "" >> "$file"
fi
for pattern in "${@:2}"; do
echo "... adding '$pattern'"
(test -f "$file" && test "$pattern" && grep -q -F -x -- "$pattern" "$file") || echo "$pattern" >> "$file"
Expand Down

0 comments on commit b772251

Please sign in to comment.