Skip to content

Commit cfabd6e

Browse files
Johannes Sixtgitster
authored andcommitted
filter-branch: subdirectory filter needs --full-history
When two branches are merged that modify a subdirectory (possibly in different intermediate steps) such that both end up identical, then rev-list chooses only one branch. But when we filter history, we want to keep both branches. Therefore, we must use --full-history. Signed-off-by: Johannes Sixt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 813b473 commit cfabd6e

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

git-filter-branch.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ case "$filter_subdir" in
323323
;;
324324
*)
325325
git-rev-list --reverse --topo-order --default HEAD \
326-
--parents "$@" -- "$filter_subdir"
326+
--parents --full-history "$@" -- "$filter_subdir"
327327
esac > ../revs
328328
commits=$(cat ../revs | wc -l | tr -d " ")
329329

t/t7003-filter-branch.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,25 @@ test_expect_success 'subdirectory filter result looks okay' '
7878
! git show sub:subdir
7979
'
8080

81+
test_expect_success 'setup and filter history that requires --full-history' '
82+
git checkout master &&
83+
mkdir subdir &&
84+
echo A > subdir/new &&
85+
git add subdir/new &&
86+
test_tick &&
87+
git commit -m "subdir on master" subdir/new &&
88+
git rm a &&
89+
test_tick &&
90+
git commit -m "again subdir on master" &&
91+
git merge branch &&
92+
git-filter-branch --subdirectory-filter subdir sub-master
93+
'
94+
95+
test_expect_success 'subdirectory filter result looks okay' '
96+
test 3 = $(git-rev-list -1 --parents sub-master | wc -w) &&
97+
git show sub-master^:new &&
98+
git show sub-master^2:new &&
99+
! git show sub:subdir
100+
'
101+
81102
test_done

0 commit comments

Comments
 (0)