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

8 messages from 2009-01-28 to 2009-01-28. Participants: Jay Soffian, Junio C Hamano, Sverre Rabbelier.
Thread: https://gitlist.dev/t/17405

## Jay Soffian, 2009-01-28 03:27

Subject: [PATCH v2 1/2] git-am: emit usage when called w/o arguments and w/o patch on stdin
Message-ID: <1233113262-17491-1-git-send-email-jaysoffian@gmail.com>
URL: https://gitlist.dev/e/1233113262-17491-1-git-send-email-jaysoffian%40gmail.com

```
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

Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
Change from v1: don't remove $dotest if mailsplit exits non-zero

 git-am.sh |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/git-am.sh b/git-am.sh
index b1c05c9..65285a0 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -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.
-- 
1.6.1.224.gb56c

```

## Jay Soffian, 2009-01-28 03:27

Subject: [PATCH v2 2/2] git-am: minor cleanups
Message-ID: <1233113262-17491-2-git-send-email-jaysoffian@gmail.com>
URL: https://gitlist.dev/e/1233113262-17491-2-git-send-email-jaysoffian%40gmail.com
In-Reply-To: <1233113262-17491-1-git-send-email-jaysoffian@gmail.com>

```
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>
>&2; exit 1" to be consistent with rest of script.

Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
Added SoB, otherwise no change from v1.

 git-am.sh |   12 ++++--------
 1 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/git-am.sh b/git-am.sh
index 65285a0..9653a98 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -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
-- 
1.6.1.224.gb56c

```

## Junio C Hamano, 2009-01-28 04:17

Subject: Re: [PATCH v2 1/2] git-am: emit usage when called w/o arguments and w/o patch on stdin
Message-ID: <7vhc3kxdwm.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vhc3kxdwm.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <1233113262-17491-1-git-send-email-jaysoffian@gmail.com>

```
Jay Soffian <jaysoffian@gmail.com> writes:

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

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

```

## Junio C Hamano, 2009-01-28 04:18

Subject: Re: [PATCH v2 2/2] git-am: minor cleanups
Message-ID: <7vd4e8xdva.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vd4e8xdva.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <1233113262-17491-2-git-send-email-jaysoffian@gmail.com>

```
Jay Soffian <jaysoffian@gmail.com> writes:

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

Who deprecated it?

Other changes looked sensible, though.

```

## Sverre Rabbelier, 2009-01-28 10:32

Subject: Re: [PATCH v2 1/2] git-am: emit usage when called w/o arguments and w/o patch on stdin
Message-ID: <bd6139dc0901280232y25a2fab0xe0eda8783314cc7@mail.gmail.com>
URL: https://gitlist.dev/e/bd6139dc0901280232y25a2fab0xe0eda8783314cc7%40mail.gmail.com
In-Reply-To: <7vhc3kxdwm.fsf@gitster.siamese.dyndns.org>

```
Heya,

On Wed, Jan 28, 2009 at 05:17, Junio C Hamano <gitster@pobox.com> wrote:
> Jay Soffian <jaysoffian@gmail.com> writes:
>> +     test $# = 0 && test -t 0 && usage

Awesome! Thanks for looking into this :).

> 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.

-- 
Cheers,

Sverre Rabbelier

```

## Jay Soffian, 2009-01-28 14:26

Subject: Re: [PATCH v2 2/2] git-am: minor cleanups
Message-ID: <76718490901280626j2caa6ebbgf98c76d8419191c7@mail.gmail.com>
URL: https://gitlist.dev/e/76718490901280626j2caa6ebbgf98c76d8419191c7%40mail.gmail.com
In-Reply-To: <7vd4e8xdva.fsf@gitster.siamese.dyndns.org>

```
On Tue, Jan 27, 2009 at 11:18 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Jay Soffian <jaysoffian@gmail.com> writes:
>
>> 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.

```

## Jay Soffian, 2009-01-28 14:28

Subject: Re: [PATCH v2 1/2] git-am: emit usage when called w/o arguments and w/o patch on stdin
Message-ID: <76718490901280628y3761b41dhd2e544093e01e209@mail.gmail.com>
URL: https://gitlist.dev/e/76718490901280628y3761b41dhd2e544093e01e209%40mail.gmail.com
In-Reply-To: <7vhc3kxdwm.fsf@gitster.siamese.dyndns.org>

```
On Tue, Jan 27, 2009 at 11:17 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Jay Soffian <jaysoffian@gmail.com> writes:
>
>> +     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.

```

## Junio C Hamano, 2009-01-28 18:10

Subject: Re: [PATCH v2 1/2] git-am: emit usage when called w/o arguments and w/o patch on stdin
Message-ID: <7v7i4fti70.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v7i4fti70.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <76718490901280628y3761b41dhd2e544093e01e209@mail.gmail.com>

```
Jay Soffian <jaysoffian@gmail.com> writes:

> On Tue, Jan 27, 2009 at 11:17 PM, Junio C Hamano <gitster@pobox.com> wrote:
>> Jay Soffian <jaysoffian@gmail.com> writes:
>>
>>> +     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?

```
