Skip to contentSkip to conversation

Fix git-add argument parsing

PATCH New Timo Hirvonen 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix git-add argument parsing

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

---

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

60d2803555831a9a9bfa2d97cec5ab2fbed1fb2c

git-add.sh +30 -14
@@ -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