threads / patch / 2673

patchMake git-mv work in subdirectories, too

Subject: [PATCH] Make git-mv work in subdirectories, too

## tl;dr

4 messages between Nov 25, 2005 and Nov 30, 2005. Diffs are folded; open one to read it.

replies: 3people: 4as markdown or json

Johannes Schindelin· Nov 25, 2005, 11:36 UTC · lore

Turns out, all git programs git-mv uses are capable of operating in a subdirectory just fine. So don't complain about it.

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---
	I am no Perl guru, so this might not be the best way to go
	about it. Also, if people agree, I would like to remove the
	extra check for GIT_DIR validity, since git-rev-parse --git-dir
	does that already.
 git-mv.perl |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

applies-to: 6b942d45a420cf8f4064f77713d9b218e7fa53cb fa750ba9ea3a27b39c8931b18cf0e60a89bf9fd7

Show changes to git-mv.perl +2 −1
diff --git a/git-mv.perl b/git-mv.perl
index bf54c38..bb61add 100755
--- a/git-mv.perl
+++ b/git-mv.perl
@@ -34,7 +34,8 @@ EOT
 }
 
 # Sanity checks:
-my $GIT_DIR = $ENV{'GIT_DIR'} || ".git";
+my $GIT_DIR = `git-rev-parse --git-dir`;
+$GIT_DIR =~ s/\n$//;
 
 unless ( -d $GIT_DIR && -d $GIT_DIR . "/objects" && 
 	-d $GIT_DIR . "/objects/" && -d $GIT_DIR . "/refs") {
---
0.99.9.GIT
Junio C Hamano· Nov 26, 2005, 02:45 UTC · re: Johannes Schindelin · lore

Re: [PATCH] Make git-mv work in subdirectories, too

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
Show 11 quoted lines
> Turns out, all git programs git-mv uses are capable of operating in
> a subdirectory just fine. So don't complain about it.
>
> Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
>
> ---
>
> 	I am no Perl guru, so this might not be the best way to go
> 	about it. Also, if people agree, I would like to remove the
> 	extra check for GIT_DIR validity, since git-rev-parse --git-dir
> 	does that already.

I think that sounds sane. You need to grab the exit status from `git-rev-parse --git-dir`, so the patch would become something like the attached. I haven't seriously used git-mv myself, so somebody needs to test it, and if it actually works and Ack on it, please.

---
Show changes to git-mv.perl +3 −9
diff --git a/git-mv.perl b/git-mv.perl
index bf54c38..6dda333 100755
--- a/git-mv.perl
+++ b/git-mv.perl
@@ -33,15 +33,9 @@ EOT
 	exit(1);
 }
 
-# Sanity checks:
-my $GIT_DIR = $ENV{'GIT_DIR'} || ".git";
-
-unless ( -d $GIT_DIR && -d $GIT_DIR . "/objects" && 
-	-d $GIT_DIR . "/objects/" && -d $GIT_DIR . "/refs") {
-    print "Git repository not found.";
-    usage();
-}
-
+my $GIT_DIR = `git rev-parse --git-dir`;
+exit 1 if $?; # rev-parse would have given "not a git dir" message.
+chomp($GIT_DIR);
 
 our ($opt_n, $opt_f, $opt_h, $opt_k, $opt_v);
 getopts("hnfkv") || usage;
Alex Riesen· Nov 29, 2005, 22:10 UTC · re: Junio C Hamano · lore

Re: [PATCH] Make git-mv work in subdirectories, too

Junio C Hamano, Sat, Nov 26, 2005 03:45:52 +0100:
Show 17 quoted lines
> > Turns out, all git programs git-mv uses are capable of operating in
> > a subdirectory just fine. So don't complain about it.
> >
> > Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
> >
> > ---
> >
> > 	I am no Perl guru, so this might not be the best way to go
> > 	about it. Also, if people agree, I would like to remove the
> > 	extra check for GIT_DIR validity, since git-rev-parse --git-dir
> > 	does that already.
> 
> I think that sounds sane.  You need to grab the exit status from
> `git-rev-parse --git-dir`, so the patch would become something
> like the attached.  I haven't seriously used git-mv myself, so
> somebody needs to test it, and if it actually works and Ack on
> it, please.
It actually works in subdirs.
--- t/t4007-mv.sh
#!/bin/sh

test_description='git-mv in subdirs' . ./test-lib.sh

test_expect_success \
    'prepare reference tree' \
    'mkdir path0 path1 &&
     cp ../../COPYING path0/COPYING &&
     git-add path0/COPYING &&
     git-commit -m add -a'
test_expect_success \
    'moving the file' \
    'cd path0 && git-mv COPYING ../path1/COPYING'
# in path0 currently
test_expect_success \
    'commiting the change' \
    'cd .. && git-commit -m move -a'
test_expect_success \
    'checking the commit' \
    'git-diff-tree -r -M --name-status  HEAD^ HEAD | \
    grep -E "^R100.+path0/COPYING.+path1/COPYING"'
test_done
Josef Weidendorfer· Nov 30, 2005, 14:50 UTC · re: Alex Riesen · lore

Re: [PATCH] Make git-mv work in subdirectories, too

On Tuesday 29 November 2005 23:10, Alex Riesen wrote:
> It actually works in subdirs.
> 
> --- t/t4007-mv.sh
> test_expect_success \
>     'moving the file' \
>     'cd path0 && git-mv COPYING ../path1/COPYING'

Thanks for the test. After moving to path1, you should check the other way, too:

  cd path0 && git-mv ../path1/COPYING COPYING

And this currenly does *not* work because git-mv is only aware of the git-controlled files in the subdirectory.

We probably also should check that source and target are in the same git repo.

Josef

← back to recent threads