git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Fix git-add argument parsing

From
THTimo Hirvonen <tihirvon@gmail.com>
Date
Sep 28, 2005, 14:27 UTC
Message-ID
<20050928172753.0e883738.tihirvon@gmail.com>

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
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
Message 1 of 1 in “Fix git-add argument parsing”
  1. Fix git-add argument parsingTimo Hirvonen, Sep 28, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.