{"thread":{"id":"22386","subject":"[PATCH 2/2] filter-branch: Add tests for submodules","startedAt":"2010-01-25T13:06:23Z","lastAt":"2010-01-29T15:27:05Z","messageCount":15,"participants":["Michal Sojka","Johannes Sixt","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"132601","messageId":"1264424786-26231-1-git-send-email-sojkam1@fel.cvut.cz","threadId":"22386","inReplyTo":null,"subject":"filter-branch fix and tests","fromName":"Michal Sojka","fromEmail":"sojkam1@fel.cvut.cz","sentAt":"2010-01-25T13:06:23Z","receivedAt":"2010-01-25T13:06:23Z","isPatch":false,"sender":{"key":"sojkam1@fel.cvut.cz","avatar":"https://avatars.githubusercontent.com/u/140542?v=4"},"body":"Hi,\n\nthis is resend of the patch I sent two weeks ago. I've extended the commit\nmessage to address Johannes' question and in the second patch I've added tests\nfor the fix.\n\nMichal\n"},{"id":"132602","messageId":"1264424786-26231-2-git-send-email-sojkam1@fel.cvut.cz","threadId":"22386","inReplyTo":"1264424786-26231-1-git-send-email-sojkam1@fel.cvut.cz","subject":"[PATCH 1/2] filter-branch: Fix to allow replacing submodules with another content","fromName":"Michal Sojka","fromEmail":"sojkam1@fel.cvut.cz","sentAt":"2010-01-25T13:06:24Z","receivedAt":"2010-01-25T13:06:24Z","isPatch":true,"sender":{"key":"sojkam1@fel.cvut.cz","avatar":"https://avatars.githubusercontent.com/u/140542?v=4"},"body":"When git filter-branch is used to replace a submodule with another\ncontent, it always fails on the first commit. Consider a repository with\nsubmod directory containing a submodule. If I want to remove the\nsubmodule and replace it with a file, the following command fails.\n\ngit filter-branch --tree-filter 'rm -rf submod &&\n\t\t\t\t git rm -q submod &&\n\t\t\t\t mkdir submod &&\n\t\t\t\t touch submod/file'\n\nThe error message is:\nerror: submod: is a directory - add files inside instead\n\nThe reason is that git diff-index, which generates the first part of the\nlist of files updated by the tree filter, emits also the removed\nsubmodule even if it was replaced by a real directory.\n\nAdding --ignored-submodules solves the problem for me and\ntests in t7003-filter-branch.sh pass correctly.\n\nIf somebody wants to replace one revision of the module with another, it\ncan be done with --index-filter. Using --tree-filter for this has no\nsense since --tree-filter \"git submodule update --init\" fails with\n  Clone of '/tmp/submod' into submodule path 'submod' failed\nso that the revision must be replaced only in index.\n\nSigned-off-by: Michal Sojka <sojkam1@fel.cvut.cz>\n---\n git-filter-branch.sh |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/git-filter-branch.sh b/git-filter-branch.sh\nindex 195b5ef..d4ac7fb 100755\n--- a/git-filter-branch.sh\n+++ b/git-filter-branch.sh\n@@ -331,7 +331,7 @@ while read commit parents; do\n \t\t\tdie \"tree filter failed: $filter_tree\"\n \n \t\t(\n-\t\t\tgit diff-index -r --name-only $commit &&\n+\t\t\tgit diff-index -r --name-only --ignore-submodules $commit && \n \t\t\tgit ls-files --others\n \t\t) > \"$tempdir\"/tree-state || exit\n \t\tgit update-index --add --replace --remove --stdin \\\n-- \n1.6.6\n"},{"id":"132600","messageId":"1264424786-26231-3-git-send-email-sojkam1@fel.cvut.cz","threadId":"22386","inReplyTo":"1264424786-26231-1-git-send-email-sojkam1@fel.cvut.cz","subject":"[PATCH 2/2] filter-branch: Add tests for submodules","fromName":"Michal Sojka","fromEmail":"sojkam1@fel.cvut.cz","sentAt":"2010-01-25T13:06:25Z","receivedAt":"2010-01-25T13:06:25Z","isPatch":true,"sender":{"key":"sojkam1@fel.cvut.cz","avatar":"https://avatars.githubusercontent.com/u/140542?v=4"},"body":"The test 'rewrite submodule with another content' passes only with the\nprevious patch.\n\nSigned-off-by: Michal Sojka <sojkam1@fel.cvut.cz>\n---\n t/t7003-filter-branch.sh |   26 ++++++++++++++++++++++++++\n 1 files changed, 26 insertions(+), 0 deletions(-)\n\ndiff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh\nindex 9503875..39d4153 100755\n--- a/t/t7003-filter-branch.sh\n+++ b/t/t7003-filter-branch.sh\n@@ -306,4 +306,30 @@ test_expect_success '--remap-to-ancestor with filename filters' '\n \ttest $orig_invariant = $(git rev-parse invariant)\n '\n \n+test_expect_success 'setup submodule' '\n+\trm -rf * .*\n+\tgit init &&\n+\ttest_commit file &&\n+\tmkdir submod &&\n+\tsubmodurl=\"$PWD/submod\"\n+\t( cd submod &&\n+\t  git init &&\n+\t  test_commit file-in-submod ) &&\n+\tgit submodule add \"$submodurl\"\n+\tgit commit -m \"added submodule\" &&\n+\ttest_commit add-file &&\n+\t( cd submod && test_commit add-in-submodule ) &&\n+\tgit add submod &&\n+\tgit commit -m \"changed submodule\"\n+'\n+\n+test_expect_success 'rewrite submodule with another content' '\n+\tgit filter-branch --tree-filter \"test -d submod && {\n+\t\t\t\t\t rm -rf submod &&\n+\t\t\t\t\t git rm -rf --quiet submod &&\n+\t\t\t\t\t mkdir submod &&\n+\t\t\t\t\t : > submod/file\n+\t\t\t\t\t } || :\"\n+'\n+\n test_done\n-- \n1.6.6\n"},{"id":"132800","messageId":"201001271649.19287.sojkam1@fel.cvut.cz","threadId":"22386","inReplyTo":"alpine.DEB.1.00.1001261939420.4641@intel-tinevez-2-302","subject":"Re: [PATCH] filter-branch fix and tests","fromName":"Michal Sojka","fromEmail":"sojkam1@fel.cvut.cz","sentAt":"2010-01-27T15:49:18Z","receivedAt":"2010-01-27T15:49:18Z","isPatch":true,"sender":{"key":"sojkam1@fel.cvut.cz","avatar":"https://avatars.githubusercontent.com/u/140542?v=4"},"body":"Hi Johannes,\n\nOn Tuesday 26 of January 2010 19:40:47 Johannes Schindelin wrote:\n> On Mon, 25 Jan 2010, Michal Sojka wrote:\n> > this is resend of the patch I sent two weeks ago. I've extended the\n> > commit message to address Johannes' question and in the second patch\n> > I've added tests for the fix.\n> \n> From a quick look, it does not seem that I will be happy with your \"fix\";\n> you changed the commit message, but did not address the issue.\n> \n> Unfortunately, I do not have time to review anything that takes longer\n> than 30 minutes in total, and today not even that, so that will have to\n> wait.\n\nThanks for your reply. I do not want to steal your time, but I may not\nunderstand what is the issue. I extended my previous patch with tests\n(see bellow) so that all the use cases which might be IMHO affected by\nmy \"fix\" are covered. If you can think of another use case let me\nknow.\n\nThe fastest way to test this patch is:\nGIT_SKIP_TESTS='t7003.[12]? t7003.[2-9]' ./t7003-filter-branch.sh -d\n\n>From 849b105541ba4b5e3592de6769922b1264be0c77 Mon Sep 17 00:00:00 2001\nFrom: Michal Sojka <sojkam1@fel.cvut.cz>\nDate: Wed, 27 Jan 2010 15:57:17 +0100\nSubject: [PATCH] filter-branch: Add tests for submodules\n\nThere are three important tests:\n1) 'rewrite submodule with another content' passes only with the\n   previous patch applied.\n\n2) 'checkout submodule during rewrite' demonstrates that it is not\n   possible to replace a submodule revision in tree-filter by checking\n   the submodule out and reseting the submodule's HEAD. Fails both\n   with and without the previous patch. This is because filter-branch\n   sets GIT_WORKING_TREE to \".\" which causes clone (called from\n   git-submodule) to fail.\n\n3) 'replace submodule revision' shows that replacing submodule\n   revision is possible by direct index manipulation. Succeeds both\n   with and without the previous patch.\n\nSigned-off-by: Michal Sojka <sojkam1@fel.cvut.cz>\n---\n t/t7003-filter-branch.sh |   48 ++++++++++++++++++++++++++++++++++++++++++++++\n 1 files changed, 48 insertions(+), 0 deletions(-)\n\ndiff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh\nindex 9503875..a218d7a 100755\n--- a/t/t7003-filter-branch.sh\n+++ b/t/t7003-filter-branch.sh\n@@ -306,4 +306,52 @@ test_expect_success '--remap-to-ancestor with filename filters' '\n \ttest $orig_invariant = $(git rev-parse invariant)\n '\n \n+test_expect_success 'setup submodule' '\n+\trm -rf * .*\n+\tgit init &&\n+\ttest_commit file &&\n+\tmkdir submod &&\n+\tsubmodurl=\"$PWD/submod\"\n+\t( cd submod &&\n+\t  git init &&\n+\t  test_commit file-in-submod ) &&\n+\tgit submodule add \"$submodurl\"\n+\tgit commit -m \"added submodule\" &&\n+\ttest_commit add-file &&\n+\t( cd submod && test_commit add-in-submodule ) &&\n+\tgit add submod &&\n+\tgit commit -m \"changed submodule\"\n+\tgit branch original HEAD\n+'\n+\n+orig_head=`git show-ref --hash HEAD`\n+export orig_head\n+\n+test_expect_success 'rewrite submodule with another content' '\n+\tgit filter-branch --tree-filter \"test -d submod && {\n+\t\t\t\t\t rm -rf submod &&\n+\t\t\t\t\t git rm -rf --quiet submod &&\n+\t\t\t\t\t mkdir submod &&\n+\t\t\t\t\t : > submod/file\n+\t\t\t\t\t } || : &&\n+\t\t\t\t\t test $orig_head != `git show-ref --hash HEAD`\"\n+'\n+\n+test_expect_failure 'checkout submodule during rewrite' '\n+\tgit reset --hard original &&\n+\tgit filter-branch -f --tree-filter \\\n+\t    \"git submodule update --init &&\n+\t     cd submod &&\n+\t     git reset --hard origin/master\" HEAD\n+'\n+\n+test_expect_success 'replace submodule revision' '\n+\tgit reset --hard original &&\n+\tgit filter-branch -f --tree-filter \\\n+\t    \"git ls-files --error-unmatch -- submod > /dev/null 2>&1 &&\n+\t     git update-index --cacheinfo 160000 0123456789012345678901234567890123456789 submod ||\n+\t     : &&\n+\t     test $orig_head != `git show-ref --hash HEAD`\"\n+'\n+\n test_done\n-- \n1.6.6\n"},{"id":"132804","messageId":"4B606748.2050209@viscovery.net","threadId":"22386","inReplyTo":"201001271649.19287.sojkam1@fel.cvut.cz","subject":"Re: [PATCH] filter-branch fix and tests","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2010-01-27T16:18:16Z","receivedAt":"2010-01-27T16:18:16Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Michal Sojka schrieb:\n> +orig_head=`git show-ref --hash HEAD`\n> +export orig_head\n\nYou place the tree filter in double-quotes. Hence, orig_head will be\ninterpolated on the filter-branch command line. You don't need to export it.\n\n> +test_expect_success 'rewrite submodule with another content' '\n> +\tgit filter-branch --tree-filter \"test -d submod && {\n> +\t\t\t\t\t rm -rf submod &&\n> +\t\t\t\t\t git rm -rf --quiet submod &&\n> +\t\t\t\t\t mkdir submod &&\n> +\t\t\t\t\t : > submod/file\n> +\t\t\t\t\t } || : &&\n> +\t\t\t\t\t test $orig_head != `git show-ref --hash HEAD`\"\n\nWhat is the purpose of the check in the last line?\n\nAs long as you have another command after the \"} || : &&\", you can just\nwrite \"}\" instead.\n\n> +test_expect_failure 'checkout submodule during rewrite' '\n> +\tgit reset --hard original &&\n> +\tgit filter-branch -f --tree-filter \\\n> +\t    \"git submodule update --init &&\n> +\t     cd submod &&\n> +\t     git reset --hard origin/master\" HEAD\n\nYou must not change the directory without changing back. Use a sub-shell.\n\nI'm not sure whether it's worth catering for this use-case anyway.\nReplacing a submodule commit should really be done only in the\n--index-filter. The tree that --tree-filter checks out is intended only as\na temporary scratch area. It is not intended as a full worktree. In\nparticular, since 'submodule update --init' changes the configuration, it\nis extremly dangerous to call from a filter.\n\n-- Hannes\n"},{"id":"132846","messageId":"201001280041.23182.sojkam1@fel.cvut.cz","threadId":"22386","inReplyTo":"4B606748.2050209@viscovery.net","subject":"Re: [PATCH] filter-branch fix and tests","fromName":"Michal Sojka","fromEmail":"sojkam1@fel.cvut.cz","sentAt":"2010-01-27T23:41:23Z","receivedAt":"2010-01-27T23:41:23Z","isPatch":true,"sender":{"key":"sojkam1@fel.cvut.cz","avatar":"https://avatars.githubusercontent.com/u/140542?v=4"},"body":"On Wednesday 27 of January 2010 17:18:16 Johannes Sixt wrote:\n> Michal Sojka schrieb:\n> > +orig_head=`git show-ref --hash HEAD`\n> > +export orig_head\n> \n> You place the tree filter in double-quotes. Hence, orig_head will be\n> interpolated on the filter-branch command line. You don't need to export\n>  it.\n\nYou're right. Fixed.\n \n> > +test_expect_success 'rewrite submodule with another content' '\n> > +\tgit filter-branch --tree-filter \"test -d submod && {\n> > +\t\t\t\t\t rm -rf submod &&\n> > +\t\t\t\t\t git rm -rf --quiet submod &&\n> > +\t\t\t\t\t mkdir submod &&\n> > +\t\t\t\t\t : > submod/file\n> > +\t\t\t\t\t } || : &&\n> > +\t\t\t\t\t test $orig_head != `git show-ref --hash HEAD`\"\n> \n> What is the purpose of the check in the last line?\n\nIt should check that something was rewritten, but it was incorrectly put into \nthe filed. Fixed.\n \n> As long as you have another command after the \"} || : &&\", you can just\n> write \"}\" instead.\n\nOK.\n\n> > +test_expect_failure 'checkout submodule during rewrite' '\n> > +\tgit reset --hard original &&\n> > +\tgit filter-branch -f --tree-filter \\\n> > +\t    \"git submodule update --init &&\n> > +\t     cd submod &&\n> > +\t     git reset --hard origin/master\" HEAD\n> \n> You must not change the directory without changing back. Use a sub-shell.\n> \n> I'm not sure whether it's worth catering for this use-case anyway.\n> Replacing a submodule commit should really be done only in the\n> --index-filter. The tree that --tree-filter checks out is intended only as\n> a temporary scratch area. It is not intended as a full worktree. In\n> particular, since 'submodule update --init' changes the configuration, it\n> is extremly dangerous to call from a filter.\n\nI fully agree. I don't plan to put this test in the final version of the \npatch. I wrote this test because I didn't exactly know which issue has Dscho \nin mind. If it was this one, I wanted to show that this is not relevant.\n\nI'm sending corrected version of the patch with tests.\n\nThanks\nMichal\n"},{"id":"132848","messageId":"1264636547-24496-1-git-send-email-sojkam1@fel.cvut.cz","threadId":"22386","inReplyTo":"201001280041.23182.sojkam1@fel.cvut.cz","subject":"[PATCHv3] filter-branch: Add tests for submodules","fromName":"Michal Sojka","fromEmail":"sojkam1@fel.cvut.cz","sentAt":"2010-01-27T23:55:47Z","receivedAt":"2010-01-27T23:55:47Z","isPatch":false,"sender":{"key":"sojkam1@fel.cvut.cz","avatar":"https://avatars.githubusercontent.com/u/140542?v=4"},"body":"There are three important tests:\n1) 'rewrite submodule with another content' passes only with the\n   previous patch applied.\n\n2) 'checkout submodule during rewrite' demonstrates that it is not\n   possible to replace a submodule revision in tree-filter by checking\n   the submodule out and reseting the submodule's HEAD. Fails both\n   with and without the previous patch. This is because filter-branch\n   sets GIT_WORKING_TREE to \".\" which causes clone (called from\n   git-submodule) to fail.\n\n3) 'replace submodule revision' shows that replacing submodule\n   revision is possible by direct index manipulation. Succeeds both\n   with and without the previous patch.\n\nSigned-off-by: Michal Sojka <sojkam1@fel.cvut.cz>\n---\n t/t7003-filter-branch.sh |   47 ++++++++++++++++++++++++++++++++++++++++++++++\n 1 files changed, 47 insertions(+), 0 deletions(-)\n\ndiff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh\nindex 9503875..fabe038 100755\n--- a/t/t7003-filter-branch.sh\n+++ b/t/t7003-filter-branch.sh\n@@ -306,4 +306,51 @@ test_expect_success '--remap-to-ancestor with filename filters' '\n \ttest $orig_invariant = $(git rev-parse invariant)\n '\n \n+test_expect_success 'setup submodule' '\n+\trm -rf * .*\n+\tgit init &&\n+\ttest_commit file &&\n+\tmkdir submod &&\n+\tsubmodurl=\"$PWD/submod\"\n+\t( cd submod &&\n+\t  git init &&\n+\t  test_commit file-in-submod ) &&\n+\tgit submodule add \"$submodurl\"\n+\tgit commit -m \"added submodule\" &&\n+\ttest_commit add-file &&\n+\t( cd submod && test_commit add-in-submodule ) &&\n+\tgit add submod &&\n+\tgit commit -m \"changed submodule\" &&\n+\tgit branch original HEAD\n+'\n+\n+orig_head=`git show-ref --hash --head HEAD`\n+\n+test_expect_success 'rewrite submodule with another content' '\n+\tgit filter-branch --tree-filter \"test -d submod && {\n+\t\t\t\t\t rm -rf submod &&\n+\t\t\t\t\t git rm -rf --quiet submod &&\n+\t\t\t\t\t mkdir submod &&\n+\t\t\t\t\t : > submod/file\n+\t\t\t\t\t } || :\" HEAD &&\n+\ttest $orig_head != `git show-ref --hash --head HEAD`\n+'\n+\n+test_expect_failure 'checkout submodule during rewrite' '\n+\tgit reset --hard original &&\n+\tgit filter-branch -f --tree-filter \\\n+\t    \"git submodule update --init &&\n+\t     ( test -d submod && cd submod &&\n+\t       git reset --hard origin/master )\" HEAD\n+'\n+\n+test_expect_success 'replace submodule revision' '\n+\tgit reset --hard original &&\n+\tgit filter-branch -f --tree-filter \\\n+\t    \"if git ls-files --error-unmatch -- submod > /dev/null 2>&1\n+\t     then git update-index --cacheinfo 160000 0123456789012345678901234567890123456789 submod\n+\t     fi\" HEAD &&\n+\ttest $orig_head != `git show-ref --hash --head HEAD`\n+'\n+\n test_done\n-- \n1.6.6\n"},{"id":"132850","messageId":"7vfx5rnl0w.fsf@alter.siamese.dyndns.org","threadId":"22386","inReplyTo":"1264636547-24496-1-git-send-email-sojkam1@fel.cvut.cz","subject":"Re: [PATCHv3] filter-branch: Add tests for submodules","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-01-28T00:14:07Z","receivedAt":"2010-01-28T00:14:07Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Michal Sojka <sojkam1@fel.cvut.cz> writes:\n\n> There are three important tests:\n\nIt is unnecessary and counterproductive to self-proclaim the importance of\na patch or new tests.  If anything, what are important are not tests\nthemselves but the conditions that they check, so \"Add tests to check\nthree important cases:\" is slightly more palatable.\n\nI'd suggest to just start with \"Add three tests to make sure:\".\n\n> 1) 'rewrite submodule with another content' passes only with the\n>    previous patch applied.\n\nSorry, but I think I am missing some context here to understand this\nsentence.  Which previous patch?\n\n> 2) 'checkout submodule during rewrite' demonstrates that it is not\n>    possible to replace a submodule revision in tree-filter by checking\n>    the submodule out and reseting the submodule's HEAD. Fails both\n>    with and without the previous patch. This is because filter-branch\n>    sets GIT_WORKING_TREE to \".\" which causes clone (called from\n>    git-submodule) to fail.\n\nI thought you agreed with Hannes that this is not something we would even\nwant to support?\n\n> 3) 'replace submodule revision' shows that replacing submodule\n>    revision is possible by direct index manipulation. Succeeds both\n>    with and without the previous patch.\n>\n> Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>\n> ---\n\nThanks.\n"},{"id":"132870","messageId":"201001281002.03232.sojkam1@fel.cvut.cz","threadId":"22386","inReplyTo":"7vfx5rnl0w.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCHv3] filter-branch: Add tests for submodules","fromName":"Michal Sojka","fromEmail":"sojkam1@fel.cvut.cz","sentAt":"2010-01-28T09:02:02Z","receivedAt":"2010-01-28T09:02:02Z","isPatch":false,"sender":{"key":"sojkam1@fel.cvut.cz","avatar":"https://avatars.githubusercontent.com/u/140542?v=4"},"body":"On Thursday 28 of January 2010 01:14:07 Junio C Hamano wrote:\n> Michal Sojka <sojkam1@fel.cvut.cz> writes:\n> > There are three important tests:\n> \n> It is unnecessary and counterproductive to self-proclaim the importance of\n> a patch or new tests.  If anything, what are important are not tests\n> themselves but the conditions that they check, so \"Add tests to check\n> three important cases:\" is slightly more palatable.\n> \n> I'd suggest to just start with \"Add three tests to make sure:\".\n\nOK\n\n> > 1) 'rewrite submodule with another content' passes only with the\n> >    previous patch applied.\n> \n> Sorry, but I think I am missing some context here to understand this\n> sentence.  Which previous patch?\n\nI should have sent both patches. Sorry for that. I'll send them now.\n \n> > 2) 'checkout submodule during rewrite' demonstrates that it is not\n> >    possible to replace a submodule revision in tree-filter by checking\n> >    the submodule out and reseting the submodule's HEAD. Fails both\n> >    with and without the previous patch. This is because filter-branch\n> >    sets GIT_WORKING_TREE to \".\" which causes clone (called from\n> >    git-submodule) to fail.\n> \n> I thought you agreed with Hannes that this is not something we would even\n> want to support?\n\nYes. I'm removing this test.\n\nCheers,\nMichal\n"},{"id":"132871","messageId":"1264669727-9977-1-git-send-email-sojkam1@fel.cvut.cz","threadId":"22386","inReplyTo":"201001281002.03232.sojkam1@fel.cvut.cz","subject":"[PATCHv4 1/2] filter-branch: Fix to allow replacing submodules with another content","fromName":"Michal Sojka","fromEmail":"sojkam1@fel.cvut.cz","sentAt":"2010-01-28T09:08:46Z","receivedAt":"2010-01-28T09:08:46Z","isPatch":false,"sender":{"key":"sojkam1@fel.cvut.cz","avatar":"https://avatars.githubusercontent.com/u/140542?v=4"},"body":"When git filter-branch is used to replace a submodule with another\ncontent, it always fails on the first commit. Consider a repository with\nsubmod directory containing a submodule. If I want to remove the\nsubmodule and replace it with a file, the following command fails.\n\ngit filter-branch --tree-filter 'rm -rf submod &&\n\t\t\t\t git rm -q submod &&\n\t\t\t\t mkdir submod &&\n\t\t\t\t touch submod/file'\n\nThe error message is:\nerror: submod: is a directory - add files inside instead\n\nThe reason is that git diff-index, which generates the first part of the\nlist of files updated by the tree filter, emits also the removed\nsubmodule even if it was replaced by a real directory.\n\nAdding --ignored-submodules solves the problem for me and\ntests in t7003-filter-branch.sh pass correctly.\n\nSigned-off-by: Michal Sojka <sojkam1@fel.cvut.cz>\n---\n git-filter-branch.sh |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/git-filter-branch.sh b/git-filter-branch.sh\nindex 195b5ef..7c4ad7d 100755\n--- a/git-filter-branch.sh\n+++ b/git-filter-branch.sh\n@@ -331,7 +331,7 @@ while read commit parents; do\n \t\t\tdie \"tree filter failed: $filter_tree\"\n \n \t\t(\n-\t\t\tgit diff-index -r --name-only $commit &&\n+\t\t\tgit diff-index -r --name-only --ignore-submodules $commit &&\n \t\t\tgit ls-files --others\n \t\t) > \"$tempdir\"/tree-state || exit\n \t\tgit update-index --add --replace --remove --stdin \\\n-- \n1.6.6\n"},{"id":"132872","messageId":"1264669727-9977-2-git-send-email-sojkam1@fel.cvut.cz","threadId":"22386","inReplyTo":"201001281002.03232.sojkam1@fel.cvut.cz","subject":"[PATCHv4 2/2] filter-branch: Add tests for submodules in tree-filter","fromName":"Michal Sojka","fromEmail":"sojkam1@fel.cvut.cz","sentAt":"2010-01-28T09:08:47Z","receivedAt":"2010-01-28T09:08:47Z","isPatch":false,"sender":{"key":"sojkam1@fel.cvut.cz","avatar":"https://avatars.githubusercontent.com/u/140542?v=4"},"body":"Add tests to make sure:\n1) a submodule can be removed and its content replaced with regular\n   files ('rewrite submodule with another content'). This test passes\n   only with the previous patch applied.\n\n2) it is possible to replace submodule revision by direct index\n   manipulation ('replace submodule revision'). Although it would be\n   better to run such a filter in --index-filter, this test shows that\n   this functionality is not broken by the previous patch. This\n   succeeds both with and without the previous patch.\n\nSigned-off-by: Michal Sojka <sojkam1@fel.cvut.cz>\n---\n t/t7003-filter-branch.sh |   39 +++++++++++++++++++++++++++++++++++++++\n 1 files changed, 39 insertions(+), 0 deletions(-)\n\ndiff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh\nindex 9503875..4ee8237 100755\n--- a/t/t7003-filter-branch.sh\n+++ b/t/t7003-filter-branch.sh\n@@ -306,4 +306,43 @@ test_expect_success '--remap-to-ancestor with filename filters' '\n \ttest $orig_invariant = $(git rev-parse invariant)\n '\n \n+test_expect_success 'setup submodule' '\n+\trm -rf * .*\n+\tgit init &&\n+\ttest_commit file &&\n+\tmkdir submod &&\n+\tsubmodurl=\"$PWD/submod\"\n+\t( cd submod &&\n+\t  git init &&\n+\t  test_commit file-in-submod ) &&\n+\tgit submodule add \"$submodurl\"\n+\tgit commit -m \"added submodule\" &&\n+\ttest_commit add-file &&\n+\t( cd submod && test_commit add-in-submodule ) &&\n+\tgit add submod &&\n+\tgit commit -m \"changed submodule\" &&\n+\tgit branch original HEAD\n+'\n+\n+orig_head=`git show-ref --hash --head HEAD`\n+\n+test_expect_success 'rewrite submodule with another content' '\n+\tgit filter-branch --tree-filter \"test -d submod && {\n+\t\t\t\t\t rm -rf submod &&\n+\t\t\t\t\t git rm -rf --quiet submod &&\n+\t\t\t\t\t mkdir submod &&\n+\t\t\t\t\t : > submod/file\n+\t\t\t\t\t } || :\" HEAD &&\n+\ttest $orig_head != `git show-ref --hash --head HEAD`\n+'\n+\n+test_expect_success 'replace submodule revision' '\n+\tgit reset --hard original &&\n+\tgit filter-branch -f --tree-filter \\\n+\t    \"if git ls-files --error-unmatch -- submod > /dev/null 2>&1\n+\t     then git update-index --cacheinfo 160000 0123456789012345678901234567890123456789 submod\n+\t     fi\" HEAD &&\n+\ttest $orig_head != `git show-ref --hash --head HEAD`\n+'\n+\n test_done\n-- \n1.6.6\n"},{"id":"132915","messageId":"7vaavxlwoz.fsf@alter.siamese.dyndns.org","threadId":"22386","inReplyTo":"1264669727-9977-2-git-send-email-sojkam1@fel.cvut.cz","subject":"Re: [PATCHv4 2/2] filter-branch: Add tests for submodules in tree-filter","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-01-28T21:57:16Z","receivedAt":"2010-01-28T21:57:16Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Michal Sojka <sojkam1@fel.cvut.cz> writes:\n\n> @@ -306,4 +306,43 @@ test_expect_success '--remap-to-ancestor with filename filters' '\n>  \ttest $orig_invariant = $(git rev-parse invariant)\n>  '\n>  \n> +test_expect_success 'setup submodule' '\n> +\trm -rf * .*\n\nYikes.  Please don't do this.\n\nIf you cannot structure your tests following what has already been done by\nthe previous tests, at least name the things that you want to remove a bit\nmore explicitly to avoid mistakes.  The loosest form that is reasonable\nwould probably be (to catch a, actual, backup-refs, ... and .git):\n\n\trm -fr ?* .?* &&\n\nbut it would be preferable to be even more explicit \"rm -fr ?* .git\".\n\nAlso make sure you don't break the chain of \"&&\" unnecessarily.\n\n> +\tgit init &&\n> +\ttest_commit file &&\n> +\tmkdir submod &&\n> +\tsubmodurl=\"$PWD/submod\"\n> +\t( cd submod &&\n> +\t  git init &&\n> +\t  test_commit file-in-submod ) &&\n> +\tgit submodule add \"$submodurl\"\n\n\"&&\"?\n"},{"id":"132963","messageId":"201001291620.35269.sojkam1@fel.cvut.cz","threadId":"22386","inReplyTo":"7vaavxlwoz.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCHv4 2/2] filter-branch: Add tests for submodules in tree-filter","fromName":"Michal Sojka","fromEmail":"sojkam1@fel.cvut.cz","sentAt":"2010-01-29T15:20:35Z","receivedAt":"2010-01-29T15:20:35Z","isPatch":false,"sender":{"key":"sojkam1@fel.cvut.cz","avatar":"https://avatars.githubusercontent.com/u/140542?v=4"},"body":"On Thursday 28 of January 2010 22:57:16 Junio C Hamano wrote:\n> Michal Sojka <sojkam1@fel.cvut.cz> writes:\n> > +test_expect_success 'setup submodule' '\n> > +\trm -rf * .*\n> \n> Yikes.  Please don't do this.\n> \n> [...]\n> \n> but it would be preferable to be even more explicit \"rm -fr ?* .git\".\n\nFixed. I did it like you suggested.\n\n> Also make sure you don't break the chain of \"&&\" unnecessarily.\n> \n\nFixed.\n\nI've also split each my test into two separate tests. In the first one I \nperform the rewrite and in the second I test that the result is what was \nexpected. I did it because the other tests in this file are structured the \nsame way.\n\nCheers,\nMichal\n"},{"id":"132964","messageId":"1264778825-26401-1-git-send-email-sojkam1@fel.cvut.cz","threadId":"22386","inReplyTo":"201001291620.35269.sojkam1@fel.cvut.cz","subject":"[PATCHv5 1/2] filter-branch: Fix to allow replacing submodules with another content","fromName":"Michal Sojka","fromEmail":"sojkam1@fel.cvut.cz","sentAt":"2010-01-29T15:27:04Z","receivedAt":"2010-01-29T15:27:04Z","isPatch":false,"sender":{"key":"sojkam1@fel.cvut.cz","avatar":"https://avatars.githubusercontent.com/u/140542?v=4"},"body":"When git filter-branch is used to replace a submodule with another\ncontent, it always fails on the first commit. Consider a repository with\nsubmod directory containing a submodule. If I want to remove the\nsubmodule and replace it with a file, the following command fails.\n\ngit filter-branch --tree-filter 'rm -rf submod &&\n\t\t\t\t git rm -q submod &&\n\t\t\t\t mkdir submod &&\n\t\t\t\t touch submod/file'\n\nThe error message is:\nerror: submod: is a directory - add files inside instead\n\nThe reason is that git diff-index, which generates the first part of the\nlist of files updated by the tree filter, emits also the removed\nsubmodule even if it was replaced by a real directory.\n\nAdding --ignored-submodules solves the problem for me and\ntests in t7003-filter-branch.sh pass correctly.\n\nSigned-off-by: Michal Sojka <sojkam1@fel.cvut.cz>\n---\n git-filter-branch.sh |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/git-filter-branch.sh b/git-filter-branch.sh\nindex 195b5ef..7c4ad7d 100755\n--- a/git-filter-branch.sh\n+++ b/git-filter-branch.sh\n@@ -331,7 +331,7 @@ while read commit parents; do\n \t\t\tdie \"tree filter failed: $filter_tree\"\n \n \t\t(\n-\t\t\tgit diff-index -r --name-only $commit &&\n+\t\t\tgit diff-index -r --name-only --ignore-submodules $commit &&\n \t\t\tgit ls-files --others\n \t\t) > \"$tempdir\"/tree-state || exit\n \t\tgit update-index --add --replace --remove --stdin \\\n-- \n1.6.6\n"},{"id":"132965","messageId":"1264778825-26401-2-git-send-email-sojkam1@fel.cvut.cz","threadId":"22386","inReplyTo":"201001291620.35269.sojkam1@fel.cvut.cz","subject":"[PATCHv5 2/2] filter-branch: Add tests for submodules in tree-filter","fromName":"Michal Sojka","fromEmail":"sojkam1@fel.cvut.cz","sentAt":"2010-01-29T15:27:05Z","receivedAt":"2010-01-29T15:27:05Z","isPatch":false,"sender":{"key":"sojkam1@fel.cvut.cz","avatar":"https://avatars.githubusercontent.com/u/140542?v=4"},"body":"Add tests to make sure:\n1) a submodule can be removed and its content replaced with regular\n   files ('rewrite submodule with another content'). This test passes\n   only with the previous patch applied.\n\n2) it is possible to replace submodule revision by direct index\n   manipulation ('replace submodule revision'). Although it would be\n   better to run such a filter in --index-filter, this test shows that\n   this functionality is not broken by the previous patch. This\n   succeeds both with and without the previous patch.\n\nSigned-off-by: Michal Sojka <sojkam1@fel.cvut.cz>\n---\n t/t7003-filter-branch.sh |   45 +++++++++++++++++++++++++++++++++++++++++++++\n 1 files changed, 45 insertions(+), 0 deletions(-)\n\ndiff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh\nindex 9503875..a7f0791 100755\n--- a/t/t7003-filter-branch.sh\n+++ b/t/t7003-filter-branch.sh\n@@ -306,4 +306,49 @@ test_expect_success '--remap-to-ancestor with filename filters' '\n \ttest $orig_invariant = $(git rev-parse invariant)\n '\n \n+test_expect_success 'setup submodule' '\n+\trm -rf ?* .git &&\n+\tgit init &&\n+\ttest_commit file &&\n+\tmkdir submod &&\n+\tsubmodurl=\"$PWD/submod\" &&\n+\t( cd submod &&\n+\t  git init &&\n+\t  test_commit file-in-submod ) &&\n+\tgit submodule add \"$submodurl\" &&\n+\tgit commit -m \"added submodule\" &&\n+\ttest_commit add-file &&\n+\t( cd submod && test_commit add-in-submodule ) &&\n+\tgit add submod &&\n+\tgit commit -m \"changed submodule\" &&\n+\tgit branch original HEAD\n+'\n+\n+orig_head=`git rev-parse HEAD`\n+\n+test_expect_success 'rewrite submodule with another content' '\n+\tgit filter-branch --tree-filter \"test -d submod && {\n+\t\t\t\t\t rm -rf submod &&\n+\t\t\t\t\t git rm -rf --quiet submod &&\n+\t\t\t\t\t mkdir submod &&\n+\t\t\t\t\t : > submod/file\n+\t\t\t\t\t } || :\" HEAD\n+'\n+test_expect_success 'test that submodule was rewritten' '\n+\ttest -f submod/file &&\n+\ttest $orig_head != `git rev-parse HEAD`\n+'\n+\n+test_expect_success 'replace submodule revision' '\n+\tgit reset --hard original &&\n+\tgit filter-branch -f --tree-filter \\\n+\t    \"if git ls-files --error-unmatch -- submod > /dev/null 2>&1\n+\t     then git update-index --cacheinfo 160000 0123456789012345678901234567890123456789 submod\n+\t     fi\" HEAD\n+'\n+test_expect_success 'test that revision was replaced' '\n+\ttest \"`git ls-files --stage submod`\" = \"160000 0123456789012345678901234567890123456789 0\tsubmod\" &&\n+\ttest $orig_head != `git rev-parse HEAD`\n+'\n+\n test_done\n-- \n1.6.6\n"}]}