Junio C Hamano | 9d9a2f4 | 2009-12-25 10:08:04 -0800 | [diff] [blame] | 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 && |
Johannes Sixt | 5a9f039 | 2010-01-21 09:23:48 +0100 | [diff] [blame] | 39 | echo different >fi/le && |
| 40 | git add fi/le && |
Junio C Hamano | 9d9a2f4 | 2009-12-25 10:08:04 -0800 | [diff] [blame] | 41 | echo resolving records && |
Johannes Sixt | 5a9f039 | 2010-01-21 09:23:48 +0100 | [diff] [blame] | 42 | check_resolve_undo recorded fi/le initial:fi/le second:fi/le third:fi/le |
Junio C Hamano | 9d9a2f4 | 2009-12-25 10:08:04 -0800 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | test_expect_success setup ' |
Johannes Sixt | 5a9f039 | 2010-01-21 09:23:48 +0100 | [diff] [blame] | 46 | mkdir fi && |
| 47 | test_commit initial fi/le first && |
Junio C Hamano | 9d9a2f4 | 2009-12-25 10:08:04 -0800 | [diff] [blame] | 48 | git branch side && |
| 49 | git branch another && |
Johannes Sixt | 5a9f039 | 2010-01-21 09:23:48 +0100 | [diff] [blame] | 50 | test_commit second fi/le second && |
Junio C Hamano | 9d9a2f4 | 2009-12-25 10:08:04 -0800 | [diff] [blame] | 51 | git checkout side && |
Johannes Sixt | 5a9f039 | 2010-01-21 09:23:48 +0100 | [diff] [blame] | 52 | test_commit third fi/le third && |
Junio C Hamano | 9d9a2f4 | 2009-12-25 10:08:04 -0800 | [diff] [blame] | 53 | git checkout another && |
Johannes Sixt | 5a9f039 | 2010-01-21 09:23:48 +0100 | [diff] [blame] | 54 | test_commit fourth fi/le fourth && |
Junio C Hamano | 9d9a2f4 | 2009-12-25 10:08:04 -0800 | [diff] [blame] | 55 | git checkout master |
| 56 | ' |
| 57 | |
| 58 | test_expect_success 'add records switch clears' ' |
| 59 | prime_resolve_undo && |
| 60 | test_tick && |
| 61 | git commit -m merged && |
| 62 | echo committing keeps && |
Johannes Sixt | 5a9f039 | 2010-01-21 09:23:48 +0100 | [diff] [blame] | 63 | check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le && |
Junio C Hamano | 9d9a2f4 | 2009-12-25 10:08:04 -0800 | [diff] [blame] | 64 | git checkout second^0 && |
| 65 | echo switching clears && |
| 66 | check_resolve_undo cleared |
| 67 | ' |
| 68 | |
| 69 | test_expect_success 'rm records reset clears' ' |
| 70 | prime_resolve_undo && |
| 71 | test_tick && |
| 72 | git commit -m merged && |
| 73 | echo committing keeps && |
Johannes Sixt | 5a9f039 | 2010-01-21 09:23:48 +0100 | [diff] [blame] | 74 | check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le && |
Junio C Hamano | 9d9a2f4 | 2009-12-25 10:08:04 -0800 | [diff] [blame] | 75 | |
| 76 | echo merge clears upfront && |
| 77 | test_must_fail git merge fourth^0 && |
| 78 | check_resolve_undo nuked && |
| 79 | |
Johannes Sixt | 5a9f039 | 2010-01-21 09:23:48 +0100 | [diff] [blame] | 80 | git rm -f fi/le && |
Junio C Hamano | 9d9a2f4 | 2009-12-25 10:08:04 -0800 | [diff] [blame] | 81 | echo resolving records && |
Johannes Sixt | 5a9f039 | 2010-01-21 09:23:48 +0100 | [diff] [blame] | 82 | check_resolve_undo recorded fi/le initial:fi/le HEAD:fi/le fourth:fi/le && |
Junio C Hamano | 9d9a2f4 | 2009-12-25 10:08:04 -0800 | [diff] [blame] | 83 | |
| 84 | git reset --hard && |
| 85 | echo resetting discards && |
| 86 | check_resolve_undo discarded |
| 87 | ' |
| 88 | |
Junio C Hamano | 4a39f79 | 2009-12-25 10:31:26 -0800 | [diff] [blame] | 89 | test_expect_success 'plumbing clears' ' |
| 90 | prime_resolve_undo && |
| 91 | test_tick && |
| 92 | git commit -m merged && |
| 93 | echo committing keeps && |
Johannes Sixt | 5a9f039 | 2010-01-21 09:23:48 +0100 | [diff] [blame] | 94 | check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le && |
Junio C Hamano | 4a39f79 | 2009-12-25 10:31:26 -0800 | [diff] [blame] | 95 | |
| 96 | echo plumbing clear && |
| 97 | git update-index --clear-resolve-undo && |
| 98 | check_resolve_undo cleared |
| 99 | ' |
| 100 | |
Junio C Hamano | 4421a82 | 2009-12-25 11:57:11 -0800 | [diff] [blame] | 101 | test_expect_success 'add records checkout -m undoes' ' |
| 102 | prime_resolve_undo && |
| 103 | git diff HEAD && |
Johannes Sixt | 5a9f039 | 2010-01-21 09:23:48 +0100 | [diff] [blame] | 104 | git checkout --conflict=merge fi/le && |
Junio C Hamano | 4421a82 | 2009-12-25 11:57:11 -0800 | [diff] [blame] | 105 | echo checkout used the record and removed it && |
| 106 | check_resolve_undo removed && |
| 107 | echo the index and the work tree is unmerged again && |
| 108 | git diff >actual && |
| 109 | grep "^++<<<<<<<" actual |
| 110 | ' |
| 111 | |
Junio C Hamano | 8aa3856 | 2009-12-25 13:40:02 -0800 | [diff] [blame] | 112 | test_expect_success 'unmerge with plumbing' ' |
| 113 | prime_resolve_undo && |
Johannes Sixt | 5a9f039 | 2010-01-21 09:23:48 +0100 | [diff] [blame] | 114 | git update-index --unresolve fi/le && |
Junio C Hamano | 8aa3856 | 2009-12-25 13:40:02 -0800 | [diff] [blame] | 115 | git ls-files -u >actual && |
| 116 | test $(wc -l <actual) = 3 |
| 117 | ' |
| 118 | |
Johannes Sixt | 5a9f039 | 2010-01-21 09:23:48 +0100 | [diff] [blame] | 119 | test_expect_success 'rerere and rerere forget' ' |
Junio C Hamano | dea4562 | 2009-12-25 15:51:32 -0800 | [diff] [blame] | 120 | mkdir .git/rr-cache && |
| 121 | prime_resolve_undo && |
| 122 | echo record the resolution && |
| 123 | git rerere && |
| 124 | rerere_id=$(cd .git/rr-cache && echo */postimage) && |
| 125 | rerere_id=${rerere_id%/postimage} && |
| 126 | test -f .git/rr-cache/$rerere_id/postimage && |
Johannes Sixt | 5a9f039 | 2010-01-21 09:23:48 +0100 | [diff] [blame] | 127 | git checkout -m fi/le && |
Junio C Hamano | dea4562 | 2009-12-25 15:51:32 -0800 | [diff] [blame] | 128 | echo resurrect the conflict && |
Johannes Sixt | 5a9f039 | 2010-01-21 09:23:48 +0100 | [diff] [blame] | 129 | grep "^=======" fi/le && |
Junio C Hamano | dea4562 | 2009-12-25 15:51:32 -0800 | [diff] [blame] | 130 | echo reresolve the conflict && |
| 131 | git rerere && |
Johannes Sixt | 5a9f039 | 2010-01-21 09:23:48 +0100 | [diff] [blame] | 132 | test "z$(cat fi/le)" = zdifferent && |
Junio C Hamano | dea4562 | 2009-12-25 15:51:32 -0800 | [diff] [blame] | 133 | echo register the resolution again && |
Johannes Sixt | 5a9f039 | 2010-01-21 09:23:48 +0100 | [diff] [blame] | 134 | git add fi/le && |
| 135 | check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le && |
Junio C Hamano | dea4562 | 2009-12-25 15:51:32 -0800 | [diff] [blame] | 136 | test -z "$(git ls-files -u)" && |
Johannes Sixt | 5a9f039 | 2010-01-21 09:23:48 +0100 | [diff] [blame] | 137 | git rerere forget fi/le && |
Junio C Hamano | dea4562 | 2009-12-25 15:51:32 -0800 | [diff] [blame] | 138 | ! test -f .git/rr-cache/$rerere_id/postimage && |
| 139 | tr "\0" "\n" <.git/MERGE_RR >actual && |
Johannes Sixt | 5a9f039 | 2010-01-21 09:23:48 +0100 | [diff] [blame] | 140 | echo "$rerere_id fi/le" >expect && |
| 141 | test_cmp expect actual |
| 142 | ' |
| 143 | |
| 144 | test_expect_success 'rerere and rerere forget (subdirectory)' ' |
| 145 | rm -fr .git/rr-cache && |
| 146 | mkdir .git/rr-cache && |
| 147 | prime_resolve_undo && |
| 148 | echo record the resolution && |
| 149 | (cd fi && git rerere) && |
| 150 | rerere_id=$(cd .git/rr-cache && echo */postimage) && |
| 151 | rerere_id=${rerere_id%/postimage} && |
| 152 | test -f .git/rr-cache/$rerere_id/postimage && |
| 153 | (cd fi && git checkout -m le) && |
| 154 | echo resurrect the conflict && |
| 155 | grep "^=======" fi/le && |
| 156 | echo reresolve the conflict && |
| 157 | (cd fi && git rerere) && |
| 158 | test "z$(cat fi/le)" = zdifferent && |
| 159 | echo register the resolution again && |
| 160 | (cd fi && git add le) && |
| 161 | check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le && |
| 162 | test -z "$(git ls-files -u)" && |
| 163 | (cd fi && git rerere forget le) && |
| 164 | ! test -f .git/rr-cache/$rerere_id/postimage && |
| 165 | tr "\0" "\n" <.git/MERGE_RR >actual && |
| 166 | echo "$rerere_id fi/le" >expect && |
Junio C Hamano | dea4562 | 2009-12-25 15:51:32 -0800 | [diff] [blame] | 167 | test_cmp expect actual |
| 168 | ' |
| 169 | |
Junio C Hamano | 9d9a2f4 | 2009-12-25 10:08:04 -0800 | [diff] [blame] | 170 | test_done |