git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Problem using git-filter-branch to move tree when repository name contains space
@ 2011-04-01 14:30 Jean-François Burdet
  2011-04-01 14:41 ` Jeff King
  0 siblings, 1 reply; 4+ messages in thread
From: Jean-François Burdet @ 2011-04-01 14:30 UTC (permalink / raw)
  To: git

Hi,

I want to move my repository (wich is contained in a directory whose
name's containing a space)  root tree to a subdirectory.

I followed what's documented in
http://www.kernel.org/pub/software/scm/git/docs/git-filter-branch.html ,
using the last example :

git filter-branch --index-filter \
        'git ls-files -s | sed "s-\t\"*-&newsubdir/-" |
                GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
                        git update-index --index-info &&
         mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD


But, look at the following two scenario:

Scenario 1 : Repository have no space in it, everything works fine :
jfburdet@nagios:~$ mkdir gittest
jfburdet@nagios:~$ cd gittest/
jfburdet@nagios:~/gittest$ git init
Initialized empty Git repository in /home/jfburdet/gittest/.git/
jfburdet@nagios:~/gittest$ touch a_file
jfburdet@nagios:~/gittest$ git add .
jfburdet@nagios:~/gittest$ git commit -m "A commit"
[master (root-commit) e6261d5] A commit
 Committer: jfburdet <jfburdet@(none)>
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 a_file
 jfburdet@nagios:~/gittest$ git filter-branch --index-filter \
>         'git ls-files -s | sed "s-\t\"*-&newsubdir/-" |
>                 GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
>                         git update-index --index-info &&
>          mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD
Rewrite e6261d591357f39e1b4f95c0dfeb7a133e211161 (1/1)
Ref 'refs/heads/master' was rewritten

Scenario 2 : Repository have space in its directory name, making the
command fails
jfburdet@nagios:~$ mkdir "git test"
jfburdet@nagios:~$ cd "git test"
jfburdet@nagios:~/git test$
jfburdet@nagios:~/git test$ git init
Initialized empty Git repository in /home/jfburdet/git test/.git/
jfburdet@nagios:~/git test$ touch a_file
jfburdet@nagios:~/git test$ git add .
jfburdet@nagios:~/git test$ git commit -m "A commit"
[master (root-commit) 3658e30] A commit
 Committer: jfburdet <jfburdet@(none)>
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 a_file
jfburdet@nagios:~/git test$ git filter-branch --index-filter \
>         'git ls-files -s | sed "s-\t\"*-&newsubdir/-" |
>                 GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
>                         git update-index --index-info &&
>          mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD
Rewrite 3658e305df3ace21d39bf57dd4e0e5627818dfcc (1/1)mv: target
`test/.git-rewrite/t/../index' is not a directory
index filter failed: git ls-files -s | sed "s-  \"*-&newsubdir/-" |
                GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
                        git update-index --index-info &&
         mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE
jfburdet@nagios:~/git test$


I tried to tweak the sed expression with no success. Can someone help me
with that ?

Please note that I can't simply rename the directory before firing up
"git filter-branch" because I'm in a process of merging repositories and
their name are mandatory.

Cheers,

Jean-François,

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Problem using git-filter-branch to move tree when repository name contains space
  2011-04-01 14:30 Problem using git-filter-branch to move tree when repository name contains space Jean-François Burdet
@ 2011-04-01 14:41 ` Jeff King
  2011-04-01 14:46   ` [PATCH] docs: fix filter-branch subdir example for exotic repo names Jeff King
  2011-04-01 21:49   ` Problem using git-filter-branch to move tree when repository name contains space Jean-François Burdet
  0 siblings, 2 replies; 4+ messages in thread
From: Jeff King @ 2011-04-01 14:41 UTC (permalink / raw)
  To: Jean-François Burdet; +Cc: git

On Fri, Apr 01, 2011 at 04:30:26PM +0200, Jean-François Burdet wrote:

> I want to move my repository (wich is contained in a directory whose
> name's containing a space)  root tree to a subdirectory.
> 
> I followed what's documented in
> http://www.kernel.org/pub/software/scm/git/docs/git-filter-branch.html ,
> using the last example :
> 
> [...]
>
> jfburdet@nagios:~/git test$ git filter-branch --index-filter \
> >         'git ls-files -s | sed "s-\t\"*-&newsubdir/-" |
> >                 GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
> >                         git update-index --index-info &&
> >          mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD
> Rewrite 3658e305df3ace21d39bf57dd4e0e5627818dfcc (1/1)mv: target
> `test/.git-rewrite/t/../index' is not a directory

The problem is that GIT_INDEX_FILE is an absolute path that contains the
repo name. So it needs to be quoted in the mv command. This should work:

  git filter-branch --index-filter \
    'git ls-files -s | sed "s-\t\"*-&newsubdir/-" |
      GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
        git update-index --index-info &&
     mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' HEAD

-Peff

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] docs: fix filter-branch subdir example for exotic repo names
  2011-04-01 14:41 ` Jeff King
@ 2011-04-01 14:46   ` Jeff King
  2011-04-01 21:49   ` Problem using git-filter-branch to move tree when repository name contains space Jean-François Burdet
  1 sibling, 0 replies; 4+ messages in thread
From: Jeff King @ 2011-04-01 14:46 UTC (permalink / raw)
  To: Jean-François Burdet; +Cc: Junio C Hamano, git

The GIT_INDEX_FILE variable we get from git has the full
path to the repo, which may contain spaces. When we use it
in our shell snippet, it needs to be quoted.

Signed-off-by: Jeff King <peff@peff.net>
---
This version tests fine for me with:

#!/bin/sh

repo='repo with space'

rm -rf "$repo"

git init "$repo" && cd "$repo" &&
echo content >file &&
git add file &&
git commit -m file &&
git filter-branch --index-filter \
  'git ls-files -s | sed "s-\t\"*-&newsubdir/-" |
    GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
      git update-index --index-info &&
   mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' HEAD

 Documentation/git-filter-branch.txt |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/Documentation/git-filter-branch.txt b/Documentation/git-filter-branch.txt
index 03c76c7..9dc1f2a 100644
--- a/Documentation/git-filter-branch.txt
+++ b/Documentation/git-filter-branch.txt
@@ -359,11 +359,11 @@ To move the whole tree into a subdirectory, or remove it from there:
 ---------------------------------------------------------------
 git filter-branch --index-filter \
 	'git ls-files -s | sed "s-\t\"*-&newsubdir/-" |
 		GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
 			git update-index --index-info &&
-	 mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD
+	 mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' HEAD
 ---------------------------------------------------------------
 
 
 
 Checklist for Shrinking a Repository
-- 
1.7.4.13.g8566c

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: Problem using git-filter-branch to move tree when repository name contains space
  2011-04-01 14:41 ` Jeff King
  2011-04-01 14:46   ` [PATCH] docs: fix filter-branch subdir example for exotic repo names Jeff King
@ 2011-04-01 21:49   ` Jean-François Burdet
  1 sibling, 0 replies; 4+ messages in thread
From: Jean-François Burdet @ 2011-04-01 21:49 UTC (permalink / raw)
  To: Jeff King; +Cc: git

What you suggested solved my problem. What a fast answer ! 6minutes !
Thanks,

JF.

On 01.04.2011 16:41, Jeff King wrote:
> The problem is that GIT_INDEX_FILE is an absolute path that contains the
> repo name. So it needs to be quoted in the mv command. This should work:
> 
>   git filter-branch --index-filter \
>     'git ls-files -s | sed "s-\t\"*-&newsubdir/-" |
>       GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
>         git update-index --index-info &&
>      mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' HEAD
> 
> -Peff
> 
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-04-01 21:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-01 14:30 Problem using git-filter-branch to move tree when repository name contains space Jean-François Burdet
2011-04-01 14:41 ` Jeff King
2011-04-01 14:46   ` [PATCH] docs: fix filter-branch subdir example for exotic repo names Jeff King
2011-04-01 21:49   ` Problem using git-filter-branch to move tree when repository name contains space Jean-François Burdet

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).