Skip to content

Commit 1f7d57f

Browse files
wentasahgitster
authored andcommitted
filter-branch: Add tests for submodules in tree-filter
Add tests to make sure that: 1) a submodule can be removed and its content replaced with regular files ('rewrite submodule with another content'). This test passes only with the previous patch applied. 2) it is possible to replace submodule revision by direct index manipulation ('replace submodule revision'). Although it would be better to run such a filter in --index-filter, this test shows that this functionality is not broken by the previous patch. This succeeds both with and without the previous patch. Signed-off-by: Michal Sojka <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 03ca839 commit 1f7d57f

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

t/t7003-filter-branch.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,4 +306,43 @@ test_expect_success '--remap-to-ancestor with filename filters' '
306306
test $orig_invariant = $(git rev-parse invariant)
307307
'
308308

309+
test_expect_success 'setup submodule' '
310+
rm -fr ?* .git &&
311+
git init &&
312+
test_commit file &&
313+
mkdir submod &&
314+
submodurl="$PWD/submod" &&
315+
( cd submod &&
316+
git init &&
317+
test_commit file-in-submod ) &&
318+
git submodule add "$submodurl" &&
319+
git commit -m "added submodule" &&
320+
test_commit add-file &&
321+
( cd submod && test_commit add-in-submodule ) &&
322+
git add submod &&
323+
git commit -m "changed submodule" &&
324+
git branch original HEAD
325+
'
326+
327+
orig_head=`git show-ref --hash --head HEAD`
328+
329+
test_expect_success 'rewrite submodule with another content' '
330+
git filter-branch --tree-filter "test -d submod && {
331+
rm -rf submod &&
332+
git rm -rf --quiet submod &&
333+
mkdir submod &&
334+
: > submod/file
335+
} || :" HEAD &&
336+
test $orig_head != `git show-ref --hash --head HEAD`
337+
'
338+
339+
test_expect_success 'replace submodule revision' '
340+
git reset --hard original &&
341+
git filter-branch -f --tree-filter \
342+
"if git ls-files --error-unmatch -- submod > /dev/null 2>&1
343+
then git update-index --cacheinfo 160000 0123456789012345678901234567890123456789 submod
344+
fi" HEAD &&
345+
test $orig_head != `git show-ref --hash --head HEAD`
346+
'
347+
309348
test_done

0 commit comments

Comments
 (0)