|
1 | 1 | #!/bin/sh
|
2 | 2 |
|
3 |
| -test_description='git merge |
| 3 | +test_description="git merge |
4 | 4 |
|
5 |
| -Testing a custom strategy.' |
| 5 | +Testing a custom strategy. |
| 6 | +
|
| 7 | +* (HEAD, master) Merge commit 'c3' |
| 8 | +|\ |
| 9 | +| * (tag: c3) c3 |
| 10 | +* | (tag: c1) c1 |
| 11 | +|/ |
| 12 | +| * tag: c2) c2 |
| 13 | +|/ |
| 14 | +* (tag: c0) c0 |
| 15 | +" |
6 | 16 |
|
7 | 17 | . ./test-lib.sh
|
8 | 18 |
|
9 |
| -cat >git-merge-theirs <<EOF |
10 |
| -#!$SHELL_PATH |
11 |
| -eval git read-tree --reset -u \\\$\$# |
12 |
| -EOF |
13 |
| -chmod +x git-merge-theirs |
14 |
| -PATH=.:$PATH |
15 |
| -export PATH |
| 19 | +test_expect_success 'set up custom strategy' ' |
| 20 | + cat >git-merge-theirs <<-EOF && |
| 21 | + #!$SHELL_PATH |
| 22 | + eval git read-tree --reset -u \\\$\$# |
| 23 | + EOF |
| 24 | +
|
| 25 | + chmod +x git-merge-theirs && |
| 26 | + PATH=.:$PATH && |
| 27 | + export PATH |
| 28 | +' |
16 | 29 |
|
17 | 30 | test_expect_success 'setup' '
|
18 |
| - echo c0 >c0.c && |
19 |
| - git add c0.c && |
20 |
| - git commit -m c0 && |
21 |
| - git tag c0 && |
22 |
| - echo c1 >c1.c && |
23 |
| - git add c1.c && |
24 |
| - git commit -m c1 && |
25 |
| - git tag c1 && |
26 |
| - git reset --hard c0 && |
| 31 | + test_commit c0 c0.c && |
| 32 | + test_commit c1 c1.c && |
| 33 | + git reset --keep c0 && |
27 | 34 | echo c1c1 >c1.c &&
|
28 |
| - echo c2 >c2.c && |
29 |
| - git add c1.c c2.c && |
30 |
| - git commit -m c2 && |
31 |
| - git tag c2 |
| 35 | + git add c1.c && |
| 36 | + test_commit c2 c2.c && |
| 37 | + git reset --keep c0 && |
| 38 | + test_commit c3 c3.c |
32 | 39 | '
|
33 | 40 |
|
34 | 41 | test_expect_success 'merge c2 with a custom strategy' '
|
35 | 42 | git reset --hard c1 &&
|
| 43 | +
|
| 44 | + git rev-parse c1 >head.old && |
| 45 | + git rev-parse c2 >second-parent.expected && |
| 46 | + git rev-parse c2^{tree} >tree.expected && |
36 | 47 | git merge -s theirs c2 &&
|
37 |
| - test "$(git rev-parse c1)" != "$(git rev-parse HEAD)" && |
38 |
| - test "$(git rev-parse c1)" = "$(git rev-parse HEAD^1)" && |
39 |
| - test "$(git rev-parse c2)" = "$(git rev-parse HEAD^2)" && |
40 |
| - test "$(git rev-parse c2^{tree})" = "$(git rev-parse HEAD^{tree})" && |
| 48 | +
|
| 49 | + git rev-parse HEAD >head.new && |
| 50 | + git rev-parse HEAD^1 >first-parent && |
| 51 | + git rev-parse HEAD^2 >second-parent && |
| 52 | + git rev-parse HEAD^{tree} >tree && |
| 53 | + git update-index --refresh && |
41 | 54 | git diff --exit-code &&
|
42 | 55 | git diff --exit-code c2 HEAD &&
|
43 | 56 | git diff --exit-code c2 &&
|
| 57 | +
|
| 58 | + ! test_cmp head.old head.new && |
| 59 | + test_cmp head.old first-parent && |
| 60 | + test_cmp second-parent.expected second-parent && |
| 61 | + test_cmp tree.expected tree && |
44 | 62 | test -f c0.c &&
|
45 | 63 | grep c1c1 c1.c &&
|
46 | 64 | test -f c2.c
|
47 | 65 | '
|
48 | 66 |
|
| 67 | +test_expect_success 'trivial merge with custom strategy' ' |
| 68 | + git reset --hard c1 && |
| 69 | +
|
| 70 | + git rev-parse c1 >head.old && |
| 71 | + git rev-parse c3 >second-parent.expected && |
| 72 | + git rev-parse c3^{tree} >tree.expected && |
| 73 | + git merge -s theirs c3 && |
| 74 | +
|
| 75 | + git rev-parse HEAD >head.new && |
| 76 | + git rev-parse HEAD^1 >first-parent && |
| 77 | + git rev-parse HEAD^2 >second-parent && |
| 78 | + git rev-parse HEAD^{tree} >tree && |
| 79 | + git update-index --refresh && |
| 80 | + git diff --exit-code && |
| 81 | + git diff --exit-code c3 HEAD && |
| 82 | + git diff --exit-code c3 && |
| 83 | +
|
| 84 | + ! test_cmp head.old head.new && |
| 85 | + test_cmp head.old first-parent && |
| 86 | + test_cmp second-parent.expected second-parent && |
| 87 | + test_cmp tree.expected tree && |
| 88 | + test -f c0.c && |
| 89 | + ! test -e c1.c && |
| 90 | + test -f c3.c |
| 91 | +' |
| 92 | + |
49 | 93 | test_done
|
0 commit comments