From 377a3543898815dda82e0b33de152958318e7bff Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Thu, 23 Feb 2017 02:27:33 -0600 Subject: 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 Signed-off-by: Junio C Hamano --- t/t7003-filter-branch.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 't') diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh index cb8fbd8e5e..45372a1cba 100755 --- a/t/t7003-filter-branch.sh +++ b/t/t7003-filter-branch.sh @@ -313,6 +313,27 @@ test_expect_success 'Tag name filtering allows slashes in tag names' ' git cat-file tag X/2 > actual && test_cmp expect actual ' +test_expect_success 'setup --prune-empty comparisons' ' + git checkout --orphan master-no-a && + git rm -rf . && + unset test_tick && + test_tick && + GIT_COMMITTER_DATE="@0 +0000" GIT_AUTHOR_DATE="@0 +0000" && + test_commit --notick B B.t B Bx && + git checkout -b branch-no-a Bx && + test_commit D D.t D Dx && + mkdir dir && + test_commit dir/D dir/D.t dir/D dir/Dx && + test_commit E E.t E Ex && + git checkout master-no-a && + test_commit C C.t C Cx && + git checkout branch-no-a && + git merge Cx -m "Merge tag '\''C'\'' into branch" && + git tag Fx && + test_commit G G.t G Gx && + test_commit H H.t H Hx && + git checkout branch +' test_expect_success 'Prune empty commits' ' git rev-list HEAD > expect && @@ -341,6 +362,15 @@ test_expect_success 'prune empty works even without index/tree filters' ' test_cmp expect actual ' +test_expect_failure '--prune-empty is able to prune root commit' ' + git rev-list branch-no-a >expect && + git branch testing H && + git filter-branch -f --prune-empty --index-filter "git update-index --remove A.t" testing && + git rev-list testing >actual && + git branch -D testing && + test_cmp expect actual +' + test_expect_success '--remap-to-ancestor with filename filters' ' git checkout master && git reset --hard A && -- cgit v1.2.1 From 4dacc8f11d4acfb43d76e2a1abc2d2a57d5a2691 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Thu, 23 Feb 2017 02:27:34 -0600 Subject: t7003: ensure --prune-empty removes entire branch when applicable Sanity check before changing the logic in git_commit_non_empty_tree. Signed-off-by: Devin J. Pohly Signed-off-by: Junio C Hamano --- t/t7003-filter-branch.sh | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 't') diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh index 45372a1cba..40526d1716 100755 --- a/t/t7003-filter-branch.sh +++ b/t/t7003-filter-branch.sh @@ -371,6 +371,13 @@ test_expect_failure '--prune-empty is able to prune root commit' ' test_cmp expect actual ' +test_expect_failure '--prune-empty is able to prune entire branch' ' + git branch prune-entire B && + git filter-branch -f --prune-empty --index-filter "git update-index --remove A.t B.t" prune-entire && + test_path_is_missing .git/refs/heads/prune-entire && + test_must_fail git reflog exists refs/heads/prune-entire +' + test_expect_success '--remap-to-ancestor with filename filters' ' git checkout master && git reset --hard A && -- cgit v1.2.1 From a582a82d2444b627260a764c17d3137d9d255531 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Thu, 23 Feb 2017 02:27:35 -0600 Subject: filter-branch: fix --prune-empty on parentless commits Previously, the git_commit_non_empty_tree function would always pass any commit with no parents to git-commit-tree, regardless of whether the tree was nonempty. The new commit would then be recorded in the filter-branch revision map, and subsequent commits which leave the tree untouched would be correctly filtered. With this change, parentless commits with an empty tree are correctly pruned, and an empty file is recorded in the revision map, signifying that it was rewritten to "no commits." This works naturally with the parent mapping for subsequent commits. Signed-off-by: Devin J. Pohly Signed-off-by: Junio C Hamano --- t/t7003-filter-branch.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 't') diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh index 40526d1716..7cb60799be 100755 --- a/t/t7003-filter-branch.sh +++ b/t/t7003-filter-branch.sh @@ -362,7 +362,7 @@ test_expect_success 'prune empty works even without index/tree filters' ' test_cmp expect actual ' -test_expect_failure '--prune-empty is able to prune root commit' ' +test_expect_success '--prune-empty is able to prune root commit' ' git rev-list branch-no-a >expect && git branch testing H && git filter-branch -f --prune-empty --index-filter "git update-index --remove A.t" testing && @@ -371,7 +371,7 @@ test_expect_failure '--prune-empty is able to prune root commit' ' test_cmp expect actual ' -test_expect_failure '--prune-empty is able to prune entire branch' ' +test_expect_success '--prune-empty is able to prune entire branch' ' git branch prune-entire B && git filter-branch -f --prune-empty --index-filter "git update-index --remove A.t B.t" prune-entire && test_path_is_missing .git/refs/heads/prune-entire && -- cgit v1.2.1 From 32da7467ebc099e6032590773827884b704980cf Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Thu, 23 Feb 2017 02:27:36 -0600 Subject: p7000: add test for filter-branch with --prune-empty Signed-off-by: Devin J. Pohly Signed-off-by: Junio C Hamano --- t/perf/p7000-filter-branch.sh | 5 +++++ 1 file changed, 5 insertions(+) (limited to 't') diff --git a/t/perf/p7000-filter-branch.sh b/t/perf/p7000-filter-branch.sh index 15ee5d1d53..b029586ccb 100755 --- a/t/perf/p7000-filter-branch.sh +++ b/t/perf/p7000-filter-branch.sh @@ -16,4 +16,9 @@ test_perf 'noop filter' ' git filter-branch -f base..HEAD ' +test_perf 'noop prune-empty' ' + git checkout --detach tip && + git filter-branch -f --prune-empty base..HEAD +' + test_done -- cgit v1.2.1