Skip to content

Commit 12f0a5e

Browse files
jherlandgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9057f0a commit 12f0a5e

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

git-cvsexportcommit.perl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use File::Temp qw(tempdir);
66
use Data::Dumper;
77
use File::Basename qw(basename dirname);
8+
use File::Spec;
89

910
our ($opt_h, $opt_P, $opt_p, $opt_v, $opt_c, $opt_f, $opt_a, $opt_m, $opt_d, $opt_u, $opt_w);
1011

@@ -15,17 +16,15 @@
1516
die "Need at least one commit identifier!" unless @ARGV;
1617

1718
if ($opt_w) {
19+
# Remember where GIT_DIR is before changing to CVS checkout
1820
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
2022
my $gd =`git-rev-parse --git-dir`;
2123
chomp($gd);
22-
if ($gd eq '.git') {
23-
my $wd = `pwd`;
24-
chomp($wd);
25-
$gd = $wd."/.git" ;
26-
}
2724
$ENV{GIT_DIR} = $gd;
2825
}
26+
# Make sure GIT_DIR is absolute
27+
$ENV{GIT_DIR} = File::Spec->rel2abs($ENV{GIT_DIR});
2928

3029
if (! -d $opt_w."/CVS" ) {
3130
die "$opt_w is not a CVS checkout";

t/t9200-git-cvsexportcommit.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ test_expect_success \
246246
;;
247247
esac
248248

249-
test_expect_failure '-w option should work with relative GIT_DIR' '
249+
test_expect_success '-w option should work with relative GIT_DIR' '
250250
mkdir W &&
251251
echo foobar >W/file1.txt &&
252252
echo bazzle >W/file2.txt &&

0 commit comments

Comments
 (0)