Browse Source

Merge branch 'dp/filter-branch-prune-empty' into maint

"git filter-branch --prune-empty" drops a single-parent commit that
becomes a no-op, but did not drop a root commit whose tree is empty.

* dp/filter-branch-prune-empty:
  p7000: add test for filter-branch with --prune-empty
  filter-branch: fix --prune-empty on parentless commits
  t7003: ensure --prune-empty removes entire branch when applicable
  t7003: ensure --prune-empty can prune root commit
maint
Junio C Hamano 8 years ago
parent
commit
bfee58c0a5
  1. 14
      Documentation/git-filter-branch.txt
  2. 2
      git-filter-branch.sh
  3. 5
      t/perf/p7000-filter-branch.sh
  4. 37
      t/t7003-filter-branch.sh

14
Documentation/git-filter-branch.txt

@ -167,14 +167,12 @@ to other tags will be rewritten to point to the underlying commit.
project root. Implies <<Remap_to_ancestor>>. project root. Implies <<Remap_to_ancestor>>.


--prune-empty:: --prune-empty::
Some kind of filters will generate empty commits, that left the tree Some filters will generate empty commits that leave the tree untouched.
untouched. This switch allow git-filter-branch to ignore such This option instructs git-filter-branch to remove such commits if they
commits. Though, this switch only applies for commits that have one have exactly one or zero non-pruned parents; merge commits will
and only one parent, it will hence keep merges points. Also, this therefore remain intact. This option cannot be used together with
option is not compatible with the use of `--commit-filter`. Though you `--commit-filter`, though the same effect can be achieved by using the
just need to use the function 'git_commit_non_empty_tree "$@"' instead provided `git_commit_non_empty_tree` function in a commit filter.
of the `git commit-tree "$@"` idiom in your commit filter to make that
happen.


--original <namespace>:: --original <namespace>::
Use this option to set the namespace where the original commits Use this option to set the namespace where the original commits

2
git-filter-branch.sh

@ -46,6 +46,8 @@ git_commit_non_empty_tree()
{ {
if test $# = 3 && test "$1" = $(git rev-parse "$3^{tree}"); then if test $# = 3 && test "$1" = $(git rev-parse "$3^{tree}"); then
map "$3" map "$3"
elif test $# = 1 && test "$1" = 4b825dc642cb6eb9a060e54bf8d69288fbee4904; then
:
else else
git commit-tree "$@" git commit-tree "$@"
fi fi

5
t/perf/p7000-filter-branch.sh

@ -16,4 +16,9 @@ test_perf 'noop filter' '
git filter-branch -f base..HEAD 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 test_done

37
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 && git cat-file tag X/2 > actual &&
test_cmp expect 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' ' test_expect_success 'Prune empty commits' '
git rev-list HEAD > expect && git rev-list HEAD > expect &&
@ -341,6 +362,22 @@ test_expect_success 'prune empty works even without index/tree filters' '
test_cmp expect actual test_cmp expect actual
' '


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 &&
git rev-list testing >actual &&
git branch -D testing &&
test_cmp expect actual
'

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 &&
test_must_fail git reflog exists refs/heads/prune-entire
'

test_expect_success '--remap-to-ancestor with filename filters' ' test_expect_success '--remap-to-ancestor with filename filters' '
git checkout master && git checkout master &&
git reset --hard A && git reset --hard A &&

Loading…
Cancel
Save