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 <djpohly@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Devin J. Pohly committed Feb 23, 2017 at 02:27 UTC 377a3543898815dda82e0b33de152958318e7bff
1 file changed +30
t/t7003-filter-branch.sh
+30
@@ -313,6 +313,27 @@ test_expect_success 'Tag name filtering allows slashes in tag names' '
313 git cat-file tag X/2 > actual &&
314 test_cmp expect actual
315 '
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 +'
337
338 test_expect_success 'Prune empty commits' '
339 git rev-list HEAD > expect &&
@@ -341,6 +362,15 @@ test_expect_success 'prune empty works even without index/tree filters' '
362 test_cmp expect actual
363 '
364
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 +
374 test_expect_success '--remap-to-ancestor with filename filters' '
375 git checkout master &&
376 git reset --hard A &&