Skip to content

Commit 377a354

Browse files
djpohlygitster
authored andcommitted
t7003: ensure --prune-empty can prune root commit
New test to expose a bug in filter-branch whereby the root commit is never pruned, even though its tree is empty and --prune-empty is given. The setup isn't exactly pretty, but I couldn't think of a simpler way to create a parallel commit graph sans the first commit. Signed-off-by: Devin J. Pohly <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3b9e3c2 commit 377a354

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

t/t7003-filter-branch.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,27 @@ test_expect_success 'Tag name filtering allows slashes in tag names' '
313313
git cat-file tag X/2 > actual &&
314314
test_cmp expect actual
315315
'
316+
test_expect_success 'setup --prune-empty comparisons' '
317+
git checkout --orphan master-no-a &&
318+
git rm -rf . &&
319+
unset test_tick &&
320+
test_tick &&
321+
GIT_COMMITTER_DATE="@0 +0000" GIT_AUTHOR_DATE="@0 +0000" &&
322+
test_commit --notick B B.t B Bx &&
323+
git checkout -b branch-no-a Bx &&
324+
test_commit D D.t D Dx &&
325+
mkdir dir &&
326+
test_commit dir/D dir/D.t dir/D dir/Dx &&
327+
test_commit E E.t E Ex &&
328+
git checkout master-no-a &&
329+
test_commit C C.t C Cx &&
330+
git checkout branch-no-a &&
331+
git merge Cx -m "Merge tag '\''C'\'' into branch" &&
332+
git tag Fx &&
333+
test_commit G G.t G Gx &&
334+
test_commit H H.t H Hx &&
335+
git checkout branch
336+
'
316337

317338
test_expect_success 'Prune empty commits' '
318339
git rev-list HEAD > expect &&
@@ -341,6 +362,15 @@ test_expect_success 'prune empty works even without index/tree filters' '
341362
test_cmp expect actual
342363
'
343364

365+
test_expect_failure '--prune-empty is able to prune root commit' '
366+
git rev-list branch-no-a >expect &&
367+
git branch testing H &&
368+
git filter-branch -f --prune-empty --index-filter "git update-index --remove A.t" testing &&
369+
git rev-list testing >actual &&
370+
git branch -D testing &&
371+
test_cmp expect actual
372+
'
373+
344374
test_expect_success '--remap-to-ancestor with filename filters' '
345375
git checkout master &&
346376
git reset --hard A &&

0 commit comments

Comments
 (0)