Re: [PATCH] git-tag: Fix the main while loop exit condition.

Subsystems: the rest

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH] git-tag: Fix the main while loop exit condition.

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:43:18

Thanks.

I think you would need something like this on top if you want to
really fix it, though.

I also suspect that we should error out on:

	$ git tag -l foo bar

but that will be left as an exercise to the readers ;-)
diff --git a/git-tag.sh b/git-tag.sh
index bc0d735..48b54a1 100755
--- a/git-tag.sh
+++ b/git-tag.sh
@@ -14,7 +14,8 @@ username=
 list=
 verify=
 LINES=0
-while [ $# -ne 0 ]; do
+while case "$#" in 0) break ;; esac
+do
     case "$1" in
     -a)
 	annotate=1
@@ -30,8 +31,9 @@ while [ $# -ne 0 ]; do
 	shift
 	;;
     -n)
-        case $2 in
-	-*)	LINES=1 	# no argument
+        case "$#,$2" in
+	1,* | *,-*)
+		LINES=1 	# no argument
 		;;
 	*)	shift
 		LINES=$(expr "$1" : '\([0-9]*\)')
@@ -43,7 +45,14 @@ while [ $# -ne 0 ]; do
     -l)
 	list=1
 	shift
-	PATTERN="$1"	# select tags by shell pattern, not re
+	case $# in
+	0)	PATTERN=
+		;;
+	*)
+		PATTERN="$1"	# select tags by shell pattern, not re
+		shift
+		;;
+	esac
 	git rev-parse --symbolic --tags | sort |
 	    while read TAG
 	    do

Re: [PATCH] git-tag: Fix the main while loop exit condition.

From: Sam Vilain <hidden>
Date: 2016-06-15 22:43:18

Junio C Hamano wrote:
Thanks.

I think you would need something like this on top if you want to
really fix it, though.

I also suspect that we should error out on:

	$ git tag -l foo bar

but that will be left as an exercise to the readers ;-)
More is required...
diff --git a/git-tag.sh b/git-tag.sh
index 48b54a1..480d16d 100755
--- a/git-tag.sh
+++ b/git-tag.sh
@@ -82,7 +82,9 @@ do
 	if test "$#" = "0"; then
 	    die "error: option -m needs an argument"
 	else
+	    message="$1"
 	    message_given=1
+	    shift
 	fi
 	;;
     -F)
@@ -93,13 +95,19 @@ do
 	else
 	    message="$(cat "$1")"
 	    message_given=1
+	    shift
 	fi
 	;;
     -u)
 	annotate=1
 	signed=1
 	shift
-	username="$1"
+	if test "$#" = "0"; then
+	    die "error: option -u needs an argument"
+	else
+	    username="$1"
+	    shift
+	fi
 	;;
     -d)
 	shift
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help