Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 94eaa80

Browse files
davvidgitster
authored andcommitted
difftool: support repositories with .git-files
Modern versions of "git submodule" use .git-files to setup the submodule directory. When run in a "git submodule"-created repository "git difftool --dir-diff" dies with the following error: $ git difftool -d HEAD~ fatal: This operation must be run in a work tree diff --raw --no-abbrev -z HEAD~: command returned error: 128 core.worktree is relative to the .git directory but the logic in find_worktree() does not account for it. Use `git rev-parse --show-toplevel` to find the worktree so that the dir-diff feature works inside a submodule. Reported-by: Gábor Lipták <[email protected]> Helped-by: Jens Lehmann <[email protected]> Helped-by: John Keeping <[email protected]> Signed-off-by: David Aguilar <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7bbc4e8 commit 94eaa80

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

git-difftool.perl

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,10 @@ sub usage
3939

4040
sub find_worktree
4141
{
42-
my ($repo) = @_;
43-
4442
# Git->repository->wc_path() does not honor changes to the working
4543
# tree location made by $ENV{GIT_WORK_TREE} or the 'core.worktree'
4644
# config variable.
47-
my $worktree;
48-
my $env_worktree = $ENV{GIT_WORK_TREE};
49-
my $core_worktree = Git::config('core.worktree');
50-
51-
if (defined($env_worktree) and (length($env_worktree) > 0)) {
52-
$worktree = $env_worktree;
53-
} elsif (defined($core_worktree) and (length($core_worktree) > 0)) {
54-
$worktree = $core_worktree;
55-
} else {
56-
$worktree = $repo->wc_path();
57-
}
58-
59-
return $worktree;
45+
return Git::command_oneline('rev-parse', '--show-toplevel');
6046
}
6147

6248
sub print_tool_help
@@ -418,7 +404,7 @@ sub dir_diff
418404
my $rc;
419405
my $error = 0;
420406
my $repo = Git->repository();
421-
my $workdir = find_worktree($repo);
407+
my $workdir = find_worktree();
422408
my ($a, $b, $tmpdir, @worktree) =
423409
setup_dir_diff($repo, $workdir, $symlinks);
424410

0 commit comments

Comments
 (0)