From 11640196b238b88110a53f75a2fdc09c948c3a06 Mon Sep 17 00:00:00 2001 From: Tobias Fendin Date: Wed, 29 Dec 2021 15:07:19 +0100 Subject: [PATCH 1/2] git-ignore: ensure new patterns comes after a newline --- bin/git-ignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bin/git-ignore b/bin/git-ignore index d19b44fda..2e5c9b5dc 100755 --- a/bin/git-ignore +++ b/bin/git-ignore @@ -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" From fff5fde917d2c343edec55092b542517f5a799d8 Mon Sep 17 00:00:00 2001 From: tfendin <52978364+tfendin@users.noreply.github.com> Date: Thu, 30 Dec 2021 12:47:29 +0100 Subject: [PATCH 2/2] Clarified comment of when newline should be added MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 罗泽轩 --- bin/git-ignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/git-ignore b/bin/git-ignore index 2e5c9b5dc..454949818 100755 --- a/bin/git-ignore +++ b/bin/git-ignore @@ -58,7 +58,7 @@ 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 + # 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