From 6209036c7843f4095c04b5ecc13199cc4eccaf3f Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Sun, 15 Aug 2010 20:08:46 -0500 Subject: [PATCH 1/3] t7606 (merge-theirs): modernize style Guard setup commands with test_expect_success, so they are easier to visually skip over and get to the good part. While at it: - use test_commit for brevity and reproducible object names; - use test_cmp instead of using the test builtin to compare the result of command substitution, for better output with -v on failure. Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- t/t7606-merge-custom.sh | 66 +++++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 26 deletions(-) diff --git a/t/t7606-merge-custom.sh b/t/t7606-merge-custom.sh index 52a451dd57..82045cd543 100755 --- a/t/t7606-merge-custom.sh +++ b/t/t7606-merge-custom.sh @@ -1,46 +1,60 @@ #!/bin/sh -test_description='git merge +test_description="git merge -Testing a custom strategy.' +Testing a custom strategy. + +* (HEAD, master) Merge commit 'c2' +|\ +| * (tag: c2) c2 +* | (tag: c1) c1 +|/ +* (tag: c0) c0 +" . ./test-lib.sh -cat >git-merge-theirs <git-merge-theirs <<-EOF && + #!$SHELL_PATH + eval git read-tree --reset -u \\\$\$# + EOF + + chmod +x git-merge-theirs && + PATH=.:$PATH && + export PATH +' test_expect_success 'setup' ' - echo c0 >c0.c && - git add c0.c && - git commit -m c0 && - git tag c0 && - echo c1 >c1.c && - git add c1.c && - git commit -m c1 && - git tag c1 && - git reset --hard c0 && + test_commit c0 c0.c && + test_commit c1 c1.c && + git reset --keep c0 && echo c1c1 >c1.c && - echo c2 >c2.c && - git add c1.c c2.c && - git commit -m c2 && - git tag c2 + git add c1.c && + test_commit c2 c2.c ' test_expect_success 'merge c2 with a custom strategy' ' git reset --hard c1 && + + git rev-parse c1 >head.old && + git rev-parse c2 >second-parent.expected && + git rev-parse c2^{tree} >tree.expected && git merge -s theirs c2 && - test "$(git rev-parse c1)" != "$(git rev-parse HEAD)" && - test "$(git rev-parse c1)" = "$(git rev-parse HEAD^1)" && - test "$(git rev-parse c2)" = "$(git rev-parse HEAD^2)" && - test "$(git rev-parse c2^{tree})" = "$(git rev-parse HEAD^{tree})" && + + git rev-parse HEAD >head && + git rev-parse HEAD^1 >first-parent && + git rev-parse HEAD^2 >second-parent && + git rev-parse HEAD^{tree} >tree && + git update-index --refresh && git diff --exit-code && git diff --exit-code c2 HEAD && git diff --exit-code c2 && + + ! test_cmp head.old head && + test_cmp head.old first-parent && + test_cmp second-parent.expected second-parent && + test_cmp tree.expected tree && test -f c0.c && grep c1c1 c1.c && test -f c2.c From 52b48ef1e40fc2b996e3d3f9cad3d096482d8e49 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Sun, 15 Aug 2010 20:11:06 -0500 Subject: [PATCH 2/3] merge: let custom strategies intervene in trivial merges MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As v1.6.1-rc1~294^2 (2008-08-23) explains, custom merge strategies do not even kick in when the merge is truly trivial. But they should, since otherwise a custom “--strategy=theirs” is not useful. Perhaps custom strategies should not allow fast-forward either. This patch does not make that change, since it is less important (because it is always possible to explicitly use --no-ff). Reported-by: Yaroslav Halchenko Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- builtin/merge.c | 1 + t/t7606-merge-custom.sh | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/builtin/merge.c b/builtin/merge.c index 37ce4f589f..e48e90bb69 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -131,6 +131,7 @@ static struct strategy *get_strategy(const char *name) ret = xcalloc(1, sizeof(struct strategy)); ret->name = xstrdup(name); + ret->attr = NO_TRIVIAL; return ret; } diff --git a/t/t7606-merge-custom.sh b/t/t7606-merge-custom.sh index 82045cd543..13c219367d 100755 --- a/t/t7606-merge-custom.sh +++ b/t/t7606-merge-custom.sh @@ -4,11 +4,13 @@ test_description="git merge Testing a custom strategy. -* (HEAD, master) Merge commit 'c2' +* (HEAD, master) Merge commit 'c3' |\ -| * (tag: c2) c2 +| * (tag: c3) c3 * | (tag: c1) c1 |/ +| * tag: c2) c2 +|/ * (tag: c0) c0 " @@ -31,7 +33,9 @@ test_expect_success 'setup' ' git reset --keep c0 && echo c1c1 >c1.c && git add c1.c && - test_commit c2 c2.c + test_commit c2 c2.c && + git reset --keep c0 && + test_commit c3 c3.c ' test_expect_success 'merge c2 with a custom strategy' ' @@ -60,4 +64,30 @@ test_expect_success 'merge c2 with a custom strategy' ' test -f c2.c ' +test_expect_success 'trivial merge with custom strategy' ' + git reset --hard c1 && + + git rev-parse c1 >head.old && + git rev-parse c3 >second-parent.expected && + git rev-parse c3^{tree} >tree.expected && + git merge -s theirs c3 && + + git rev-parse HEAD >head && + git rev-parse HEAD^1 >first-parent && + git rev-parse HEAD^2 >second-parent && + git rev-parse HEAD^{tree} >tree && + git update-index --refresh && + git diff --exit-code && + git diff --exit-code c3 HEAD && + git diff --exit-code c3 && + + ! test_cmp head.old head && + test_cmp head.old first-parent && + test_cmp second-parent.expected second-parent && + test_cmp tree.expected tree && + test -f c0.c && + ! test -e c1.c && + test -f c3.c +' + test_done From 0e1b50152bfc12d2d286af17993f6356171e9ce5 Mon Sep 17 00:00:00 2001 From: Brian Gernhardt Date: Mon, 23 Aug 2010 16:15:47 -0400 Subject: [PATCH 3/3] t7606: Avoid using head as a file name A file named 'head' gets confused with the HEAD ref on case-insensitive file systems. Replace '>head' with '>head.new' to match the '>head.old' files they are compared to. Signed-off-by: Brian Gernhardt Acked-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- t/t7606-merge-custom.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/t/t7606-merge-custom.sh b/t/t7606-merge-custom.sh index 13c219367d..8e8c4d7246 100755 --- a/t/t7606-merge-custom.sh +++ b/t/t7606-merge-custom.sh @@ -46,7 +46,7 @@ test_expect_success 'merge c2 with a custom strategy' ' git rev-parse c2^{tree} >tree.expected && git merge -s theirs c2 && - git rev-parse HEAD >head && + git rev-parse HEAD >head.new && git rev-parse HEAD^1 >first-parent && git rev-parse HEAD^2 >second-parent && git rev-parse HEAD^{tree} >tree && @@ -55,7 +55,7 @@ test_expect_success 'merge c2 with a custom strategy' ' git diff --exit-code c2 HEAD && git diff --exit-code c2 && - ! test_cmp head.old head && + ! test_cmp head.old head.new && test_cmp head.old first-parent && test_cmp second-parent.expected second-parent && test_cmp tree.expected tree && @@ -72,7 +72,7 @@ test_expect_success 'trivial merge with custom strategy' ' git rev-parse c3^{tree} >tree.expected && git merge -s theirs c3 && - git rev-parse HEAD >head && + git rev-parse HEAD >head.new && git rev-parse HEAD^1 >first-parent && git rev-parse HEAD^2 >second-parent && git rev-parse HEAD^{tree} >tree && @@ -81,7 +81,7 @@ test_expect_success 'trivial merge with custom strategy' ' git diff --exit-code c3 HEAD && git diff --exit-code c3 && - ! test_cmp head.old head && + ! test_cmp head.old head.new && test_cmp head.old first-parent && test_cmp second-parent.expected second-parent && test_cmp tree.expected tree &&