{"thread":{"id":"22169","subject":"[PATCH/RFC] filter-branch: Fix to allow replacing submodules with another content","startedAt":"2010-01-11T16:33:54Z","lastAt":"2010-01-13T14:56:39Z","messageCount":3,"participants":["Michal Sojka","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"131294","messageId":"1263227634-11259-1-git-send-email-sojkam1@fel.cvut.cz","threadId":"22169","inReplyTo":null,"subject":"[PATCH/RFC] filter-branch: Fix to allow replacing submodules with another content","fromName":"Michal Sojka","fromEmail":"sojkam1@fel.cvut.cz","sentAt":"2010-01-11T16:33:54Z","receivedAt":"2010-01-11T16:33:54Z","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\ndirectory submodule 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 submodule &&\n\t\t\t\t git rm -q submodule &&\n\t\t\t\t mkdir submodule &&\n\t\t\t\t touch submodule/file'\n\nThe error message is:\nerror: submodule: is a directory - add files inside instead\n\nThe reason is that git diff-index, which generates a part of the list of\nfiles to update-index, emits also the removed submodule even if it was\nreplaced by a real directory.\n\nAdding --ignored-submodules solves the problem for me and\ntests in t7003-filter-branch.sh passes 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..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":"131298","messageId":"alpine.DEB.1.00.1001111901380.4985@pacific.mpi-cbg.de","threadId":"22169","inReplyTo":"1263227634-11259-1-git-send-email-sojkam1@fel.cvut.cz","subject":"Re: [PATCH/RFC] filter-branch: Fix to allow replacing submodules with another content","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2010-01-11T18:02:06Z","receivedAt":"2010-01-11T18:02:06Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 11 Jan 2010, Michal Sojka wrote:\n\n> When git filter-branch is used to replace a submodule with another\n> content, it always fails on the first commit. Consider a repository with\n> directory submodule containing a submodule. If I want to remove the\n> submodule and replace it with a file, the following command fails.\n> \n> git filter-branch --tree-filter 'rm -rf submodule &&\n> \t\t\t\t git rm -q submodule &&\n> \t\t\t\t mkdir submodule &&\n> \t\t\t\t touch submodule/file'\n> \n> The error message is:\n> error: submodule: is a directory - add files inside instead\n> \n> The reason is that git diff-index, which generates a part of the list of\n> files to update-index, emits also the removed submodule even if it was\n> replaced by a real directory.\n> \n> Adding --ignored-submodules solves the problem for me and\n> tests in t7003-filter-branch.sh passes correctly.\n\nHave you tested replacing one revision of a submodule with another?\n\nCiao,\nDscho\n"},{"id":"131478","messageId":"201001131556.40167.sojkam1@fel.cvut.cz","threadId":"22169","inReplyTo":"alpine.DEB.1.00.1001111901380.4985@pacific.mpi-cbg.de","subject":"Re: [PATCH/RFC] filter-branch: Fix to allow replacing submodules with another content","fromName":"Michal Sojka","fromEmail":"sojkam1@fel.cvut.cz","sentAt":"2010-01-13T14:56:39Z","receivedAt":"2010-01-13T14:56:39Z","isPatch":true,"sender":{"key":"sojkam1@fel.cvut.cz","avatar":"https://avatars.githubusercontent.com/u/140542?v=4"},"body":"On Monday 11 of January 2010 19:02:06 Johannes Schindelin wrote:\n> Hi,\n> \n> On Mon, 11 Jan 2010, Michal Sojka wrote:\n> > When git filter-branch is used to replace a submodule with another\n> > content, it always fails on the first commit. Consider a repository with\n> > directory submodule containing a submodule. If I want to remove the\n> > submodule and replace it with a file, the following command fails.\n> >\n> > git filter-branch --tree-filter 'rm -rf submodule &&\n> > \t\t\t\t git rm -q submodule &&\n> > \t\t\t\t mkdir submodule &&\n> > \t\t\t\t touch submodule/file'\n> >\n> > The error message is:\n> > error: submodule: is a directory - add files inside instead\n> >\n> > The reason is that git diff-index, which generates a part of the list of\n> > files to update-index, emits also the removed submodule even if it was\n> > replaced by a real directory.\n> >\n> > Adding --ignored-submodules solves the problem for me and\n> > tests in t7003-filter-branch.sh passes correctly.\n> \n> Have you tested replacing one revision of a submodule with another?\n\nHi,\n\nno, I didn't try it. I wanted to test it now but it seems to me that\nit cannot work even without my patch. I may be trying wrong\n--tree-filter. If anybody has a better idea, let me know.\n\nI suppose that in order to change the revision of the submodule within\nthe tree filter, I need to checkout the original revision first. Then\nI could use e.g. git reset HEAD^ to change it. Unfortunately even\ncheckout of the submodule fails:\n\n$ git filter-branch --tree-filter \"git submodule update --init\" HEAD\nClone of '/tmp/submod' into submodule path 'submod' failed\ntree filter failed: git submodule update --init\n\nThis is because filter-branch sets GIT_WORKING_TREE to \".\" which\ncauses clone to fail.\n\nReplacing a revision of a submodule can be done only by manipulating\nindex, but for this case you would use index-filter rather than\ntree-filter. Right?\n\nI have created a few tests for testing filter-branch with submodules.\nSee the patch bellow.\n\nMichal\n\n>From 9aa38185d795061a2f00204d181244f906280b5a Mon Sep 17 00:00:00 2001\nFrom: Michal Sojka <sojkam1@fel.cvut.cz>\nDate: Wed, 13 Jan 2010 15:15:28 +0100\nSubject: [PATCH] filter-branch: Add tests for submodules\n\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..daebd17 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_failure '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"}]}