Fix longstanding "git am" bug
cover Fix longstanding "git am" bug
Simon Schubert rerolled a patch to add "git am --directory=<dir>" from three months ago, which is a good complement to existing "git am -p<n>", but it had the same issue of duplicating an existing bug to the new feature.
Let's fix the existing bug first, before accepting any new feature, which will happen after 1.6.1 goes final.
Junio C Hamano (4):
git-am --whitespace: do not lose the command line option
git-am: propagate -C<n>, -p<n> options as well
git-am: propagate --3way options as well
Test that git-am does not lose -C/-p/--whitespace options
git-am.sh | 15 +++++++++---- t/t4252-am-options.sh | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ t/t4252/am-test-1-1 | 19 +++++++++++++++++ t/t4252/am-test-1-2 | 21 +++++++++++++++++++ t/t4252/am-test-2-1 | 19 +++++++++++++++++ t/t4252/am-test-2-2 | 21 +++++++++++++++++++ t/t4252/am-test-3-1 | 19 +++++++++++++++++ t/t4252/am-test-3-2 | 21 +++++++++++++++++++ t/t4252/am-test-4-1 | 19 +++++++++++++++++ t/t4252/am-test-4-2 | 22 ++++++++++++++++++++ t/t4252/file-1-0 | 7 ++++++ t/t4252/file-2-0 | 7 ++++++ 12 files changed, 239 insertions(+), 5 deletions(-) create mode 100755 t/t4252-am-options.sh create mode 100644 t/t4252/am-test-1-1 create mode 100644 t/t4252/am-test-1-2 create mode 100644 t/t4252/am-test-2-1 create mode 100644 t/t4252/am-test-2-2 create mode 100644 t/t4252/am-test-3-1 create mode 100644 t/t4252/am-test-3-2 create mode 100644 t/t4252/am-test-4-1 create mode 100644 t/t4252/am-test-4-2 create mode 100644 t/t4252/file-1-0 create mode 100644 t/t4252/file-2-0
PATCH 1/4 git-am --whitespace: do not lose the command line option
When you start "git am --whitespace=fix" and the patch application process is interrupted by an unapplicable patch early in the series, after fixing the offending patch, the remainder of the patch should be processed still with --whitespace=fix when restarted with "git am --resolved" (or dropping the offending patch with "git am --skip").
The breakage was introduced by the commit 67dad68 (add -C[NUM] to git-am, 2007-02-08); this should fix it.
--- git-am.sh | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
git-am.sh +4 -4
@@ -121,7 +121,7 @@ It does not apply to blobs recorded in its index." prec=4 dotest="$GIT_DIR/rebase-apply" -sign= utf8=t keep= skip= interactive= resolved= rebasing= abort= +sign= utf8=t keep= skip= interactive= resolved= rebasing= abort= ws= resolvemsg= resume= git_apply_opt=
@@ -156,7 +156,7 @@ do --resolvemsg) shift; resolvemsg=$1 ;; --whitespace) - git_apply_opt="$git_apply_opt $1=$2"; shift ;; + ws="--whitespace=$2"; shift ;; -C|-p) git_apply_opt="$git_apply_opt $1$2"; shift ;; --)
@@ -283,7 +283,7 @@ if test "$(cat "$dotest/keep")" = t then keep=-k fi -ws=`cat "$dotest/whitespace"` +ws=$(cat "$dotest/whitespace") if test "$(cat "$dotest/sign")" = t then SIGNOFF=`git var GIT_COMMITTER_IDENT | sed -e '
@@ -454,7 +454,7 @@ do case "$resolved" in '') - git apply $git_apply_opt --index "$dotest/patch" + git apply $git_apply_opt $ws --index "$dotest/patch" apply_status=$? ;; t)
Signature · 1 line
1.6.1.rc1.60.g1d1d7
PATCH 2/4 git-am: propagate -C<n>, -p<n> options as well
These options are meant to deal with patches that do not apply cleanly due to the differences between the version the patch was based on and the version "git am" is working on.
Because a series of patches applied in the same "git am" run tends to come from the same source, it is more useful to propagate these options after the application stops.
--- git-am.sh | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-)
git-am.sh +7 -7
@@ -121,7 +121,7 @@ It does not apply to blobs recorded in its index." prec=4 dotest="$GIT_DIR/rebase-apply" -sign= utf8=t keep= skip= interactive= resolved= rebasing= abort= ws= +sign= utf8=t keep= skip= interactive= resolved= rebasing= abort= resolvemsg= resume= git_apply_opt=
@@ -156,7 +156,7 @@ do --resolvemsg) shift; resolvemsg=$1 ;; --whitespace) - ws="--whitespace=$2"; shift ;; + git_apply_opt="$git_apply_opt $1=$2"; shift ;; -C|-p) git_apply_opt="$git_apply_opt $1$2"; shift ;; --)
@@ -247,10 +247,10 @@ else exit 1 } - # -s, -u, -k and --whitespace flags are kept for the - # resuming session after a patch failure. + # -s, -u, -k, --whitespace, -C and -p flags are kept + # for the resuming session after a patch failure. # -3 and -i can and must be given when resuming. - echo " $ws" >"$dotest/whitespace" + echo " $git_apply_opt" >"$dotest/apply_opt_extra" echo "$sign" >"$dotest/sign" echo "$utf8" >"$dotest/utf8" echo "$keep" >"$dotest/keep"
@@ -283,7 +283,7 @@ if test "$(cat "$dotest/keep")" = t then keep=-k fi -ws=$(cat "$dotest/whitespace") +git_apply_opt=$(cat "$dotest/apply_opt_extra") if test "$(cat "$dotest/sign")" = t then SIGNOFF=`git var GIT_COMMITTER_IDENT | sed -e '
@@ -454,7 +454,7 @@ do case "$resolved" in '') - git apply $git_apply_opt $ws --index "$dotest/patch" + git apply $git_apply_opt --index "$dotest/patch" apply_status=$? ;; t)
Signature · 1 line
1.6.1.rc1.60.g1d1d7
PATCH 3/4 git-am: propagate --3way options as well
The reasoning is the same as the previous patch, where we made -C<n> and -p<n> propagate across a failure.
--- git-am.sh | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-)
git-am.sh +7 -2
@@ -247,10 +247,11 @@ else exit 1 } - # -s, -u, -k, --whitespace, -C and -p flags are kept + # -s, -u, -k, --whitespace, -3, -C and -p flags are kept # for the resuming session after a patch failure. - # -3 and -i can and must be given when resuming. + # -i can and must be given when resuming. echo " $git_apply_opt" >"$dotest/apply_opt_extra" + echo "$threeway" >"$dotest/threeway" echo "$sign" >"$dotest/sign" echo "$utf8" >"$dotest/utf8" echo "$keep" >"$dotest/keep"
@@ -283,6 +284,10 @@ if test "$(cat "$dotest/keep")" = t then keep=-k fi +if test "$(cat "$dotest/threeway")" = t +then + threeway=t +fi git_apply_opt=$(cat "$dotest/apply_opt_extra") if test "$(cat "$dotest/sign")" = t then
Signature · 1 line
1.6.1.rc1.60.g1d1d7
PATCH 4/4 Test that git-am does not lose -C/-p/--whitespace options
These tests make sure that "git am" does not lose command line options specified when it was started, after it is interrupted by a patch that does not apply earlier in the series.
--- t/t4252-am-options.sh | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ t/t4252/am-test-1-1 | 19 +++++++++++++++++ t/t4252/am-test-1-2 | 21 +++++++++++++++++++ t/t4252/am-test-2-1 | 19 +++++++++++++++++ t/t4252/am-test-2-2 | 21 +++++++++++++++++++ t/t4252/am-test-3-1 | 19 +++++++++++++++++ t/t4252/am-test-3-2 | 21 +++++++++++++++++++ t/t4252/am-test-4-1 | 19 +++++++++++++++++ t/t4252/am-test-4-2 | 22 ++++++++++++++++++++ t/t4252/file-1-0 | 7 ++++++ t/t4252/file-2-0 | 7 ++++++ 11 files changed, 229 insertions(+), 0 deletions(-) create mode 100755 t/t4252-am-options.sh create mode 100644 t/t4252/am-test-1-1 create mode 100644 t/t4252/am-test-1-2 create mode 100644 t/t4252/am-test-2-1 create mode 100644 t/t4252/am-test-2-2 create mode 100644 t/t4252/am-test-3-1 create mode 100644 t/t4252/am-test-3-2 create mode 100644 t/t4252/am-test-4-1 create mode 100644 t/t4252/am-test-4-2 create mode 100644 t/t4252/file-1-0 create mode 100644 t/t4252/file-2-0
t/t4252-am-options.sh new file +54 -0
@@ -0,0 +1,54 @@ +#!/bin/sh + +test_description='git am not losing options' +. ./test-lib.sh + +tm="$TEST_DIRECTORY/t4252" + +test_expect_success setup ' + cp "$tm/file-1-0" file-1 && + cp "$tm/file-2-0" file-2 && + git add file-1 file-2 && + test_tick && + git commit -m initial && + git tag initial +' + +test_expect_success 'interrupted am --whitespace=fix' ' + rm -rf .git/rebase-apply && + git reset --hard initial && + test_must_fail git am --whitespace=fix "$tm"/am-test-1-? && + git am --skip && + grep 3 file-1 && + grep "^Six$" file-2 +' + +test_expect_success 'interrupted am -C1' ' + rm -rf .git/rebase-apply && + git reset --hard initial && + test_must_fail git am -C1 "$tm"/am-test-2-? && + git am --skip && + grep 3 file-1 && + grep "^Three$" file-2 +' + +test_expect_success 'interrupted am -p2' ' + rm -rf .git/rebase-apply && + git reset --hard initial && + test_must_fail git am -p2 "$tm"/am-test-3-? && + git am --skip && + grep 3 file-1 && + grep "^Three$" file-2 +' + +test_expect_success 'interrupted am -C1 -p2' ' + rm -rf .git/rebase-apply && + git reset --hard initial && + test_must_fail git am -p2 -C1 "$tm"/am-test-4-? && + cat .git/rebase-apply/apply_opt_extra && + git am --skip && + grep 3 file-1 && + grep "^Three$" file-2 +' + +test_done
t/t4252/am-test-1-1 new file +19 -0
@@ -0,0 +1,19 @@ +From: A U Thor <[email protected]> +Date: Thu Dec 4 16:00:00 2008 -0800 +Subject: Three + +Application of this should be rejected because the first line in the +context does not match. + +diff --git i/file-1 w/file-1 +index 06e567b..10f8342 100644 +--- i/file-1 ++++ w/file-1 +@@ -1,6 +1,6 @@ + One + 2 +-3 ++Three + 4 + 5 + 6
t/t4252/am-test-1-2 new file +21 -0
@@ -0,0 +1,21 @@ +From: A U Thor <[email protected]> +Date: Thu Dec 4 16:00:00 2008 -0800 +Subject: Six + +Applying this patch with --whitespace=fix should lose +the trailing whitespace after "Six". + +diff --git i/file-2 w/file-2 +index 06e567b..b6f3a16 100644 +--- i/file-2 ++++ w/file-2 +@@ -1,7 +1,7 @@ + 1 + 2 +-3 ++Three + 4 + 5 +-6 ++Six + 7
t/t4252/am-test-2-1 new file +19 -0
@@ -0,0 +1,19 @@ +From: A U Thor <[email protected]> +Date: Thu Dec 4 16:00:00 2008 -0800 +Subject: Three + +Application of this should be rejected even with -C1 because the +preimage line in the context does not match. + +diff --git i/file-1 w/file-1 +index 06e567b..10f8342 100644 +--- i/file-1 ++++ w/file-1 +@@ -1,6 +1,6 @@ + 1 + 2 +-Tres ++Three + 4 + 5 + 6
t/t4252/am-test-2-2 new file +21 -0
@@ -0,0 +1,21 @@ +From: A U Thor <[email protected]> +Date: Thu Dec 4 16:00:00 2008 -0800 +Subject: Six + +Applying this patch with -C1 should be successful even though +the first line in the context does not match. + +diff --git i/file-2 w/file-2 +index 06e567b..b6f3a16 100644 +--- i/file-2 ++++ w/file-2 +@@ -1,7 +1,7 @@ + One + 2 +-3 ++Three + 4 + 5 +-6 ++Six + 7
t/t4252/am-test-3-1 new file +19 -0
@@ -0,0 +1,19 @@ +From: A U Thor <[email protected]> +Date: Thu Dec 4 16:00:00 2008 -0800 +Subject: Three + +Application of this should be rejected even with -p2 because the +preimage line in the context does not match. + +diff --git i/junk/file-1 w/junk/file-1 +index 06e567b..10f8342 100644 +--- i/junk/file-1 ++++ w/junk/file-1 +@@ -1,6 +1,6 @@ + 1 + 2 +-Tres ++Three + 4 + 5 + 6
t/t4252/am-test-3-2 new file +21 -0
@@ -0,0 +1,21 @@ +From: A U Thor <[email protected]> +Date: Thu Dec 4 16:00:00 2008 -0800 +Subject: Six + +Applying this patch with -p2 should be successful even though +the patch is against a wrong level. + +diff --git i/junk/file-2 w/junk/file-2 +index 06e567b..b6f3a16 100644 +--- i/junk/file-2 ++++ w/junk/file-2 +@@ -1,7 +1,7 @@ + 1 + 2 +-3 ++Three + 4 + 5 +-6 ++Six + 7
t/t4252/am-test-4-1 new file +19 -0
@@ -0,0 +1,19 @@ +From: A U Thor <[email protected]> +Date: Thu Dec 4 16:00:00 2008 -0800 +Subject: Three + +Application of this should be rejected even with -C1 -p2 because +the preimage line in the context does not match. + +diff --git i/junk/file-1 w/junk/file-1 +index 06e567b..10f8342 100644 +--- i/junk/file-1 ++++ w/junk/file-1 +@@ -1,6 +1,6 @@ + 1 + 2 +-Tres ++Three + 4 + 5 + 6
t/t4252/am-test-4-2 new file +22 -0
@@ -0,0 +1,22 @@ +From: A U Thor <[email protected]> +Date: Thu Dec 4 16:00:00 2008 -0800 +Subject: Six + +Applying this patch with -C1 -p2 should be successful even though +the patch is against a wrong level and the first context line does +not match. + +diff --git i/junk/file-2 w/junk/file-2 +index 06e567b..b6f3a16 100644 +--- i/junk/file-2 ++++ w/junk/file-2 +@@ -1,7 +1,7 @@ + One + 2 +-3 ++Three + 4 + 5 +-6 ++Six + 7
t/t4252/file-1-0 new file +7 -0
@@ -0,0 +1,7 @@ +1 +2 +3 +4 +5 +6 +7
t/t4252/file-2-0 new file +7 -0
@@ -0,0 +1,7 @@ +1 +2 +3 +4 +5 +6 +7
Signature · 1 line
1.6.1.rc1.60.g1d1d7
Re: [PATCH 2/4] git-am: propagate -C<n>, -p<n> options as well
In reply to Junio C HamanoHi,
Quoted 4 lines · Junio C Hamano
git-am.sh +1
-1- echo " $ws" >"$dotest/whitespace" + echo " $git_apply_opt" >"$dotest/apply_opt_extra"From the other scripts, it appears we have sort of a convention to use
dashes instead of underscores for file names (see e.g. $dotest/patch-merge-tmp-dir).
Other than that, the whole series looks good to me.
Thanks for the work, especially the tests,
Dscho
Re: [PATCH 2/4] git-am: propagate -C<n>, -p<n> options as well
Quoted 8 lines · Johannes Schindelin
Quoted 4 lines · Junio C Hamano
(quoted diff) +1
-1- echo " $ws" >"$dotest/whitespace" + echo " $git_apply_opt" >"$dotest/apply_opt_extra"From the other scripts, it appears we have sort of a convention to use
dashes instead of underscores for file names (see e.g. $dotest/patch-merge-tmp-dir).
You are right. And there is no reason to call it "extra" either.
git-am.sh | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
git-am.sh +2 -2
@@ -250,7 +250,7 @@ else # -s, -u, -k, --whitespace, -3, -C and -p flags are kept # for the resuming session after a patch failure. # -i can and must be given when resuming. - echo " $git_apply_opt" >"$dotest/apply_opt_extra" + echo " $git_apply_opt" >"$dotest/apply-opt" echo "$threeway" >"$dotest/threeway" echo "$sign" >"$dotest/sign" echo "$utf8" >"$dotest/utf8"
@@ -288,7 +288,7 @@ if test "$(cat "$dotest/threeway")" = t then threeway=t fi -git_apply_opt=$(cat "$dotest/apply_opt_extra") +git_apply_opt=$(cat "$dotest/apply-opt") if test "$(cat "$dotest/sign")" = t then SIGNOFF=`git var GIT_COMMITTER_IDENT | sed -e '