git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/2] git-am: emit usage when called w/o arguments and w/o patch on stdin
@ 2009-01-28  3:27 Jay Soffian
  2009-01-28  3:27 ` [PATCH v2 2/2] git-am: minor cleanups Jay Soffian
  2009-01-28  4:17 ` [PATCH v2 1/2] git-am: emit usage when called w/o arguments and w/o patch on stdin Junio C Hamano
  0 siblings, 2 replies; 8+ messages in thread
From: Jay Soffian @ 2009-01-28  3:27 UTC (permalink / raw)
  To: git; +Cc: Jay Soffian, gitster, sverre

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

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 2/2] git-am: minor cleanups
  2009-01-28  3:27 [PATCH v2 1/2] git-am: emit usage when called w/o arguments and w/o patch on stdin Jay Soffian
@ 2009-01-28  3:27 ` Jay Soffian
  2009-01-28  4:18   ` Junio C Hamano
  2009-01-28  4:17 ` [PATCH v2 1/2] git-am: emit usage when called w/o arguments and w/o patch on stdin Junio C Hamano
  1 sibling, 1 reply; 8+ messages in thread
From: Jay Soffian @ 2009-01-28  3:27 UTC (permalink / raw)
  To: git; +Cc: Jay Soffian, gitster, sverre

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

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 1/2] git-am: emit usage when called w/o arguments and w/o patch on stdin
  2009-01-28  3:27 [PATCH v2 1/2] git-am: emit usage when called w/o arguments and w/o patch on stdin Jay Soffian
  2009-01-28  3:27 ` [PATCH v2 2/2] git-am: minor cleanups Jay Soffian
@ 2009-01-28  4:17 ` Junio C Hamano
  2009-01-28 10:32   ` Sverre Rabbelier
  2009-01-28 14:28   ` Jay Soffian
  1 sibling, 2 replies; 8+ messages in thread
From: Junio C Hamano @ 2009-01-28  4:17 UTC (permalink / raw)
  To: Jay Soffian; +Cc: git, gitster, sverre

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?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 2/2] git-am: minor cleanups
  2009-01-28  3:27 ` [PATCH v2 2/2] git-am: minor cleanups Jay Soffian
@ 2009-01-28  4:18   ` Junio C Hamano
  2009-01-28 14:26     ` Jay Soffian
  0 siblings, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2009-01-28  4:18 UTC (permalink / raw)
  To: Jay Soffian; +Cc: git, gitster, sverre

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.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 1/2] git-am: emit usage when called w/o arguments and  w/o patch on stdin
  2009-01-28  4:17 ` [PATCH v2 1/2] git-am: emit usage when called w/o arguments and w/o patch on stdin Junio C Hamano
@ 2009-01-28 10:32   ` Sverre Rabbelier
  2009-01-28 14:28   ` Jay Soffian
  1 sibling, 0 replies; 8+ messages in thread
From: Sverre Rabbelier @ 2009-01-28 10:32 UTC (permalink / raw)
  To: Jay Soffian; +Cc: git, Junio C Hamano

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 2/2] git-am: minor cleanups
  2009-01-28  4:18   ` Junio C Hamano
@ 2009-01-28 14:26     ` Jay Soffian
  0 siblings, 0 replies; 8+ messages in thread
From: Jay Soffian @ 2009-01-28 14:26 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, sverre

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.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 1/2] git-am: emit usage when called w/o arguments and  w/o patch on stdin
  2009-01-28  4:17 ` [PATCH v2 1/2] git-am: emit usage when called w/o arguments and w/o patch on stdin Junio C Hamano
  2009-01-28 10:32   ` Sverre Rabbelier
@ 2009-01-28 14:28   ` Jay Soffian
  2009-01-28 18:10     ` Junio C Hamano
  1 sibling, 1 reply; 8+ messages in thread
From: Jay Soffian @ 2009-01-28 14:28 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, sverre

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.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 1/2] git-am: emit usage when called w/o arguments and  w/o patch on stdin
  2009-01-28 14:28   ` Jay Soffian
@ 2009-01-28 18:10     ` Junio C Hamano
  0 siblings, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2009-01-28 18:10 UTC (permalink / raw)
  To: Jay Soffian; +Cc: git, sverre

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?

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2009-01-28 18:12 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-28  3:27 [PATCH v2 1/2] git-am: emit usage when called w/o arguments and w/o patch on stdin Jay Soffian
2009-01-28  3:27 ` [PATCH v2 2/2] git-am: minor cleanups Jay Soffian
2009-01-28  4:18   ` Junio C Hamano
2009-01-28 14:26     ` Jay Soffian
2009-01-28  4:17 ` [PATCH v2 1/2] git-am: emit usage when called w/o arguments and w/o patch on stdin Junio C Hamano
2009-01-28 10:32   ` Sverre Rabbelier
2009-01-28 14:28   ` Jay Soffian
2009-01-28 18:10     ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).