Merge pull request #949 from tfendin/git-ignore-ensure-newline

This commit is contained in:
罗泽轩 2022-01-03 21:24:34 +08:00 committed by GitHub
commit b772251074
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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"