resolve-undo: "checkout -m path" uses resolve-undo information
[git/git.git] / t / t2030-unresolve-info.sh
CommitLineData
9d9a2f4a
JH
1#!/bin/sh
2
3test_description='undoing resolution'
4
5. ./test-lib.sh
6
7check_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
32prime_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
43}
44
45test_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
55'
56
57test_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
66'
67
68test_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 &&
74
75 echo merge clears upfront &&
76 test_must_fail git merge fourth^0 &&
77 check_resolve_undo nuked &&
78
79 git rm -f file &&
80 echo resolving records &&
81 check_resolve_undo recorded file initial:file HEAD:file fourth:file &&
82
83 git reset --hard &&
84 echo resetting discards &&
85 check_resolve_undo discarded
86'
87
4a39f79d
JH
88test_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 &&
94
95 echo plumbing clear &&
96 git update-index --clear-resolve-undo &&
97 check_resolve_undo cleared
98'
99
4421a823
JH
100test_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
109'
110
9d9a2f4a 111test_done