DORMANTno replies

[PATCH] Fix git-add argument parsing

From: Timo Hirvonen <hidden>
Date: 2016-06-15 22:42:07
Subsystem: the rest · Maintainer: Linus Torvalds

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

Signed-off-by: Timo Hirvonen <redacted>

---

 git-add.sh |   44 ++++++++++++++++++++++++++++++--------------
 1 files changed, 30 insertions(+), 14 deletions(-)

60d2803555831a9a9bfa2d97cec5ab2fbed1fb2c
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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help