am: teach mercurial patch parser how to read from stdin

git-mailsplit, which splits mbox patches, will read the patch from stdin when the filename is "-" or there are no files listed on the command-line. To be consistent with this behavior, teach the mercurial patch parser to read from stdin if the filename is "-" or no files are listed on the command-line. Based-on-patch-by: Chris Packham <judge.packham@gmail.com> Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Paul Tan <pyokagan@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Paul Tan committed Jun 15, 2015 at 19:08 UTC 9f0aa6e65447c719abe8fe739d9f1e40b7335af8
2 files changed +12 -1
git-am.sh
+2 -1
@@ -327,6 +327,7 @@ split_patches () {
327 ;;
328 hg)
329 this=0
330 + test 0 -eq "$#" && set -- -
331 for hg in "$@"
332 do
333 this=$(( $this + 1 ))
@@ -353,7 +354,7 @@ split_patches () {
354 print "\n", $_ ;
355 $subject = 1;
356 }
356 - ' <"$hg" >"$dotest/$msgnum" || clean_abort
357 + ' -- "$hg" >"$dotest/$msgnum" || clean_abort
358 done
359 echo "$this" >"$dotest/last"
360 this=
t/t4150-am.sh
+10
@@ -259,6 +259,16 @@ test_expect_success 'am applies hg patch' '
259 test_cmp_rev second^ HEAD^
260 '
261
262 +test_expect_success 'am --patch-format=hg applies hg patch' '
263 + rm -fr .git/rebase-apply &&
264 + git checkout -f first &&
265 + git am --patch-format=hg <patch1-hg.eml &&
266 + test_path_is_missing .git/rebase-apply &&
267 + git diff --exit-code second &&
268 + test_cmp_rev second HEAD &&
269 + test_cmp_rev second^ HEAD^
270 +'
271 +
272 test_expect_success 'setup: new author and committer' '
273 GIT_AUTHOR_NAME="Another Thor" &&
274 GIT_AUTHOR_EMAIL="a.thor@example.com" &&