Skip to content

Commit

Permalink
git-ignore: ensure new patterns comes after a newline
Browse files Browse the repository at this point in the history
tfendin committed Dec 29, 2021
1 parent 2370a4e commit 1164019
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
@@ -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 $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"

0 comments on commit 1164019

Please sign in to comment.