Merge branch 'da/mergetool-tool-help'
authorJunio C Hamano <gitster@pobox.com>
Tue, 21 Oct 2014 20:28:37 +0000 (13:28 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 21 Oct 2014 20:28:37 +0000 (13:28 -0700)
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

1  2 
git-mergetool.sh
git-sh-setup.sh
diff --combined git-mergetool.sh
index 96a61ba6f470d7634552a42547de57f63fae8d81,821253e3688ca3fdc9091334984b5125a15abc33..ec644d542d9754fa09ac7fb1b0f1f932a9bedbed
  
  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"
        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
        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 9447980330ce7892757f9b11fa45cfeb3e6fcb34,3eb1b678386f7e9ed569dd8b11d78c4c508bbadc..d968760139b0e7b9219a1602a2e646a3ed398136
@@@ -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
                exit 1
        }
        : ${GIT_OBJECT_DIRECTORY="$GIT_DIR/objects"}
+ }
+ if test -z "$NONGIT_OK"
+ then
+       git_dir_init
  fi
  
  peel_committish () {