From 1556ef1e373e2928cd0d4a3630f142a57c1f1813 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 4 Dec 2008 15:03:28 -0800 Subject: [PATCH 1/5] 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. Signed-off-by: Junio C Hamano --- git-am.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/git-am.sh b/git-am.sh index aa602618e6c..1bf70d47779 100755 --- a/git-am.sh +++ b/git-am.sh @@ -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) From a20033796b312390ea8a50917bea623efd6fad97 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 4 Dec 2008 15:38:27 -0800 Subject: [PATCH 2/5] git-am: propagate -C, -p 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. Signed-off-by: Junio C Hamano --- git-am.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/git-am.sh b/git-am.sh index 1bf70d47779..ed54e716d9a 100755 --- a/git-am.sh +++ b/git-am.sh @@ -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) From 22db240dd1791b32e7f6d25a466c2835bdccb51e Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 4 Dec 2008 15:38:27 -0800 Subject: [PATCH 3/5] git-am: propagate --3way options as well The reasoning is the same as the previous patch, where we made -C and -p propagate across a failure. Signed-off-by: Junio C Hamano --- git-am.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/git-am.sh b/git-am.sh index ed54e716d9a..13c02d6adec 100755 --- a/git-am.sh +++ b/git-am.sh @@ -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 From fe6beab7e80565dac81125aa82521f7673905ebc Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 4 Dec 2008 17:08:48 -0800 Subject: [PATCH 4/5] 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. Signed-off-by: Junio C Hamano --- 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(+) 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 diff --git a/t/t4252-am-options.sh b/t/t4252-am-options.sh new file mode 100755 index 00000000000..1a1946dd976 --- /dev/null +++ b/t/t4252-am-options.sh @@ -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 diff --git a/t/t4252/am-test-1-1 b/t/t4252/am-test-1-1 new file mode 100644 index 00000000000..b0c09dc9658 --- /dev/null +++ b/t/t4252/am-test-1-1 @@ -0,0 +1,19 @@ +From: A U Thor +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 diff --git a/t/t4252/am-test-1-2 b/t/t4252/am-test-1-2 new file mode 100644 index 00000000000..1b874ae115d --- /dev/null +++ b/t/t4252/am-test-1-2 @@ -0,0 +1,21 @@ +From: A U Thor +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 diff --git a/t/t4252/am-test-2-1 b/t/t4252/am-test-2-1 new file mode 100644 index 00000000000..feda94a0ccc --- /dev/null +++ b/t/t4252/am-test-2-1 @@ -0,0 +1,19 @@ +From: A U Thor +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 diff --git a/t/t4252/am-test-2-2 b/t/t4252/am-test-2-2 new file mode 100644 index 00000000000..2ac66009763 --- /dev/null +++ b/t/t4252/am-test-2-2 @@ -0,0 +1,21 @@ +From: A U Thor +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 diff --git a/t/t4252/am-test-3-1 b/t/t4252/am-test-3-1 new file mode 100644 index 00000000000..608e5abba4c --- /dev/null +++ b/t/t4252/am-test-3-1 @@ -0,0 +1,19 @@ +From: A U Thor +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 diff --git a/t/t4252/am-test-3-2 b/t/t4252/am-test-3-2 new file mode 100644 index 00000000000..0081b96f2a9 --- /dev/null +++ b/t/t4252/am-test-3-2 @@ -0,0 +1,21 @@ +From: A U Thor +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 diff --git a/t/t4252/am-test-4-1 b/t/t4252/am-test-4-1 new file mode 100644 index 00000000000..e48cd6cbde9 --- /dev/null +++ b/t/t4252/am-test-4-1 @@ -0,0 +1,19 @@ +From: A U Thor +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 diff --git a/t/t4252/am-test-4-2 b/t/t4252/am-test-4-2 new file mode 100644 index 00000000000..0e69bfa55b8 --- /dev/null +++ b/t/t4252/am-test-4-2 @@ -0,0 +1,22 @@ +From: A U Thor +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 diff --git a/t/t4252/file-1-0 b/t/t4252/file-1-0 new file mode 100644 index 00000000000..06e567b11df --- /dev/null +++ b/t/t4252/file-1-0 @@ -0,0 +1,7 @@ +1 +2 +3 +4 +5 +6 +7 diff --git a/t/t4252/file-2-0 b/t/t4252/file-2-0 new file mode 100644 index 00000000000..06e567b11df --- /dev/null +++ b/t/t4252/file-2-0 @@ -0,0 +1,7 @@ +1 +2 +3 +4 +5 +6 +7 From 9b9f5a2258e6df611d2903d84fd8d41806ce0e00 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 5 Dec 2008 11:19:43 -0800 Subject: [PATCH 5/5] git-am: rename apply_opt_extra file to apply-opt All other state files use dash in their names, not underscores. Also, there is no reason to call this "extra". Drop it. Signed-off-by: Junio C Hamano --- git-am.sh | 4 ++-- t/t4252-am-options.sh | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/git-am.sh b/git-am.sh index 13c02d6adec..4b157fe5d53 100755 --- a/git-am.sh +++ b/git-am.sh @@ -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 ' diff --git a/t/t4252-am-options.sh b/t/t4252-am-options.sh index 1a1946dd976..3ab9e8e6e36 100755 --- a/t/t4252-am-options.sh +++ b/t/t4252-am-options.sh @@ -45,7 +45,6 @@ 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