Make 'rerere forget' work from a subdirectory.

It forgot to apply the prefix to the paths given on the command line.

[jc: added test]

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Johannes Sixt
2010-01-21 09:23:48 +01:00
committed by Junio C Hamano
parent 28414b6b3a
commit 5a9f039529
2 changed files with 53 additions and 24 deletions

View File

@ -120,8 +120,10 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)
if (argc < 2) if (argc < 2)
return rerere(flags); return rerere(flags);
if (!strcmp(argv[1], "forget")) if (!strcmp(argv[1], "forget")) {
return rerere_forget(argv + 2); const char **pathspec = get_pathspec(prefix, argv + 2);
return rerere_forget(pathspec);
}
fd = setup_rerere(&merge_rr, flags); fd = setup_rerere(&merge_rr, flags);
if (fd < 0) if (fd < 0)

View File

@ -36,21 +36,22 @@ prime_resolve_undo () {
test_must_fail git merge third^0 && test_must_fail git merge third^0 &&
echo merge does not leave anything && echo merge does not leave anything &&
check_resolve_undo empty && check_resolve_undo empty &&
echo different >file && echo different >fi/le &&
git add file && git add fi/le &&
echo resolving records && echo resolving records &&
check_resolve_undo recorded file initial:file second:file third:file check_resolve_undo recorded fi/le initial:fi/le second:fi/le third:fi/le
} }
test_expect_success setup ' test_expect_success setup '
test_commit initial file first && mkdir fi &&
test_commit initial fi/le first &&
git branch side && git branch side &&
git branch another && git branch another &&
test_commit second file second && test_commit second fi/le second &&
git checkout side && git checkout side &&
test_commit third file third && test_commit third fi/le third &&
git checkout another && git checkout another &&
test_commit fourth file fourth && test_commit fourth fi/le fourth &&
git checkout master git checkout master
' '
@ -59,7 +60,7 @@ test_expect_success 'add records switch clears' '
test_tick && test_tick &&
git commit -m merged && git commit -m merged &&
echo committing keeps && echo committing keeps &&
check_resolve_undo kept file initial:file second:file third:file && check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le &&
git checkout second^0 && git checkout second^0 &&
echo switching clears && echo switching clears &&
check_resolve_undo cleared check_resolve_undo cleared
@ -70,15 +71,15 @@ test_expect_success 'rm records reset clears' '
test_tick && test_tick &&
git commit -m merged && git commit -m merged &&
echo committing keeps && echo committing keeps &&
check_resolve_undo kept file initial:file second:file third:file && check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le &&
echo merge clears upfront && echo merge clears upfront &&
test_must_fail git merge fourth^0 && test_must_fail git merge fourth^0 &&
check_resolve_undo nuked && check_resolve_undo nuked &&
git rm -f file && git rm -f fi/le &&
echo resolving records && echo resolving records &&
check_resolve_undo recorded file initial:file HEAD:file fourth:file && check_resolve_undo recorded fi/le initial:fi/le HEAD:fi/le fourth:fi/le &&
git reset --hard && git reset --hard &&
echo resetting discards && echo resetting discards &&
@ -90,7 +91,7 @@ test_expect_success 'plumbing clears' '
test_tick && test_tick &&
git commit -m merged && git commit -m merged &&
echo committing keeps && echo committing keeps &&
check_resolve_undo kept file initial:file second:file third:file && check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le &&
echo plumbing clear && echo plumbing clear &&
git update-index --clear-resolve-undo && git update-index --clear-resolve-undo &&
@ -100,7 +101,7 @@ test_expect_success 'plumbing clears' '
test_expect_success 'add records checkout -m undoes' ' test_expect_success 'add records checkout -m undoes' '
prime_resolve_undo && prime_resolve_undo &&
git diff HEAD && git diff HEAD &&
git checkout --conflict=merge file && git checkout --conflict=merge fi/le &&
echo checkout used the record and removed it && echo checkout used the record and removed it &&
check_resolve_undo removed && check_resolve_undo removed &&
echo the index and the work tree is unmerged again && echo the index and the work tree is unmerged again &&
@ -110,12 +111,12 @@ test_expect_success 'add records checkout -m undoes' '
test_expect_success 'unmerge with plumbing' ' test_expect_success 'unmerge with plumbing' '
prime_resolve_undo && prime_resolve_undo &&
git update-index --unresolve file && git update-index --unresolve fi/le &&
git ls-files -u >actual && git ls-files -u >actual &&
test $(wc -l <actual) = 3 test $(wc -l <actual) = 3
' '
test_expect_success 'rerere and rerere --forget' ' test_expect_success 'rerere and rerere forget' '
mkdir .git/rr-cache && mkdir .git/rr-cache &&
prime_resolve_undo && prime_resolve_undo &&
echo record the resolution && echo record the resolution &&
@ -123,20 +124,46 @@ test_expect_success 'rerere and rerere --forget' '
rerere_id=$(cd .git/rr-cache && echo */postimage) && rerere_id=$(cd .git/rr-cache && echo */postimage) &&
rerere_id=${rerere_id%/postimage} && rerere_id=${rerere_id%/postimage} &&
test -f .git/rr-cache/$rerere_id/postimage && test -f .git/rr-cache/$rerere_id/postimage &&
git checkout -m file && git checkout -m fi/le &&
echo resurrect the conflict && echo resurrect the conflict &&
grep "^=======" file && grep "^=======" fi/le &&
echo reresolve the conflict && echo reresolve the conflict &&
git rerere && git rerere &&
test "z$(cat file)" = zdifferent && test "z$(cat fi/le)" = zdifferent &&
echo register the resolution again && echo register the resolution again &&
git add file && git add fi/le &&
check_resolve_undo kept file initial:file second:file third:file && check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le &&
test -z "$(git ls-files -u)" && test -z "$(git ls-files -u)" &&
git rerere forget file && git rerere forget fi/le &&
! test -f .git/rr-cache/$rerere_id/postimage && ! test -f .git/rr-cache/$rerere_id/postimage &&
tr "\0" "\n" <.git/MERGE_RR >actual && tr "\0" "\n" <.git/MERGE_RR >actual &&
echo "$rerere_id file" >expect && 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 &&
test_cmp expect actual test_cmp expect actual
' '