From 7398d10bd4a19587eb068393123fdfb1b3bbdc15 Mon Sep 17 00:00:00 2001 From: nickl- Date: Sat, 21 Jul 2012 13:34:35 +0200 Subject: [PATCH] Fix #127 git-ignore won't add duplicates. As per the bug identified in #127 git-ignore would add duplicate entries in .gitignore which is redundant and should not happen. grep will suitably verify that the entry doesn't exit but only if the file actually exists or we will get an error on stderr. check if the file exists with test -f and that the new entry is present or alternatively just go ahead and add the new value which will create the file if it didn't exist. Running the same command again does not add the duplicate. --- bin/git-ignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/git-ignore b/bin/git-ignore index 84166f5..e0c1474 100755 --- a/bin/git-ignore +++ b/bin/git-ignore @@ -5,6 +5,6 @@ if test $# -eq 0; then else for pattern in $@; do echo "... adding '$pattern' to .gitignore" - echo $pattern >> .gitignore + (test -f .gitignore && grep -q $pattern .gitignore) || echo $pattern >> .gitignore done fi