Fix 'git cvsexportcommit -w $cvsdir ...' when used with relative $GIT_DIR
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johan Herland committed
Feb 12, 2008 at 00:43 UTC
12f0a5ea7dc999bfe06973bf61261fc809c2b2fb
2 files changed
+6
-7
git-cvsexportcommit.perl
+5
-6
@@ -5,6 +5,7 @@ use Getopt::Std;
5
use File::Temp qw(tempdir);
6
use Data::Dumper;
7
use File::Basename qw(basename dirname);
8
+use File::Spec;
9
10
our ($opt_h, $opt_P, $opt_p, $opt_v, $opt_c, $opt_f, $opt_a, $opt_m, $opt_d, $opt_u, $opt_w);
11
@@ -15,17 +16,15 @@ $opt_h && usage();
16
die "Need at least one commit identifier!" unless @ARGV;
17
18
if ($opt_w) {
19
+ # Remember where GIT_DIR is before changing to CVS checkout
20
unless ($ENV{GIT_DIR}) {
19
- # Remember where our GIT_DIR is before changing to CVS checkout
21
+ # No GIT_DIR set. Figure it out for ourselves
22
my $gd =`git-rev-parse --git-dir`;
23
chomp($gd);
22
- if ($gd eq '.git') {
23
- my $wd = `pwd`;
24
- chomp($wd);
25
- $gd = $wd."/.git" ;
26
- }
24
$ENV{GIT_DIR} = $gd;
25
}
26
+ # Make sure GIT_DIR is absolute
27
+ $ENV{GIT_DIR} = File::Spec->rel2abs($ENV{GIT_DIR});
28
29
if (! -d $opt_w."/CVS" ) {
30
die "$opt_w is not a CVS checkout";
t/t9200-git-cvsexportcommit.sh
+1
-1
@@ -246,7 +246,7 @@ test_expect_success \
246
;;
247
esac
248
249
-test_expect_failure '-w option should work with relative GIT_DIR' '
249
+test_expect_success '-w option should work with relative GIT_DIR' '
250
mkdir W &&
251
echo foobar >W/file1.txt &&
252
echo bazzle >W/file2.txt &&