@matheusbsbs / matheus-bagliano / commits / 2161da1039
Fork 0

t3507: introduce pristine-detach helper

All the tests in t3507 (cherry-pick with conflicts) begin with the same checkout + read-tree + clean incantation to ensure a predictable starting point. Factor out a function for that so the interesting part of the tests is easier to read. The "update-index --refresh" and "diff-index --exit-code HEAD" are not necessary as the point of this testsuite is not about testing "read-tree --reset". Improved-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Nieder committed Feb 19, 2011 at 23:12 UTC 2161da103950704a92993702696c9b573dcbccae
1 file changed +22 -54
t/t3507-cherry-pick-conflict.sh
+22 -54
@@ -11,6 +11,18 @@ test_description='test cherry-pick and revert with conflicts
11
12 . ./test-lib.sh
13
14 +test_cmp_rev () {
15 + git rev-parse --verify "$1" >expect.rev &&
16 + git rev-parse --verify "$2" >actual.rev &&
17 + test_cmp expect.rev actual.rev
18 +}
19 +
20 +pristine_detach () {
21 + git checkout -f "$1^0" &&
22 + git read-tree -u --reset HEAD &&
23 + git clean -d -f -f -q -x
24 +}
25 +
26 test_expect_success setup '
27
28 echo unrelated >unrelated &&
@@ -23,13 +35,7 @@ test_expect_success setup '
35 '
36
37 test_expect_success 'failed cherry-pick does not advance HEAD' '
26 -
27 - git checkout -f initial^0 &&
28 - git read-tree -u --reset HEAD &&
29 - git clean -d -f -f -q -x &&
30 -
31 - git update-index --refresh &&
32 - git diff-index --exit-code HEAD &&
38 + pristine_detach initial &&
39
40 head=$(git rev-parse HEAD) &&
41 test_must_fail git cherry-pick picked &&
@@ -39,12 +45,7 @@ test_expect_success 'failed cherry-pick does not advance HEAD' '
45 '
46
47 test_expect_success 'advice from failed cherry-pick' "
42 - git checkout -f initial^0 &&
43 - git read-tree -u --reset HEAD &&
44 - git clean -d -f -f -q -x &&
45 -
46 - git update-index --refresh &&
47 - git diff-index --exit-code HEAD &&
48 + pristine_detach initial &&
49
50 picked=\$(git rev-parse --short picked) &&
51 cat <<-EOF >expected &&
@@ -59,13 +60,7 @@ test_expect_success 'advice from failed cherry-pick' "
60 "
61
62 test_expect_success 'failed cherry-pick produces dirty index' '
62 -
63 - git checkout -f initial^0 &&
64 - git read-tree -u --reset HEAD &&
65 - git clean -d -f -f -q -x &&
66 -
67 - git update-index --refresh &&
68 - git diff-index --exit-code HEAD &&
63 + pristine_detach initial &&
64
65 test_must_fail git cherry-pick picked &&
66
@@ -74,9 +69,7 @@ test_expect_success 'failed cherry-pick produces dirty index' '
69 '
70
71 test_expect_success 'failed cherry-pick registers participants in index' '
77 -
78 - git read-tree -u --reset HEAD &&
79 - git clean -d -f -f -q -x &&
72 + pristine_detach initial &&
73 {
74 git checkout base -- foo &&
75 git ls-files --stage foo &&
@@ -90,10 +83,7 @@ test_expect_success 'failed cherry-pick registers participants in index' '
83 2 s/ 0 / 2 /
84 3 s/ 0 / 3 /
85 " < stages > expected &&
93 - git checkout -f initial^0 &&
94 -
95 - git update-index --refresh &&
96 - git diff-index --exit-code HEAD &&
86 + git read-tree -u --reset HEAD &&
87
88 test_must_fail git cherry-pick picked &&
89 git ls-files --stage --unmerged > actual &&
@@ -102,10 +92,7 @@ test_expect_success 'failed cherry-pick registers participants in index' '
92 '
93
94 test_expect_success 'failed cherry-pick describes conflict in work tree' '
105 -
106 - git checkout -f initial^0 &&
107 - git read-tree -u --reset HEAD &&
108 - git clean -d -f -f -q -x &&
95 + pristine_detach initial &&
96 cat <<-EOF > expected &&
97 <<<<<<< HEAD
98 a
@@ -114,9 +101,6 @@ test_expect_success 'failed cherry-pick describes conflict in work tree' '
101 >>>>>>> objid picked
102 EOF
103
117 - git update-index --refresh &&
118 - git diff-index --exit-code HEAD &&
119 -
104 test_must_fail git cherry-pick picked &&
105
106 sed "s/[a-f0-9]*\.\.\./objid/" foo > actual &&
@@ -124,11 +108,8 @@ test_expect_success 'failed cherry-pick describes conflict in work tree' '
108 '
109
110 test_expect_success 'diff3 -m style' '
127 -
111 + pristine_detach initial &&
112 git config merge.conflictstyle diff3 &&
129 - git checkout -f initial^0 &&
130 - git read-tree -u --reset HEAD &&
131 - git clean -d -f -f -q -x &&
113 cat <<-EOF > expected &&
114 <<<<<<< HEAD
115 a
@@ -139,9 +120,6 @@ test_expect_success 'diff3 -m style' '
120 >>>>>>> objid picked
121 EOF
122
142 - git update-index --refresh &&
143 - git diff-index --exit-code HEAD &&
144 -
123 test_must_fail git cherry-pick picked &&
124
125 sed "s/[a-f0-9]*\.\.\./objid/" foo > actual &&
@@ -149,10 +127,8 @@ test_expect_success 'diff3 -m style' '
127 '
128
129 test_expect_success 'revert also handles conflicts sanely' '
152 -
130 git config --unset merge.conflictstyle &&
154 - git read-tree -u --reset HEAD &&
155 - git clean -d -f -f -q -x &&
131 + pristine_detach initial &&
132 cat <<-EOF > expected &&
133 <<<<<<< HEAD
134 a
@@ -173,10 +149,7 @@ test_expect_success 'revert also handles conflicts sanely' '
149 2 s/ 0 / 2 /
150 3 s/ 0 / 3 /
151 " < stages > expected-stages &&
176 - git checkout -f initial^0 &&
177 -
178 - git update-index --refresh &&
179 - git diff-index --exit-code HEAD &&
152 + git read-tree -u --reset HEAD &&
153
154 head=$(git rev-parse HEAD) &&
155 test_must_fail git revert picked &&
@@ -192,10 +165,8 @@ test_expect_success 'revert also handles conflicts sanely' '
165 '
166
167 test_expect_success 'revert conflict, diff3 -m style' '
168 + pristine_detach initial &&
169 git config merge.conflictstyle diff3 &&
196 - git checkout -f initial^0 &&
197 - git read-tree -u --reset HEAD &&
198 - git clean -d -f -f -q -x &&
170 cat <<-EOF > expected &&
171 <<<<<<< HEAD
172 a
@@ -206,9 +177,6 @@ test_expect_success 'revert conflict, diff3 -m style' '
177 >>>>>>> parent of objid picked
178 EOF
179
209 - git update-index --refresh &&
210 - git diff-index --exit-code HEAD &&
211 -
180 test_must_fail git revert picked &&
181
182 sed "s/[a-f0-9]*\.\.\./objid/" foo > actual &&