From: Junio C Hamano Date: Tue, 21 Oct 2014 20:28:37 +0000 (-0700) Subject: Merge branch 'da/mergetool-tool-help' X-Git-Tag: v2.2.0-rc0~29 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/e96e98b3399ae4c638466f84068fe94d4712c5a3?ds=inline;hp=-c 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 --- e96e98b3399ae4c638466f84068fe94d4712c5a3 diff --combined git-mergetool.sh index 96a61ba6f4,821253e368..ec644d542d --- a/git-mergetool.sh +++ b/git-mergetool.sh @@@ -10,11 -10,11 +10,11 @@@ USAGE='[--tool=tool] [--tool-help] [-y|--no-prompt|--prompt] [file to merge] ...' SUBDIRECTORY_OK=Yes + NONGIT_OK=Yes OPTIONS_SPEC= TOOL_MODE=merge . git-sh-setup . git-mergetool--lib - require_work_tree # Returns true if the mode reflects a symlink is_symlink () { @@@ -205,7 -205,7 +205,7 @@@ checkout_staged_file () "$(git checkout-index --temp --stage="$1" "$2" 2>/dev/null)" \ : '\([^ ]*\) ') - if test $? -eq 0 -a -n "$tmpfile" + if test $? -eq 0 && test -n "$tmpfile" then mv -- "$(git rev-parse --show-cdup)$tmpfile" "$3" else @@@ -262,7 -262,7 +262,7 @@@ merge_file () checkout_staged_file 2 "$MERGED" "$LOCAL" checkout_staged_file 3 "$MERGED" "$REMOTE" - if test -z "$local_mode" -o -z "$remote_mode" + if test -z "$local_mode" || test -z "$remote_mode" then echo "Deleted merge conflict for '$MERGED':" describe_file "$local_mode" "local" "$LOCAL" @@@ -283,7 -283,7 +283,7 @@@ echo "Normal merge conflict for '$MERGED':" describe_file "$local_mode" "local" "$LOCAL" describe_file "$remote_mode" "remote" "$REMOTE" - if "$prompt" = true + if test "$guessed_merge_tool" = true || test "$prompt" = true then printf "Hit return to start merge resolution tool (%s): " "$merge_tool" read ans || return 1 @@@ -321,12 -321,15 +321,16 @@@ return 0 } -prompt=$(git config --bool mergetool.prompt || echo true) +prompt=$(git config --bool mergetool.prompt) +guessed_merge_tool=false while test $# != 0 do case "$1" in + --tool-help=*) + TOOL_MODE=${1#--tool-help=} + show_tool_help + ;; --tool-help) show_tool_help ;; @@@ -378,16 -381,12 +382,19 @@@ prompt_after_failed_merge () done } + git_dir_init + require_work_tree + if test -z "$merge_tool" then - merge_tool=$(get_merge_tool "$merge_tool") || exit + # Check if a merge tool has been configured + merge_tool=$(get_configured_merge_tool) + # Try to guess an appropriate merge tool if no tool has been set. + if test -z "$merge_tool" + then + merge_tool=$(guess_merge_tool) || exit + guessed_merge_tool=true + fi fi merge_keep_backup="$(git config --bool mergetool.keepBackup || echo true)" merge_keep_temporaries="$(git config --bool mergetool.keepTemporaries || echo false)" diff --combined git-sh-setup.sh index 9447980330,3eb1b67838..d968760139 --- a/git-sh-setup.sh +++ b/git-sh-setup.sh @@@ -160,7 -160,7 +160,7 @@@ git_pager() else GIT_PAGER=cat fi - : ${LESS=-FRSX} + : ${LESS=-FRX} : ${LV=-c} export LESS LV @@@ -330,8 -330,7 +330,7 @@@ esa # Make sure we are in a valid repository of a vintage we understand, # if we require to be in a git repository. - if test -z "$NONGIT_OK" - then + git_dir_init () { GIT_DIR=$(git rev-parse --git-dir) || exit if [ -z "$SUBDIRECTORY_OK" ] then @@@ -346,6 -345,11 +345,11 @@@ exit 1 } : ${GIT_OBJECT_DIRECTORY="$GIT_DIR/objects"} + } + + if test -z "$NONGIT_OK" + then + git_dir_init fi peel_committish () {