logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

git-difftool--helper (2660B)


  1. #!/bin/sh
  2. # git-difftool--helper is a GIT_EXTERNAL_DIFF-compatible diff tool launcher.
  3. # This script is typically launched by using the 'git difftool'
  4. # convenience command.
  5. #
  6. # Copyright (c) 2009, 2010 David Aguilar
  7. TOOL_MODE=diff
  8. . git-mergetool--lib
  9. # difftool.prompt controls the default prompt/no-prompt behavior
  10. # and is overridden with $GIT_DIFFTOOL*_PROMPT.
  11. should_prompt () {
  12. prompt_merge=$(git config --bool mergetool.prompt || echo true)
  13. prompt=$(git config --bool difftool.prompt || echo $prompt_merge)
  14. if test "$prompt" = true
  15. then
  16. test -z "$GIT_DIFFTOOL_NO_PROMPT"
  17. else
  18. test -n "$GIT_DIFFTOOL_PROMPT"
  19. fi
  20. }
  21. # Indicates that --extcmd=... was specified
  22. use_ext_cmd () {
  23. test -n "$GIT_DIFFTOOL_EXTCMD"
  24. }
  25. launch_merge_tool () {
  26. # Merged is the filename as it appears in the work tree
  27. # Local is the contents of a/filename
  28. # Remote is the contents of b/filename
  29. # Custom merge tool commands might use $BASE so we provide it
  30. MERGED="$1"
  31. LOCAL="$2"
  32. REMOTE="$3"
  33. BASE="$1"
  34. # $LOCAL and $REMOTE are temporary files so prompt
  35. # the user with the real $MERGED name before launching $merge_tool.
  36. if should_prompt
  37. then
  38. printf "\nViewing (%s/%s): '%s'\n" "$GIT_DIFF_PATH_COUNTER" \
  39. "$GIT_DIFF_PATH_TOTAL" "$MERGED"
  40. if use_ext_cmd
  41. then
  42. printf "Launch '%s' [Y/n]? " \
  43. "$GIT_DIFFTOOL_EXTCMD"
  44. else
  45. printf "Launch '%s' [Y/n]? " "$merge_tool"
  46. fi
  47. read ans || return
  48. if test "$ans" = n
  49. then
  50. return
  51. fi
  52. fi
  53. if use_ext_cmd
  54. then
  55. export BASE
  56. eval $GIT_DIFFTOOL_EXTCMD '"$LOCAL"' '"$REMOTE"'
  57. else
  58. initialize_merge_tool "$merge_tool" || exit 1
  59. run_merge_tool "$merge_tool"
  60. fi
  61. }
  62. if ! use_ext_cmd
  63. then
  64. if test -n "$GIT_DIFF_TOOL"
  65. then
  66. merge_tool="$GIT_DIFF_TOOL"
  67. else
  68. merge_tool="$(get_merge_tool)"
  69. subshell_exit_status=$?
  70. if test $subshell_exit_status -gt 1
  71. then
  72. exit $subshell_exit_status
  73. fi
  74. fi
  75. fi
  76. if test -n "$GIT_DIFFTOOL_DIRDIFF"
  77. then
  78. LOCAL="$1"
  79. REMOTE="$2"
  80. initialize_merge_tool "$merge_tool" || exit 1
  81. run_merge_tool "$merge_tool" false
  82. status=$?
  83. if test $status -ge 126
  84. then
  85. # Command not found (127), not executable (126) or
  86. # exited via a signal (>= 128).
  87. exit $status
  88. fi
  89. if test "$GIT_DIFFTOOL_TRUST_EXIT_CODE" = true
  90. then
  91. exit $status
  92. fi
  93. else
  94. # Launch the merge tool on each path provided by 'git diff'
  95. while test $# -gt 6
  96. do
  97. launch_merge_tool "$1" "$2" "$5"
  98. status=$?
  99. if test $status -ge 126
  100. then
  101. # Command not found (127), not executable (126) or
  102. # exited via a signal (>= 128).
  103. exit $status
  104. fi
  105. if test "$status" != 0 &&
  106. test "$GIT_DIFFTOOL_TRUST_EXIT_CODE" = true
  107. then
  108. exit $status
  109. fi
  110. shift 7
  111. done
  112. fi
  113. exit 0