Skip to content

Commit e96e98b

Browse files
committed
Merge branch 'da/mergetool-tool-help'
Allow "git mergetool --help" to run outside a Git repository. * da/mergetool-tool-help: difftool: don't assume that default sh is sane mergetool: don't require a work tree for --tool-help git-sh-setup: move GIT_DIR initialization into a function mergetool: use more conservative temporary filenames test-lib-functions: adjust style to match CodingGuidelines t7610-mergetool: prefer test_config over git config
2 parents 02f4db8 + 4fb4b02 commit e96e98b

File tree

4 files changed

+21
-14
lines changed

4 files changed

+21
-14
lines changed

git-difftool.perl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,9 @@ sub find_worktree
4747

4848
sub print_tool_help
4949
{
50-
my $cmd = 'TOOL_MODE=diff';
51-
$cmd .= ' && . "$(git --exec-path)/git-mergetool--lib"';
52-
$cmd .= ' && show_tool_help';
53-
5450
# See the comment at the bottom of file_diff() for the reason behind
5551
# using system() followed by exit() instead of exec().
56-
my $rc = system('sh', '-c', $cmd);
52+
my $rc = system(qw(git mergetool --tool-help=diff));
5753
exit($rc | ($rc >> 8));
5854
}
5955

git-mergetool.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010

1111
USAGE='[--tool=tool] [--tool-help] [-y|--no-prompt|--prompt] [file to merge] ...'
1212
SUBDIRECTORY_OK=Yes
13+
NONGIT_OK=Yes
1314
OPTIONS_SPEC=
1415
TOOL_MODE=merge
1516
. git-sh-setup
1617
. git-mergetool--lib
17-
require_work_tree
1818

1919
# Returns true if the mode reflects a symlink
2020
is_symlink () {
@@ -327,6 +327,10 @@ guessed_merge_tool=false
327327
while test $# != 0
328328
do
329329
case "$1" in
330+
--tool-help=*)
331+
TOOL_MODE=${1#--tool-help=}
332+
show_tool_help
333+
;;
330334
--tool-help)
331335
show_tool_help
332336
;;
@@ -378,6 +382,9 @@ prompt_after_failed_merge () {
378382
done
379383
}
380384

385+
git_dir_init
386+
require_work_tree
387+
381388
if test -z "$merge_tool"
382389
then
383390
# Check if a merge tool has been configured

git-sh-setup.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,7 @@ esac
330330
331331
# Make sure we are in a valid repository of a vintage we understand,
332332
# if we require to be in a git repository.
333-
if test -z "$NONGIT_OK"
334-
then
333+
git_dir_init () {
335334
GIT_DIR=$(git rev-parse --git-dir) || exit
336335
if [ -z "$SUBDIRECTORY_OK" ]
337336
then
@@ -346,6 +345,11 @@ then
346345
exit 1
347346
}
348347
: ${GIT_OBJECT_DIRECTORY="$GIT_DIR/objects"}
348+
}
349+
350+
if test -z "$NONGIT_OK"
351+
then
352+
git_dir_init
349353
fi
350354
351355
peel_committish () {

t/t7610-mergetool.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Testing basic merge tool invocation'
1414
# running mergetool
1515

1616
test_expect_success 'setup' '
17-
git config rerere.enabled true &&
17+
test_config rerere.enabled true &&
1818
echo master >file1 &&
1919
echo master spaced >"spaced name" &&
2020
echo master file11 >file11 &&
@@ -129,7 +129,7 @@ test_expect_success 'mergetool crlf' '
129129
git submodule update -N &&
130130
test "$(cat submod/bar)" = "master submodule" &&
131131
git commit -m "branch1 resolved with mergetool - autocrlf" &&
132-
git config core.autocrlf false &&
132+
test_config core.autocrlf false &&
133133
git reset --hard
134134
'
135135

@@ -176,7 +176,7 @@ test_expect_success 'mergetool skips autoresolved' '
176176
test_expect_success 'mergetool merges all from subdir' '
177177
(
178178
cd subdir &&
179-
git config rerere.enabled false &&
179+
test_config rerere.enabled false &&
180180
test_must_fail git merge master &&
181181
( yes "r" | git mergetool ../submod ) &&
182182
( yes "d" "d" | git mergetool --no-prompt ) &&
@@ -190,7 +190,7 @@ test_expect_success 'mergetool merges all from subdir' '
190190
'
191191

192192
test_expect_success 'mergetool skips resolved paths when rerere is active' '
193-
git config rerere.enabled true &&
193+
test_config rerere.enabled true &&
194194
rm -rf .git/rr-cache &&
195195
git checkout -b test5 branch1 &&
196196
git submodule update -N &&
@@ -204,7 +204,7 @@ test_expect_success 'mergetool skips resolved paths when rerere is active' '
204204
'
205205

206206
test_expect_success 'conflicted stash sets up rerere' '
207-
git config rerere.enabled true &&
207+
test_config rerere.enabled true &&
208208
git checkout stash1 &&
209209
echo "Conflicting stash content" >file11 &&
210210
git stash &&
@@ -232,7 +232,7 @@ test_expect_success 'conflicted stash sets up rerere' '
232232

233233
test_expect_success 'mergetool takes partial path' '
234234
git reset --hard &&
235-
git config rerere.enabled false &&
235+
test_config rerere.enabled false &&
236236
git checkout -b test12 branch1 &&
237237
git submodule update -N &&
238238
test_must_fail git merge master &&

0 commit comments

Comments
 (0)