Merge branch 'jh/notes' (early part)
[git/kusma.git] / t / t2030-unresolve-info.sh
bloba38bd6df8490e8c54c29a54084f2a5c232f24e15
1 #!/bin/sh
3 test_description='undoing resolution'
5 . ./test-lib.sh
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
15 path=$1
16 shift
17 for stage in 1 2 3
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"
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 &&
39 echo different >file &&
40 git add file &&
41 echo resolving records &&
42 check_resolve_undo recorded file initial:file second:file third:file
45 test_expect_success setup '
46 test_commit initial file first &&
47 git branch side &&
48 git branch another &&
49 test_commit second file second &&
50 git checkout side &&
51 test_commit third file third &&
52 git checkout another &&
53 test_commit fourth file fourth &&
54 git checkout master
57 test_expect_success 'add records switch clears' '
58 prime_resolve_undo &&
59 test_tick &&
60 git commit -m merged &&
61 echo committing keeps &&
62 check_resolve_undo kept file initial:file second:file third:file &&
63 git checkout second^0 &&
64 echo switching clears &&
65 check_resolve_undo cleared
68 test_expect_success 'rm records reset clears' '
69 prime_resolve_undo &&
70 test_tick &&
71 git commit -m merged &&
72 echo committing keeps &&
73 check_resolve_undo kept file initial:file second:file third:file &&
75 echo merge clears upfront &&
76 test_must_fail git merge fourth^0 &&
77 check_resolve_undo nuked &&
79 git rm -f file &&
80 echo resolving records &&
81 check_resolve_undo recorded file initial:file HEAD:file fourth:file &&
83 git reset --hard &&
84 echo resetting discards &&
85 check_resolve_undo discarded
88 test_expect_success 'plumbing clears' '
89 prime_resolve_undo &&
90 test_tick &&
91 git commit -m merged &&
92 echo committing keeps &&
93 check_resolve_undo kept file initial:file second:file third:file &&
95 echo plumbing clear &&
96 git update-index --clear-resolve-undo &&
97 check_resolve_undo cleared
100 test_expect_success 'add records checkout -m undoes' '
101 prime_resolve_undo &&
102 git diff HEAD &&
103 git checkout --conflict=merge file &&
104 echo checkout used the record and removed it &&
105 check_resolve_undo removed &&
106 echo the index and the work tree is unmerged again &&
107 git diff >actual &&
108 grep "^++<<<<<<<" actual
111 test_expect_success 'unmerge with plumbing' '
112 prime_resolve_undo &&
113 git update-index --unresolve file &&
114 git ls-files -u >actual &&
115 test $(wc -l <actual) = 3
118 test_expect_success 'rerere and rerere --forget' '
119 mkdir .git/rr-cache &&
120 prime_resolve_undo &&
121 echo record the resolution &&
122 git rerere &&
123 rerere_id=$(cd .git/rr-cache && echo */postimage) &&
124 rerere_id=${rerere_id%/postimage} &&
125 test -f .git/rr-cache/$rerere_id/postimage &&
126 git checkout -m file &&
127 echo resurrect the conflict &&
128 grep "^=======" file &&
129 echo reresolve the conflict &&
130 git rerere &&
131 test "z$(cat file)" = zdifferent &&
132 echo register the resolution again &&
133 git add file &&
134 check_resolve_undo kept file initial:file second:file third:file &&
135 test -z "$(git ls-files -u)" &&
136 git rerere forget file &&
137 ! test -f .git/rr-cache/$rerere_id/postimage &&
138 tr "\0" "\n" <.git/MERGE_RR >actual &&
139 echo "$rerere_id file" >expect &&
140 test_cmp expect actual
143 test_done