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

4 messages from 2005-11-25 to 2005-11-30. Participants: Johannes Schindelin, Junio C Hamano, Alex Riesen, Josef Weidendorfer.
Thread: https://gitlist.dev/t/2673

## Johannes Schindelin, 2005-11-25 11:36

Subject: [PATCH] Make git-mv work in subdirectories, too
Message-ID: <Pine.LNX.4.63.0511251236060.30796@wbgn013.biozentrum.uni-wuerzburg.de>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0511251236060.30796%40wbgn013.biozentrum.uni-wuerzburg.de

```

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
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, 2005-11-26 02:45

Subject: Re: [PATCH] Make git-mv work in subdirectories, too
Message-ID: <7vmzjsdt3z.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vmzjsdt3z.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <Pine.LNX.4.63.0511251236060.30796@wbgn013.biozentrum.uni-wuerzburg.de>

```
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

> 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.

---

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, 2005-11-29 22:10

Subject: Re: [PATCH] Make git-mv work in subdirectories, too
Message-ID: <20051129221024.GB3033@steel.home>
URL: https://gitlist.dev/e/20051129221024.GB3033%40steel.home
In-Reply-To: <7vmzjsdt3z.fsf@assigned-by-dhcp.cox.net>

```
Junio C Hamano, Sat, Nov 26, 2005 03:45:52 +0100:
> > 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, 2005-11-30 14:50

Subject: Re: [PATCH] Make git-mv work in subdirectories, too
Message-ID: <200511301550.10644.Josef.Weidendorfer@gmx.de>
URL: https://gitlist.dev/e/200511301550.10644.Josef.Weidendorfer%40gmx.de
In-Reply-To: <20051129221024.GB3033@steel.home>

```
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

```
