Skip to contentSkip to conversation

git-am: emit usage when called w/o arguments and w/o patch on stdin

PATCH Superseded Jay Soffian 3 participants 8 messages Jun 15, 2016

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 git-am: emit usage when called w/o arguments and w/o patch on stdin

When git am is called w/o arguments, w/o a patch on stdin and the user hits ctrl-c, it leaves behind a partially populated $dotest directory. After this commit, it emits usage when called w/o arguments and w/o a patch on stdin.

Also ensure that $dotest is cleaned up if user manages to interupt mailsplit while it is processing input, but not if mailsplit exits non-zero due to error.

Noticed by Sverre Rabbelier

---
Change from v1: don't remove $dotest if mailsplit exits non-zero

 git-am.sh |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
git-am.sh +5 -2
index b1c05c9..65285a0 100755
@@ -254,10 +254,13 @@ else
 		done
 		shift
 	fi
-	git mailsplit -d"$prec" -o"$dotest" -b -- "$@" > "$dotest/last" ||  {
-		rm -fr "$dotest"
+	test $# = 0 && test -t 0 && usage
+	trap 'rm -fr "$dotest"' 0
+	git mailsplit -d"$prec" -o"$dotest" -b -- "$@" > "$dotest/last" || {
+		trap - 0
 		exit 1
 	}
+	trap - 0
 
 	# -s, -u, -k, --whitespace, -3, -C and -p flags are kept
 	# for the resuming session after a patch failure.
Signature · 1 line
1.6.1.224.gb56c
#1 lore raw

PATCH v2 2/2 git-am: minor cleanups

Update usage statement to remove a no-longer supported option, and to hide two options (one a no-op, one internal) unless --help-all is used.

Use "test -t 0" instead of deprecated "tty -s" to detect when stdin is a terminal. (test -t 0 is used elsewhere in git-am and in other git shell scripts, tty -s is not.)

Use "test ..." instead of "[ ... ]" and "die <msg>" instead of "echo <msg>

Quoted 1 line

&2; exit 1" to be consistent with rest of script.

---
Added SoB, otherwise no change from v1.

 git-am.sh |   12 ++++--------
 1 files changed, 4 insertions(+), 8 deletions(-)
git-am.sh +4 -8
index 65285a0..9653a98 100755
@@ -8,9 +8,8 @@ OPTIONS_SPEC="\
 git am [options] [<mbox>|<Maildir>...]
 git am [options] (--resolved | --skip | --abort)
 --
-d,dotest=       (removed -- do not use)
 i,interactive   run interactively
-b,binary        (historical option -- no-op)
+b,binary*       (historical option -- no-op)
 3,3way          allow fall back on 3way merging if needed
 s,signoff       add a Signed-off-by line to the commit message
 u,utf8          recode into utf8 (default)
@@ -24,7 +23,7 @@ resolvemsg=     override error message when patch failure occurs
 r,resolved      to be used after a patch failure
 skip            skip the current patch
 abort           restore the original branch and abort the patching operation.
-rebasing        (internal use for git-rebase)"
+rebasing*       (internal use for git-rebase)"
 
 . git-sh-setup
 prefix=$(git rev-parse --show-prefix)
@@ -204,7 +203,7 @@ then
 		# unreliable -- stdin could be /dev/null for example
 		# and the caller did not intend to feed us a patch but
 		# wanted to continue unattended.
-		tty -s
+		test -t 0
 		;;
 	*)
 		false
@@ -283,10 +282,7 @@ fi
 case "$resolved" in
 '')
 	files=$(git diff-index --cached --name-only HEAD --) || exit
-	if [ "$files" ]; then
-	   echo "Dirty index: cannot apply patches (dirty: $files)" >&2
-	   exit 1
-	fi
+	test "$files" && die "Dirty index: cannot apply patches (dirty: $files)"
 esac
 
 if test "$(cat "$dotest/utf8")" = t
Signature · 1 line
1.6.1.224.gb56c
#2 lore raw

Re: [PATCH v2 2/2] git-am: minor cleanups

Quoted 2 lines · Jay Soffian

Use "test -t 0" instead of deprecated "tty -s" to detect when stdin is a terminal.

Who deprecated it?

Other changes looked sensible, though.

#3 lore raw

Re: [PATCH v2 2/2] git-am: minor cleanups

Quoted 6 lines · Junio C Hamano
Quoted 2 lines · Jay Soffian

Use "test -t 0" instead of deprecated "tty -s" to detect when stdin is a terminal.

Who deprecated it?

I believe it's IEEE Std 1003.2-1992 / POSIX.2. I found the initial reference in the BSD/OS X man page[1], but google also found me other references [2,3]. Also, elsewhere git uses "test -t 0", not "tty -s".

[1] http://developer.apple.com/DOCUMENTATION/Darwin/Reference/ManPages/man1/tty.1.html
(The -s option is deprecated in favor of the ``test -t 0'' command.)
[2] http://docs.sun.com/app/docs/doc/816-5165/tty-1?a=view
(Portable applications should use test -t.)
[3] http://opengroup.org/onlinepubs/007908799/xcu/tty.html
(Portable applications should use test -t 0.)

j.

#4 lore raw
In reply to Jay Soffian

git-am.sh else · line 257

Quoted 1 line · Jay Soffian
git-am.sh +1 -0
+	test $# = 0 && test -t 0 && usage

Sorry to be dense. Why isn't your patch the above single liner?

#5 lore raw
Quoted 6 lines · Junio C Hamano
Quoted 1 line · Jay Soffian

+ test $# = 0 && test -t 0 && usage

Sorry to be dense. Why isn't your patch the above single liner?

"Also ensure that $dotest is cleaned up if user manages to interupt mailsplit while it is processing input, but not if mailsplit exits non-zero due to error."

j.

#6 lore raw
Quoted 11 lines · Jay Soffian
Quoted 6 lines · Junio C Hamano
Quoted 1 line · Jay Soffian

+ test $# = 0 && test -t 0 && usage

Sorry to be dense. Why isn't your patch the above single liner?

"Also ensure that $dotest is cleaned up if user manages to interupt mailsplit while it is processing input, but not if mailsplit exits non-zero due to error."

My point was why "Also" needs to be in the same commit. Aren't they separate issues?

#7 lore raw
In reply to Junio C Hamano

Heya,

Quoted 2 lines · Junio C Hamano
Quoted 1 line · Jay Soffian

+ test $# = 0 && test -t 0 && usage

Awesome! Thanks for looking into this :).

Quoted 1 line

Sorry to be dense. Why isn't your patch the above single liner?

I hope you two work this out soon so it gets into maint.

Signature · 3 lines
Cheers,

Sverre Rabbelier