Skip to content

Commit 9d764f9

Browse files
committed
Merge branch 'fl/git-pm'
* fl/git-pm: Git.pm: Always set Repository to absolute path if autodetecting Git.pm: Set GIT_WORK_TREE if we set GIT_DIR
2 parents 77ce907 + fe53bbc commit 9d764f9

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

perl/Git.pm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ sub repository {
185185

186186
if ($dir) {
187187
$dir =~ m#^/# or $dir = $opts{Directory} . '/' . $dir;
188-
$opts{Repository} = $dir;
188+
$opts{Repository} = abs_path($dir);
189189

190190
# If --git-dir went ok, this shouldn't die either.
191191
my $prefix = $search->command_oneline('rev-parse', '--show-prefix');
@@ -1280,6 +1280,8 @@ sub _cmd_exec {
12801280
my ($self, @args) = @_;
12811281
if ($self) {
12821282
$self->repo_path() and $ENV{'GIT_DIR'} = $self->repo_path();
1283+
$self->repo_path() and $self->wc_path()
1284+
and $ENV{'GIT_WORK_TREE'} = $self->wc_path();
12831285
$self->wc_path() and chdir($self->wc_path());
12841286
$self->wc_subdir() and chdir($self->wc_subdir());
12851287
}

t/t9700-perl-git.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ test_expect_success \
2929
git add . &&
3030
git commit -m "first commit" &&
3131
32+
echo "new file in subdir 2" > directory2/file2 &&
33+
git add . &&
34+
git commit -m "commit in directory2" &&
35+
3236
echo "changed file 1" > file1 &&
3337
git commit -a -m "second commit" &&
3438

t/t9700/test.pl

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,22 @@
8686
unlink $tmpfile;
8787

8888
# paths
89-
is($r->repo_path, "./.git", "repo_path");
89+
is($r->repo_path, $abs_repo_dir . "/.git", "repo_path");
9090
is($r->wc_path, $abs_repo_dir . "/", "wc_path");
9191
is($r->wc_subdir, "", "wc_subdir initial");
9292
$r->wc_chdir("directory1");
9393
is($r->wc_subdir, "directory1", "wc_subdir after wc_chdir");
94-
TODO: {
95-
local $TODO = "commands do not work after wc_chdir";
96-
# Failure output is active even in non-verbose mode and thus
97-
# annoying. Hence we skip these tests as long as they fail.
98-
todo_skip 'config after wc_chdir', 1;
99-
is($r->config("color.string"), "value", "config after wc_chdir");
100-
}
94+
is($r->config("test.string"), "value", "config after wc_chdir");
95+
96+
# Object generation in sub directory
97+
chdir("directory2");
98+
my $r2 = Git->repository();
99+
is($r2->repo_path, $abs_repo_dir . "/.git", "repo_path (2)");
100+
is($r2->wc_path, $abs_repo_dir . "/", "wc_path (2)");
101+
is($r2->wc_subdir, "directory2/", "wc_subdir initial (2)");
102+
103+
# commands in sub directory
104+
my $last_commit = $r2->command_oneline(qw(rev-parse --verify HEAD));
105+
like($last_commit, qr/^[0-9a-fA-F]{40}$/, 'rev-parse returned hash');
106+
my $dir_commit = $r2->command_oneline('log', '-n1', '--pretty=format:%H', '.');
107+
isnt($last_commit, $dir_commit, 'log . does not show last commit');

0 commit comments

Comments
 (0)