threads / patch / 3343

patchDetect misspelled pathspec to git-add

Subject: [PATCH] Detect misspelled pathspec to git-add

## tl;dr

2 messages between Feb 15, 2006 and Feb 15, 2006. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Junio C Hamano· Feb 15, 2006, 09:14 UTC · lore

This is in the same spirit as an earlier patch for git-commit. It does an extra ls-files to avoid complaining when a fully tracked directory name is given on the command line (otherwise --others restriction would say the pathspec does not match).

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 * I noticed this when I accidentally said "git add /a/b/c"
   when I meant "git add a/b/c", and I did not notice it until
   I said "git commit" which said "Nothing to commit."
   It does one extra ls-files only if any pathspec is given; I
   am hoping this slight performance hit is tolerated.  I think
   people who does "git add ." all the time to mean "add
   everything I added anywhere since I did git add last time"
   deserve it ;-).
   Comments?
 git-add.sh |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
ca28a7e03232b9a3b66df8519d9ee827882c83c1
Show changes to git-add.sh +11 −0
diff --git a/git-add.sh b/git-add.sh
index f719b4b..13fad82 100755
--- a/git-add.sh
+++ b/git-add.sh
@@ -24,6 +24,17 @@ while : ; do
   shift
 done
 
+# Check misspelled pathspec
+case "$#" in
+0)	;;
+*)
+	git-ls-files --error-unmatch --others --cached -- "$@" >/dev/null || {
+		echo >&2 "Maybe you misspelled it?"
+		exit 1
+	}
+	;;
+esac
+
 if test -f "$GIT_DIR/info/exclude"
 then
 	git-ls-files -z \
-- 
1.2.0.gcfba7

← back to recent threads