Skip to content

Commit 6d875d1

Browse files
peffgitster
authored andcommitted
t7003: test ref rewriting explicitly
After it has rewritten all of the commits, filter-branch will then rewrite each of the input refs based on the resulting map of old/new commits. But we don't have any explicit test coverage of this code. Let's make sure we are covering each of those cases: - deleting a ref when all of its commits were pruned - rewriting a ref based on the mapping (this happens throughout the script, but let's make sure we generate the correct messages) - rewriting a ref whose tip was excluded, in which case we rewrite to the nearest ancestor. Note in this case that we still insist that no "warning" line is present (even though it looks like we'd trigger the "... was rewritten into multiple commits" one). See the next commit for more details. Note these all pass currently, but the latter two will fail when run with GIT_TEST_DEFAULT_HASH=sha256. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 94f6e3e commit 6d875d1

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

t/t7003-filter-branch.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,4 +503,35 @@ test_expect_success 'rewrite repository including refs that point at non-commit
503503
! fgrep fatal filter-output
504504
'
505505

506+
test_expect_success 'filter-branch handles ref deletion' '
507+
git switch --orphan empty-commit &&
508+
git commit --allow-empty -m "empty commit" &&
509+
git tag empty &&
510+
git branch to-delete &&
511+
git filter-branch -f --prune-empty to-delete >out 2>&1 &&
512+
grep "to-delete.*was deleted" out &&
513+
test_must_fail git rev-parse --verify to-delete
514+
'
515+
516+
test_expect_success 'filter-branch handles ref rewrite' '
517+
git checkout empty &&
518+
test_commit to-drop &&
519+
git branch rewrite &&
520+
git filter-branch -f \
521+
--index-filter "git rm --ignore-unmatch --cached to-drop.t" \
522+
rewrite >out 2>&1 &&
523+
grep "rewrite.*was rewritten" out &&
524+
! grep -i warning out &&
525+
git diff-tree empty rewrite
526+
'
527+
528+
test_expect_success 'filter-branch handles ancestor rewrite' '
529+
test_commit to-exclude &&
530+
git branch ancestor &&
531+
git filter-branch -f ancestor -- :^to-exclude.t >out 2>&1 &&
532+
grep "ancestor.*was rewritten" out &&
533+
! grep -i warning out &&
534+
git diff-tree HEAD^ ancestor
535+
'
536+
506537
test_done

0 commit comments

Comments
 (0)