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

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