git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Fix 'git cvsexportcommit -w $cvsdir ...' when used with relative $GIT_DIR
@ 2008-02-11  1:28 Johan Herland
  2008-02-11 20:10 ` Junio C Hamano
  2008-02-11 20:58 ` Robin Rosenberg
  0 siblings, 2 replies; 8+ messages in thread
From: Johan Herland @ 2008-02-11  1:28 UTC (permalink / raw)
  To: git

When using the '-w $cvsdir' option to cvsexportcommit, it will chdir into
$cvsdir before executing several other git commands. If $GIT_DIR is set to
a relative path (e.g. '.'), the git commands executed by cvsexportcommit
will naturally fail with "fatal: Not a git repository".

Therefore, if $GIT_DIR is relative, prepend $PWD to $GIT_DIR before the
chdir to $cvsdir.

Signed-off-by: Johan Herland <johan@herland.net>
---

I'm working on an update hook script for automatically propagating commits 
to a CVS server. My script calls 'git cvsexportcommit -w $cvsdir ...'. 
However, the hooks infrastructure invokes the update hook script with the 
(bare, in my case) Git repo as $PWD and sets up GIT_DIR="." in the script's 
environment. For now, I work around this bug in my script by forcing 
$GIT_DIR to $PWD, but this really seems like a bug in cvsexportcommit.

In my case, this bug can also be fixed by making sure the hook 
infrastructure set up an _absolute_ GIT_DIR for the update hook, something 
I'd consider more polite than the current GIT_DIR=".". Whether we want to 
fix this as well should be discussed. But the patch below is needed in any 
case, since cvsexportcommit may not only be called from hook scripts.


Have fun! :)

...Johan


 git-cvsexportcommit.perl |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/git-cvsexportcommit.perl b/git-cvsexportcommit.perl
index d2e50c3..fd4fbfb 100755
--- a/git-cvsexportcommit.perl
+++ b/git-cvsexportcommit.perl
@@ -15,15 +15,18 @@ $opt_h && usage();
 die "Need at least one commit identifier!" unless @ARGV;
 
 if ($opt_w) {
+	# Remember where GIT_DIR is before changing to CVS checkout
 	unless ($ENV{GIT_DIR}) {
-		# Remember where our GIT_DIR is before changing to CVS checkout
+		# Oops no GIT_DIR set. Figure out for ourselves
 		my $gd =`git-rev-parse --git-dir`;
 		chomp($gd);
-		if ($gd eq '.git') {
-			my $wd = `pwd`;
-			chomp($wd);
-			$gd = $wd."/.git"	;
-		}
+		$ENV{GIT_DIR} = $gd;
+	}
+	unless ($ENV{GIT_DIR} =~ m[^/]) {
+		# GIT_DIR is relative. Prepend $PWD
+		my $wd = `pwd`;
+		chomp($wd);
+		my $gd = $wd."/".$ENV{GIT_DIR};
 		$ENV{GIT_DIR} = $gd;
 	}
 
-- 
1.5.4.2.g41ac4

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

* Re: [PATCH] Fix 'git cvsexportcommit -w $cvsdir ...' when used with relative $GIT_DIR
  2008-02-11  1:28 [PATCH] Fix 'git cvsexportcommit -w $cvsdir ...' when used with relative $GIT_DIR Johan Herland
@ 2008-02-11 20:10 ` Junio C Hamano
  2008-02-11 20:58 ` Robin Rosenberg
  1 sibling, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2008-02-11 20:10 UTC (permalink / raw)
  To: Johan Herland; +Cc: git, Robin Rosenberg

Johan Herland <johan@herland.net> writes:

> When using the '-w $cvsdir' option to cvsexportcommit, it will chdir into
> $cvsdir before executing several other git commands. If $GIT_DIR is set to
> a relative path (e.g. '.'), the git commands executed by cvsexportcommit
> will naturally fail with "fatal: Not a git repository".
>
> Therefore, if $GIT_DIR is relative, prepend $PWD to $GIT_DIR before the
> chdir to $cvsdir.

That sounds like a correct thing to do.  Robin?

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

* Re: [PATCH] Fix 'git cvsexportcommit -w $cvsdir ...' when used with relative $GIT_DIR
  2008-02-11  1:28 [PATCH] Fix 'git cvsexportcommit -w $cvsdir ...' when used with relative $GIT_DIR Johan Herland
  2008-02-11 20:10 ` Junio C Hamano
@ 2008-02-11 20:58 ` Robin Rosenberg
  2008-02-11 23:43   ` Johan Herland
  1 sibling, 1 reply; 8+ messages in thread
From: Robin Rosenberg @ 2008-02-11 20:58 UTC (permalink / raw)
  To: Johan Herland; +Cc: git

måndagen den 11 februari 2008 skrev Johan Herland:
> When using the '-w $cvsdir' option to cvsexportcommit, it will chdir into
> $cvsdir before executing several other git commands. If $GIT_DIR is set to
> a relative path (e.g. '.'), the git commands executed by cvsexportcommit
> will naturally fail with "fatal: Not a git repository".
[...]

>  die "Need at least one commit identifier!" unless @ARGV;
>  
>  if ($opt_w) {
> +	# Remember where GIT_DIR is before changing to CVS checkout
>  	unless ($ENV{GIT_DIR}) {
> -		# Remember where our GIT_DIR is before changing to CVS checkout
> +		# Oops no GIT_DIR set. Figure out for ourselves

That's not an "Oops". It's perfectly normal not to have GIT_DIR set.

>  		my $gd =`git-rev-parse --git-dir`;
>  		chomp($gd);
> -		if ($gd eq '.git') {
> -			my $wd = `pwd`;Kopia
> -			chomp($wd);
> -			$gd = $wd."/.git"	;
> -		}
> +		$ENV{GIT_DIR} = $gd;
> +	}
> +	unless ($ENV{GIT_DIR} =~ m[^/]) {
> +		# GIT_DIR is relative. Prepend $PWD
Hmm. C:/foo? You should probably use rel2abs in the File::Spec
module.

-- robin

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

* [PATCH] Fix 'git cvsexportcommit -w $cvsdir ...' when used with relative $GIT_DIR
  2008-02-11 20:58 ` Robin Rosenberg
@ 2008-02-11 23:43   ` Johan Herland
  2008-02-12 20:41     ` Robin Rosenberg
  0 siblings, 1 reply; 8+ messages in thread
From: Johan Herland @ 2008-02-11 23:43 UTC (permalink / raw)
  To: Robin Rosenberg; +Cc: git, Junio C Hamano

When using the '-w $cvsdir' option to cvsexportcommit, it will chdir into
$cvsdir before executing several other git commands. If $GIT_DIR is set to
a relative path (e.g. '.'), the git commands executed by cvsexportcommit
will naturally fail.

Therefore, ensure that $GIT_DIR is absolute before the chdir to $cvsdir.

Signed-off-by: Johan Herland <johan@herland.net>
---

On Monday 11 February 2008, Robin Rosenberg wrote:
> måndagen den 11 februari 2008 skrev Johan Herland:
> > -		# Remember where our GIT_DIR is before changing to CVS checkout
> > +		# Oops no GIT_DIR set. Figure out for ourselves
> 
> That's not an "Oops". It's perfectly normal not to have GIT_DIR set.

Of course not. Fixed.

> > +	unless ($ENV{GIT_DIR} =~ m[^/]) {
> 
> Hmm. C:/foo? You should probably use rel2abs in the File::Spec 
> module.

Thanks. Fixed.


Have fun! :)

...Johan


 git-cvsexportcommit.perl |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/git-cvsexportcommit.perl b/git-cvsexportcommit.perl
index d2e50c3..2a8ad1e 100755
--- a/git-cvsexportcommit.perl
+++ b/git-cvsexportcommit.perl
@@ -5,6 +5,7 @@ use Getopt::Std;
 use File::Temp qw(tempdir);
 use Data::Dumper;
 use File::Basename qw(basename dirname);
+use File::Spec;
 
 our ($opt_h, $opt_P, $opt_p, $opt_v, $opt_c, $opt_f, $opt_a, $opt_m, $opt_d, $opt_u, $opt_w);
 
@@ -15,17 +16,15 @@ $opt_h && usage();
 die "Need at least one commit identifier!" unless @ARGV;
 
 if ($opt_w) {
+	# Remember where GIT_DIR is before changing to CVS checkout
 	unless ($ENV{GIT_DIR}) {
-		# Remember where our GIT_DIR is before changing to CVS checkout
+		# No GIT_DIR set. Figure it out for ourselves
 		my $gd =`git-rev-parse --git-dir`;
 		chomp($gd);
-		if ($gd eq '.git') {
-			my $wd = `pwd`;
-			chomp($wd);
-			$gd = $wd."/.git"	;
-		}
 		$ENV{GIT_DIR} = $gd;
 	}
+	# Make sure GIT_DIR is absolute
+	$ENV{GIT_DIR} = File::Spec->rel2abs($ENV{GIT_DIR});
 
 	if (! -d $opt_w."/CVS" ) {
 		die "$opt_w is not a CVS checkout";
-- 
1.5.4.2.g41ac4

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

* Re: [PATCH] Fix 'git cvsexportcommit -w $cvsdir ...' when used with relative $GIT_DIR
  2008-02-11 23:43   ` Johan Herland
@ 2008-02-12 20:41     ` Robin Rosenberg
  2008-02-13  3:11       ` [PATCH] Add testcase for 'git cvsexportcommit -w $cvsdir ...' " Johan Herland
  0 siblings, 1 reply; 8+ messages in thread
From: Robin Rosenberg @ 2008-02-12 20:41 UTC (permalink / raw)
  To: Johan Herland; +Cc: git, Junio C Hamano


Looks ok. Something for the test suite?

-- robin

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

* [PATCH] Add testcase for 'git cvsexportcommit -w $cvsdir ...' with relative $GIT_DIR
  2008-02-12 20:41     ` Robin Rosenberg
@ 2008-02-13  3:11       ` Johan Herland
  2008-02-13  7:58         ` Junio C Hamano
  0 siblings, 1 reply; 8+ messages in thread
From: Johan Herland @ 2008-02-13  3:11 UTC (permalink / raw)
  To: Robin Rosenberg; +Cc: git, Junio C Hamano

The testcase verifies that 'git cvsexportcommit' functions correctly when
the '-w' option is used, and GIT_DIR is set to a relative path (e.g. '.').

Signed-off-by: Johan Herland <johan@herland.net>
---

On Tuesday 12 February 2008, Robin Rosenberg wrote:
> Looks ok. Something for the test suite?

Like this?


Have fun! :)

...Johan


 t/t9200-git-cvsexportcommit.sh |   18 +++++++++++++++++-
 1 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/t/t9200-git-cvsexportcommit.sh b/t/t9200-git-cvsexportcommit.sh
index a15222c..5dae88c 100755
--- a/t/t9200-git-cvsexportcommit.sh
+++ b/t/t9200-git-cvsexportcommit.sh
@@ -2,7 +2,7 @@
 #
 # Copyright (c) Robin Rosenberg
 #
-test_description='CVS export comit. '
+test_description='Test export of commits to CVS'
 
 . ./test-lib.sh
 
@@ -246,4 +246,20 @@ test_expect_success \
 	;;
 esac
 
+test_expect_success \
+     '-w option should work with relative GIT_DIR' \
+     'mkdir W &&
+      echo foobar >W/file1.txt &&
+      echo bazzle >W/file2.txt &&
+      git add W/file1.txt &&
+      git add W/file2.txt &&
+      git commit -m "More updates" &&
+      id=$(git rev-list --max-count=1 HEAD) &&
+      (cd "$GIT_DIR" &&
+      GIT_DIR=. git cvsexportcommit -w "$CVSWORK" -c $id &&
+      check_entries "$CVSWORK/W" "file1.txt/1.1/|file2.txt/1.1/" &&
+      diff -u "$CVSWORK/W/file1.txt" ../W/file1.txt &&
+      diff -u "$CVSWORK/W/file2.txt" ../W/file2.txt
+      )'
+
 test_done
-- 
1.5.4.2.g41ac4

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

* Re: [PATCH] Add testcase for 'git cvsexportcommit -w $cvsdir ...' with relative $GIT_DIR
  2008-02-13  3:11       ` [PATCH] Add testcase for 'git cvsexportcommit -w $cvsdir ...' " Johan Herland
@ 2008-02-13  7:58         ` Junio C Hamano
  2008-02-13  9:26           ` Jakub Narebski
  0 siblings, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2008-02-13  7:58 UTC (permalink / raw)
  To: Johan Herland; +Cc: Robin Rosenberg, git

Johan Herland <johan@herland.net> writes:

> The testcase verifies that 'git cvsexportcommit' functions correctly when
> the '-w' option is used, and GIT_DIR is set to a relative path (e.g. '.').
>
> Signed-off-by: Johan Herland <johan@herland.net>
> ---
>
> On Tuesday 12 February 2008, Robin Rosenberg wrote:
>> Looks ok. Something for the test suite?
>
> Like this?

Yeah, looks good.

Except that I'll reorder the patches so that

 (1) this test comes first, but with test_expect_failure instead;

 (2) then your earlier fix patch, but with a change that changes
     the test_expect_failure to test_expect_success.

Thanks.

Perhaps it would be a good idea to require fix-up patches to
always come with a test case to prevent future regression.

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

* Re: [PATCH] Add testcase for 'git cvsexportcommit -w $cvsdir ...' with relative $GIT_DIR
  2008-02-13  7:58         ` Junio C Hamano
@ 2008-02-13  9:26           ` Jakub Narebski
  0 siblings, 0 replies; 8+ messages in thread
From: Jakub Narebski @ 2008-02-13  9:26 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Johan Herland, Robin Rosenberg, git

Junio C Hamano <gitster@pobox.com> writes:

> Except that I'll reorder the patches so that
> 
>  (1) this test comes first, but with test_expect_failure instead;
> 
>  (2) then your earlier fix patch, but with a change that changes
>      the test_expect_failure to test_expect_success.
> 
> Thanks.
> 
> Perhaps it would be a good idea to require fix-up patches to
> always come with a test case to prevent future regression.

Perhaps we should add this hint to SubmittingPatches, on top
of your additions? And to t/README?

-- 
Jakub Narebski
Poland
ShadeHawk on #git

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

end of thread, other threads:[~2008-02-13  9:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-11  1:28 [PATCH] Fix 'git cvsexportcommit -w $cvsdir ...' when used with relative $GIT_DIR Johan Herland
2008-02-11 20:10 ` Junio C Hamano
2008-02-11 20:58 ` Robin Rosenberg
2008-02-11 23:43   ` Johan Herland
2008-02-12 20:41     ` Robin Rosenberg
2008-02-13  3:11       ` [PATCH] Add testcase for 'git cvsexportcommit -w $cvsdir ...' " Johan Herland
2008-02-13  7:58         ` Junio C Hamano
2008-02-13  9:26           ` Jakub Narebski

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 NNTP newsgroup(s).