{"thread":{"id":"26959","subject":"Problem using git-filter-branch to move tree when repository name contains space","startedAt":"2011-04-01T14:30:26Z","lastAt":"2011-04-01T21:49:04Z","messageCount":4,"participants":["Jean-François Burdet","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"164891","messageId":"4D95E182.6030903@revelate.com","threadId":"26959","inReplyTo":null,"subject":"Problem using git-filter-branch to move tree when repository name contains space","fromName":"Jean-François Burdet","fromEmail":"jfburdet@revelate.com","sentAt":"2011-04-01T14:30:26Z","receivedAt":"2011-04-01T14:30:26Z","isPatch":false,"sender":{"key":"jfburdet@revelate.com","avatar":null},"body":"Hi,\n\nI want to move my repository (wich is contained in a directory whose\nname's containing a space)  root tree to a subdirectory.\n\nI followed what's documented in\nhttp://www.kernel.org/pub/software/scm/git/docs/git-filter-branch.html ,\nusing the last example :\n\ngit filter-branch --index-filter \\\n        'git ls-files -s | sed \"s-\\t\\\"*-&newsubdir/-\" |\n                GIT_INDEX_FILE=$GIT_INDEX_FILE.new \\\n                        git update-index --index-info &&\n         mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD\n\n\nBut, look at the following two scenario:\n\nScenario 1 : Repository have no space in it, everything works fine :\njfburdet@nagios:~$ mkdir gittest\njfburdet@nagios:~$ cd gittest/\njfburdet@nagios:~/gittest$ git init\nInitialized empty Git repository in /home/jfburdet/gittest/.git/\njfburdet@nagios:~/gittest$ touch a_file\njfburdet@nagios:~/gittest$ git add .\njfburdet@nagios:~/gittest$ git commit -m \"A commit\"\n[master (root-commit) e6261d5] A commit\n Committer: jfburdet <jfburdet@(none)>\n 0 files changed, 0 insertions(+), 0 deletions(-)\n create mode 100644 a_file\n jfburdet@nagios:~/gittest$ git filter-branch --index-filter \\\n>         'git ls-files -s | sed \"s-\\t\\\"*-&newsubdir/-\" |\n>                 GIT_INDEX_FILE=$GIT_INDEX_FILE.new \\\n>                         git update-index --index-info &&\n>          mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD\nRewrite e6261d591357f39e1b4f95c0dfeb7a133e211161 (1/1)\nRef 'refs/heads/master' was rewritten\n\nScenario 2 : Repository have space in its directory name, making the\ncommand fails\njfburdet@nagios:~$ mkdir \"git test\"\njfburdet@nagios:~$ cd \"git test\"\njfburdet@nagios:~/git test$\njfburdet@nagios:~/git test$ git init\nInitialized empty Git repository in /home/jfburdet/git test/.git/\njfburdet@nagios:~/git test$ touch a_file\njfburdet@nagios:~/git test$ git add .\njfburdet@nagios:~/git test$ git commit -m \"A commit\"\n[master (root-commit) 3658e30] A commit\n Committer: jfburdet <jfburdet@(none)>\n 0 files changed, 0 insertions(+), 0 deletions(-)\n create mode 100644 a_file\njfburdet@nagios:~/git test$ git filter-branch --index-filter \\\n>         'git ls-files -s | sed \"s-\\t\\\"*-&newsubdir/-\" |\n>                 GIT_INDEX_FILE=$GIT_INDEX_FILE.new \\\n>                         git update-index --index-info &&\n>          mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD\nRewrite 3658e305df3ace21d39bf57dd4e0e5627818dfcc (1/1)mv: target\n`test/.git-rewrite/t/../index' is not a directory\nindex filter failed: git ls-files -s | sed \"s-  \\\"*-&newsubdir/-\" |\n                GIT_INDEX_FILE=$GIT_INDEX_FILE.new \\\n                        git update-index --index-info &&\n         mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE\njfburdet@nagios:~/git test$\n\n\nI tried to tweak the sed expression with no success. Can someone help me\nwith that ?\n\nPlease note that I can't simply rename the directory before firing up\n\"git filter-branch\" because I'm in a process of merging repositories and\ntheir name are mandatory.\n\nCheers,\n\nJean-François,\n"},{"id":"164892","messageId":"20110401144107.GA3103@sigill.intra.peff.net","threadId":"26959","inReplyTo":"4D95E182.6030903@revelate.com","subject":"Re: Problem using git-filter-branch to move tree when repository name contains space","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-04-01T14:41:07Z","receivedAt":"2011-04-01T14:41:07Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Apr 01, 2011 at 04:30:26PM +0200, Jean-François Burdet wrote:\n\n> I want to move my repository (wich is contained in a directory whose\n> name's containing a space)  root tree to a subdirectory.\n> \n> I followed what's documented in\n> http://www.kernel.org/pub/software/scm/git/docs/git-filter-branch.html ,\n> using the last example :\n> \n> [...]\n>\n> jfburdet@nagios:~/git test$ git filter-branch --index-filter \\\n> >         'git ls-files -s | sed \"s-\\t\\\"*-&newsubdir/-\" |\n> >                 GIT_INDEX_FILE=$GIT_INDEX_FILE.new \\\n> >                         git update-index --index-info &&\n> >          mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD\n> Rewrite 3658e305df3ace21d39bf57dd4e0e5627818dfcc (1/1)mv: target\n> `test/.git-rewrite/t/../index' is not a directory\n\nThe problem is that GIT_INDEX_FILE is an absolute path that contains the\nrepo name. So it needs to be quoted in the mv command. This should work:\n\n  git filter-branch --index-filter \\\n    'git ls-files -s | sed \"s-\\t\\\"*-&newsubdir/-\" |\n      GIT_INDEX_FILE=$GIT_INDEX_FILE.new \\\n        git update-index --index-info &&\n     mv \"$GIT_INDEX_FILE.new\" \"$GIT_INDEX_FILE\"' HEAD\n\n-Peff\n"},{"id":"164893","messageId":"20110401144627.GA3686@sigill.intra.peff.net","threadId":"26959","inReplyTo":"20110401144107.GA3103@sigill.intra.peff.net","subject":"[PATCH] docs: fix filter-branch subdir example for exotic repo names","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-04-01T14:46:27Z","receivedAt":"2011-04-01T14:46:27Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"The GIT_INDEX_FILE variable we get from git has the full\npath to the repo, which may contain spaces. When we use it\nin our shell snippet, it needs to be quoted.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\nThis version tests fine for me with:\n\n#!/bin/sh\n\nrepo='repo with space'\n\nrm -rf \"$repo\"\n\ngit init \"$repo\" && cd \"$repo\" &&\necho content >file &&\ngit add file &&\ngit commit -m file &&\ngit filter-branch --index-filter \\\n  'git ls-files -s | sed \"s-\\t\\\"*-&newsubdir/-\" |\n    GIT_INDEX_FILE=$GIT_INDEX_FILE.new \\\n      git update-index --index-info &&\n   mv \"$GIT_INDEX_FILE.new\" \"$GIT_INDEX_FILE\"' HEAD\n\n Documentation/git-filter-branch.txt |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/Documentation/git-filter-branch.txt b/Documentation/git-filter-branch.txt\nindex 03c76c7..9dc1f2a 100644\n--- a/Documentation/git-filter-branch.txt\n+++ b/Documentation/git-filter-branch.txt\n@@ -359,11 +359,11 @@ To move the whole tree into a subdirectory, or remove it from there:\n ---------------------------------------------------------------\n git filter-branch --index-filter \\\n \t'git ls-files -s | sed \"s-\\t\\\"*-&newsubdir/-\" |\n \t\tGIT_INDEX_FILE=$GIT_INDEX_FILE.new \\\n \t\t\tgit update-index --index-info &&\n-\t mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD\n+\t mv \"$GIT_INDEX_FILE.new\" \"$GIT_INDEX_FILE\"' HEAD\n ---------------------------------------------------------------\n \n \n \n Checklist for Shrinking a Repository\n-- \n1.7.4.13.g8566c\n"},{"id":"164928","messageId":"4D964850.3050800@revelate.com","threadId":"26959","inReplyTo":"20110401144107.GA3103@sigill.intra.peff.net","subject":"Re: Problem using git-filter-branch to move tree when repository name contains space","fromName":"Jean-François Burdet","fromEmail":"jfburdet@revelate.com","sentAt":"2011-04-01T21:49:04Z","receivedAt":"2011-04-01T21:49:04Z","isPatch":false,"sender":{"key":"jfburdet@revelate.com","avatar":null},"body":"What you suggested solved my problem. What a fast answer ! 6minutes !\nThanks,\n\nJF.\n\nOn 01.04.2011 16:41, Jeff King wrote:\n> The problem is that GIT_INDEX_FILE is an absolute path that contains the\n> repo name. So it needs to be quoted in the mv command. This should work:\n> \n>   git filter-branch --index-filter \\\n>     'git ls-files -s | sed \"s-\\t\\\"*-&newsubdir/-\" |\n>       GIT_INDEX_FILE=$GIT_INDEX_FILE.new \\\n>         git update-index --index-info &&\n>      mv \"$GIT_INDEX_FILE.new\" \"$GIT_INDEX_FILE\"' HEAD\n> \n> -Peff\n> \n> \n"}]}