threads / patch / 1964

patchFix git-add argument parsing

Subject: [PATCH] Fix git-add argument parsing

## tl;dr

One message between Sep 28, 2005 and Sep 28, 2005. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

Timo Hirvonen· Sep 28, 2005, 14:27 UTC · lore

Complain if no arguments given instead of adding all files to the index.

Signed-off-by: Timo Hirvonen <tihirvon@gmail.com>
---
 git-add.sh |   44 ++++++++++++++++++++++++++++++--------------
 1 files changed, 30 insertions(+), 14 deletions(-)
60d2803555831a9a9bfa2d97cec5ab2fbed1fb2c
Show changes to git-add.sh +30 −14
diff --git a/git-add.sh b/git-add.sh
--- a/git-add.sh
+++ b/git-add.sh
@@ -1,23 +1,39 @@
 #!/bin/sh
 
+usage()
+{
+	echo "usage: git add [-n] [-v] <file>..."
+	exit 1
+}
+
 show_only=
 verbose=
-while : ; do
-  case "$1" in
-    -n)
-	show_only=true
-	verbose=true
-	;;
-    -v)
-	verbose=true
-	;;
-    *)
-	break
-	;;
-  esac
-  shift
+while test $# -gt 0
+do
+	case "$1" in
+	-n)
+		show_only=true
+		verbose=true
+		;;
+	-v)
+		verbose=true
+		;;
+	--)
+		shift
+		break
+		;;
+	-*)
+		usage
+		;;
+	*)
+		break
+		;;
+	esac
+	shift
 done
 
+test $# -eq 0 && usage
+
 GIT_DIR=$(git-rev-parse --git-dir) || exit
 global_exclude=
 if [ -f "$GIT_DIR/info/exclude" ]; then

← back to recent threads