]>
Commit | Line | Data |
---|---|---|
9d9a2f4a JH |
1 | #!/bin/sh |
2 | ||
3 | test_description='undoing resolution' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | check_resolve_undo () { | |
8 | msg=$1 | |
9 | shift | |
10 | while case $# in | |
11 | 0) break ;; | |
12 | 1|2|3) die "Bug in check-resolve-undo test" ;; | |
13 | esac | |
14 | do | |
15 | path=$1 | |
16 | shift | |
17 | for stage in 1 2 3 | |
18 | do | |
19 | sha1=$1 | |
20 | shift | |
21 | case "$sha1" in | |
22 | '') continue ;; | |
23 | esac | |
24 | sha1=$(git rev-parse --verify "$sha1") | |
25 | printf "100644 %s %s\t%s\n" $sha1 $stage $path | |
26 | done | |
27 | done >"$msg.expect" && | |
28 | git ls-files --resolve-undo >"$msg.actual" && | |
29 | test_cmp "$msg.expect" "$msg.actual" | |
30 | } | |
31 | ||
32 | prime_resolve_undo () { | |
33 | git reset --hard && | |
34 | git checkout second^0 && | |
35 | test_tick && | |
36 | test_must_fail git merge third^0 && | |
37 | echo merge does not leave anything && | |
38 | check_resolve_undo empty && | |
5a9f0395 JS |
39 | echo different >fi/le && |
40 | git add fi/le && | |
9d9a2f4a | 41 | echo resolving records && |
5a9f0395 | 42 | check_resolve_undo recorded fi/le initial:fi/le second:fi/le third:fi/le |
9d9a2f4a JH |
43 | } |
44 | ||
45 | test_expect_success setup ' | |
5a9f0395 | 46 | mkdir fi && |
53d8afaf JS |
47 | printf "a\0a" >binary && |
48 | git add binary && | |
5a9f0395 | 49 | test_commit initial fi/le first && |
9d9a2f4a JH |
50 | git branch side && |
51 | git branch another && | |
53d8afaf JS |
52 | printf "a\0b" >binary && |
53 | git add binary && | |
5a9f0395 | 54 | test_commit second fi/le second && |
9d9a2f4a | 55 | git checkout side && |
5a9f0395 | 56 | test_commit third fi/le third && |
9d9a2f4a | 57 | git checkout another && |
5a9f0395 | 58 | test_commit fourth fi/le fourth && |
9d9a2f4a JH |
59 | git checkout master |
60 | ' | |
61 | ||
62 | test_expect_success 'add records switch clears' ' | |
63 | prime_resolve_undo && | |
64 | test_tick && | |
65 | git commit -m merged && | |
66 | echo committing keeps && | |
5a9f0395 | 67 | check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le && |
9d9a2f4a JH |
68 | git checkout second^0 && |
69 | echo switching clears && | |
70 | check_resolve_undo cleared | |
71 | ' | |
72 | ||
73 | test_expect_success 'rm records reset clears' ' | |
74 | prime_resolve_undo && | |
75 | test_tick && | |
76 | git commit -m merged && | |
77 | echo committing keeps && | |
5a9f0395 | 78 | check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le && |
9d9a2f4a JH |
79 | |
80 | echo merge clears upfront && | |
81 | test_must_fail git merge fourth^0 && | |
82 | check_resolve_undo nuked && | |
83 | ||
5a9f0395 | 84 | git rm -f fi/le && |
9d9a2f4a | 85 | echo resolving records && |
5a9f0395 | 86 | check_resolve_undo recorded fi/le initial:fi/le HEAD:fi/le fourth:fi/le && |
9d9a2f4a JH |
87 | |
88 | git reset --hard && | |
89 | echo resetting discards && | |
90 | check_resolve_undo discarded | |
91 | ' | |
92 | ||
4a39f79d JH |
93 | test_expect_success 'plumbing clears' ' |
94 | prime_resolve_undo && | |
95 | test_tick && | |
96 | git commit -m merged && | |
97 | echo committing keeps && | |
5a9f0395 | 98 | check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le && |
4a39f79d JH |
99 | |
100 | echo plumbing clear && | |
101 | git update-index --clear-resolve-undo && | |
102 | check_resolve_undo cleared | |
103 | ' | |
104 | ||
4421a823 JH |
105 | test_expect_success 'add records checkout -m undoes' ' |
106 | prime_resolve_undo && | |
107 | git diff HEAD && | |
5a9f0395 | 108 | git checkout --conflict=merge fi/le && |
4421a823 JH |
109 | echo checkout used the record and removed it && |
110 | check_resolve_undo removed && | |
111 | echo the index and the work tree is unmerged again && | |
112 | git diff >actual && | |
113 | grep "^++<<<<<<<" actual | |
114 | ' | |
115 | ||
8aa38563 JH |
116 | test_expect_success 'unmerge with plumbing' ' |
117 | prime_resolve_undo && | |
5a9f0395 | 118 | git update-index --unresolve fi/le && |
8aa38563 | 119 | git ls-files -u >actual && |
3fb0459b | 120 | test_line_count = 3 actual |
8aa38563 JH |
121 | ' |
122 | ||
5a9f0395 | 123 | test_expect_success 'rerere and rerere forget' ' |
dea4562b JH |
124 | mkdir .git/rr-cache && |
125 | prime_resolve_undo && | |
126 | echo record the resolution && | |
127 | git rerere && | |
128 | rerere_id=$(cd .git/rr-cache && echo */postimage) && | |
129 | rerere_id=${rerere_id%/postimage} && | |
130 | test -f .git/rr-cache/$rerere_id/postimage && | |
5a9f0395 | 131 | git checkout -m fi/le && |
dea4562b | 132 | echo resurrect the conflict && |
5a9f0395 | 133 | grep "^=======" fi/le && |
dea4562b JH |
134 | echo reresolve the conflict && |
135 | git rerere && | |
5a9f0395 | 136 | test "z$(cat fi/le)" = zdifferent && |
dea4562b | 137 | echo register the resolution again && |
5a9f0395 JS |
138 | git add fi/le && |
139 | check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le && | |
dea4562b | 140 | test -z "$(git ls-files -u)" && |
5a9f0395 | 141 | git rerere forget fi/le && |
dea4562b JH |
142 | ! test -f .git/rr-cache/$rerere_id/postimage && |
143 | tr "\0" "\n" <.git/MERGE_RR >actual && | |
5a9f0395 JS |
144 | echo "$rerere_id fi/le" >expect && |
145 | test_cmp expect actual | |
146 | ' | |
147 | ||
148 | test_expect_success 'rerere and rerere forget (subdirectory)' ' | |
149 | rm -fr .git/rr-cache && | |
150 | mkdir .git/rr-cache && | |
151 | prime_resolve_undo && | |
152 | echo record the resolution && | |
153 | (cd fi && git rerere) && | |
154 | rerere_id=$(cd .git/rr-cache && echo */postimage) && | |
155 | rerere_id=${rerere_id%/postimage} && | |
156 | test -f .git/rr-cache/$rerere_id/postimage && | |
157 | (cd fi && git checkout -m le) && | |
158 | echo resurrect the conflict && | |
159 | grep "^=======" fi/le && | |
160 | echo reresolve the conflict && | |
161 | (cd fi && git rerere) && | |
162 | test "z$(cat fi/le)" = zdifferent && | |
163 | echo register the resolution again && | |
164 | (cd fi && git add le) && | |
165 | check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le && | |
166 | test -z "$(git ls-files -u)" && | |
167 | (cd fi && git rerere forget le) && | |
168 | ! test -f .git/rr-cache/$rerere_id/postimage && | |
169 | tr "\0" "\n" <.git/MERGE_RR >actual && | |
170 | echo "$rerere_id fi/le" >expect && | |
dea4562b JH |
171 | test_cmp expect actual |
172 | ' | |
173 | ||
53d8afaf JS |
174 | test_expect_success 'rerere forget (binary)' ' |
175 | git checkout -f side && | |
176 | printf "a\0c" >binary && | |
177 | git commit -a -m binary && | |
178 | test_must_fail git merge second && | |
179 | git rerere forget binary | |
180 | ' | |
181 | ||
9d9a2f4a | 182 | test_done |