2009-12-25 18:08:04 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='undoing resolution'
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
check_resolve_undo () {
|
|
|
|
msg=$1
|
|
|
|
shift
|
|
|
|
while case $# in
|
|
|
|
0) break ;;
|
|
|
|
1|2|3) die "Bug in check-resolve-undo test" ;;
|
|
|
|
esac
|
|
|
|
do
|
|
|
|
path=$1
|
|
|
|
shift
|
|
|
|
for stage in 1 2 3
|
|
|
|
do
|
|
|
|
sha1=$1
|
|
|
|
shift
|
|
|
|
case "$sha1" in
|
|
|
|
'') continue ;;
|
|
|
|
esac
|
|
|
|
sha1=$(git rev-parse --verify "$sha1")
|
|
|
|
printf "100644 %s %s\t%s\n" $sha1 $stage $path
|
|
|
|
done
|
|
|
|
done >"$msg.expect" &&
|
|
|
|
git ls-files --resolve-undo >"$msg.actual" &&
|
|
|
|
test_cmp "$msg.expect" "$msg.actual"
|
|
|
|
}
|
|
|
|
|
|
|
|
prime_resolve_undo () {
|
|
|
|
git reset --hard &&
|
|
|
|
git checkout second^0 &&
|
|
|
|
test_tick &&
|
|
|
|
test_must_fail git merge third^0 &&
|
|
|
|
echo merge does not leave anything &&
|
|
|
|
check_resolve_undo empty &&
|
2010-01-21 08:23:48 +00:00
|
|
|
echo different >fi/le &&
|
|
|
|
git add fi/le &&
|
2009-12-25 18:08:04 +00:00
|
|
|
echo resolving records &&
|
2010-01-21 08:23:48 +00:00
|
|
|
check_resolve_undo recorded fi/le initial:fi/le second:fi/le third:fi/le
|
2009-12-25 18:08:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test_expect_success setup '
|
2010-01-21 08:23:48 +00:00
|
|
|
mkdir fi &&
|
2013-04-01 21:36:36 +00:00
|
|
|
printf "a\0a" >binary &&
|
|
|
|
git add binary &&
|
2010-01-21 08:23:48 +00:00
|
|
|
test_commit initial fi/le first &&
|
2009-12-25 18:08:04 +00:00
|
|
|
git branch side &&
|
|
|
|
git branch another &&
|
2013-04-01 21:36:36 +00:00
|
|
|
printf "a\0b" >binary &&
|
|
|
|
git add binary &&
|
2010-01-21 08:23:48 +00:00
|
|
|
test_commit second fi/le second &&
|
2009-12-25 18:08:04 +00:00
|
|
|
git checkout side &&
|
2010-01-21 08:23:48 +00:00
|
|
|
test_commit third fi/le third &&
|
2013-04-04 18:41:43 +00:00
|
|
|
git branch add-add &&
|
2009-12-25 18:08:04 +00:00
|
|
|
git checkout another &&
|
2010-01-21 08:23:48 +00:00
|
|
|
test_commit fourth fi/le fourth &&
|
2013-04-04 18:41:43 +00:00
|
|
|
git checkout add-add &&
|
|
|
|
test_commit fifth add-differently &&
|
2009-12-25 18:08:04 +00:00
|
|
|
git checkout master
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'add records switch clears' '
|
|
|
|
prime_resolve_undo &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m merged &&
|
|
|
|
echo committing keeps &&
|
2010-01-21 08:23:48 +00:00
|
|
|
check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le &&
|
2009-12-25 18:08:04 +00:00
|
|
|
git checkout second^0 &&
|
|
|
|
echo switching clears &&
|
|
|
|
check_resolve_undo cleared
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'rm records reset clears' '
|
|
|
|
prime_resolve_undo &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m merged &&
|
|
|
|
echo committing keeps &&
|
2010-01-21 08:23:48 +00:00
|
|
|
check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le &&
|
2009-12-25 18:08:04 +00:00
|
|
|
|
|
|
|
echo merge clears upfront &&
|
|
|
|
test_must_fail git merge fourth^0 &&
|
|
|
|
check_resolve_undo nuked &&
|
|
|
|
|
2010-01-21 08:23:48 +00:00
|
|
|
git rm -f fi/le &&
|
2009-12-25 18:08:04 +00:00
|
|
|
echo resolving records &&
|
2010-01-21 08:23:48 +00:00
|
|
|
check_resolve_undo recorded fi/le initial:fi/le HEAD:fi/le fourth:fi/le &&
|
2009-12-25 18:08:04 +00:00
|
|
|
|
|
|
|
git reset --hard &&
|
|
|
|
echo resetting discards &&
|
|
|
|
check_resolve_undo discarded
|
|
|
|
'
|
|
|
|
|
2009-12-25 18:31:26 +00:00
|
|
|
test_expect_success 'plumbing clears' '
|
|
|
|
prime_resolve_undo &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m merged &&
|
|
|
|
echo committing keeps &&
|
2010-01-21 08:23:48 +00:00
|
|
|
check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le &&
|
2009-12-25 18:31:26 +00:00
|
|
|
|
|
|
|
echo plumbing clear &&
|
|
|
|
git update-index --clear-resolve-undo &&
|
|
|
|
check_resolve_undo cleared
|
|
|
|
'
|
|
|
|
|
2009-12-25 19:57:11 +00:00
|
|
|
test_expect_success 'add records checkout -m undoes' '
|
|
|
|
prime_resolve_undo &&
|
|
|
|
git diff HEAD &&
|
2010-01-21 08:23:48 +00:00
|
|
|
git checkout --conflict=merge fi/le &&
|
2009-12-25 19:57:11 +00:00
|
|
|
echo checkout used the record and removed it &&
|
|
|
|
check_resolve_undo removed &&
|
|
|
|
echo the index and the work tree is unmerged again &&
|
|
|
|
git diff >actual &&
|
|
|
|
grep "^++<<<<<<<" actual
|
|
|
|
'
|
|
|
|
|
2009-12-25 21:40:02 +00:00
|
|
|
test_expect_success 'unmerge with plumbing' '
|
|
|
|
prime_resolve_undo &&
|
2010-01-21 08:23:48 +00:00
|
|
|
git update-index --unresolve fi/le &&
|
2009-12-25 21:40:02 +00:00
|
|
|
git ls-files -u >actual &&
|
2012-04-11 11:24:01 +00:00
|
|
|
test_line_count = 3 actual
|
2009-12-25 21:40:02 +00:00
|
|
|
'
|
|
|
|
|
2010-01-21 08:23:48 +00:00
|
|
|
test_expect_success 'rerere and rerere forget' '
|
2009-12-25 23:51:32 +00:00
|
|
|
mkdir .git/rr-cache &&
|
|
|
|
prime_resolve_undo &&
|
|
|
|
echo record the resolution &&
|
|
|
|
git rerere &&
|
|
|
|
rerere_id=$(cd .git/rr-cache && echo */postimage) &&
|
|
|
|
rerere_id=${rerere_id%/postimage} &&
|
|
|
|
test -f .git/rr-cache/$rerere_id/postimage &&
|
2010-01-21 08:23:48 +00:00
|
|
|
git checkout -m fi/le &&
|
2009-12-25 23:51:32 +00:00
|
|
|
echo resurrect the conflict &&
|
2010-01-21 08:23:48 +00:00
|
|
|
grep "^=======" fi/le &&
|
2009-12-25 23:51:32 +00:00
|
|
|
echo reresolve the conflict &&
|
|
|
|
git rerere &&
|
2010-01-21 08:23:48 +00:00
|
|
|
test "z$(cat fi/le)" = zdifferent &&
|
2009-12-25 23:51:32 +00:00
|
|
|
echo register the resolution again &&
|
2010-01-21 08:23:48 +00:00
|
|
|
git add fi/le &&
|
|
|
|
check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le &&
|
2009-12-25 23:51:32 +00:00
|
|
|
test -z "$(git ls-files -u)" &&
|
2010-01-21 08:23:48 +00:00
|
|
|
git rerere forget fi/le &&
|
2009-12-25 23:51:32 +00:00
|
|
|
! test -f .git/rr-cache/$rerere_id/postimage &&
|
|
|
|
tr "\0" "\n" <.git/MERGE_RR >actual &&
|
2010-01-21 08:23:48 +00:00
|
|
|
echo "$rerere_id fi/le" >expect &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'rerere and rerere forget (subdirectory)' '
|
|
|
|
rm -fr .git/rr-cache &&
|
|
|
|
mkdir .git/rr-cache &&
|
|
|
|
prime_resolve_undo &&
|
|
|
|
echo record the resolution &&
|
|
|
|
(cd fi && git rerere) &&
|
|
|
|
rerere_id=$(cd .git/rr-cache && echo */postimage) &&
|
|
|
|
rerere_id=${rerere_id%/postimage} &&
|
|
|
|
test -f .git/rr-cache/$rerere_id/postimage &&
|
|
|
|
(cd fi && git checkout -m le) &&
|
|
|
|
echo resurrect the conflict &&
|
|
|
|
grep "^=======" fi/le &&
|
|
|
|
echo reresolve the conflict &&
|
|
|
|
(cd fi && git rerere) &&
|
|
|
|
test "z$(cat fi/le)" = zdifferent &&
|
|
|
|
echo register the resolution again &&
|
|
|
|
(cd fi && git add le) &&
|
|
|
|
check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le &&
|
|
|
|
test -z "$(git ls-files -u)" &&
|
|
|
|
(cd fi && git rerere forget le) &&
|
|
|
|
! test -f .git/rr-cache/$rerere_id/postimage &&
|
|
|
|
tr "\0" "\n" <.git/MERGE_RR >actual &&
|
|
|
|
echo "$rerere_id fi/le" >expect &&
|
2009-12-25 23:51:32 +00:00
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2013-04-01 21:36:36 +00:00
|
|
|
test_expect_success 'rerere forget (binary)' '
|
|
|
|
git checkout -f side &&
|
|
|
|
printf "a\0c" >binary &&
|
|
|
|
git commit -a -m binary &&
|
|
|
|
test_must_fail git merge second &&
|
|
|
|
git rerere forget binary
|
|
|
|
'
|
|
|
|
|
2013-04-04 18:41:43 +00:00
|
|
|
test_expect_success 'rerere forget (add-add conflict)' '
|
|
|
|
git checkout -f master &&
|
|
|
|
echo master >add-differently &&
|
|
|
|
git add add-differently &&
|
|
|
|
git commit -m "add differently" &&
|
|
|
|
test_must_fail git merge fifth &&
|
|
|
|
git rerere forget add-differently 2>actual &&
|
|
|
|
test_i18ngrep "no remembered" actual
|
|
|
|
'
|
|
|
|
|
2009-12-25 18:08:04 +00:00
|
|
|
test_done
|