git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/8] sh-tools: add a git-sh-tools shell helper script

From
David Aguilar <davvid@gmail.com>
Date
Mar 30, 2009, 05:03 UTC
Message-ID
<1238389428-69328-4-git-send-email-davvid@gmail.com>
In-Reply-To
<1238389428-69328-3-git-send-email-davvid@gmail.com>
git-sh-tools holds functions common to the git-*tool commands.
Signed-off-by: David Aguilar <davvid@gmail.com>
---
 .gitignore                     |    1 +
 Documentation/git-sh-tools.txt |   49 +++++++++++++++++++++++++++++++++++++++
 Makefile                       |    1 +
 command-list.txt               |    1 +
 git-sh-tools.sh                |   50 ++++++++++++++++++++++++++++++++++++++++
 5 files changed, 102 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/git-sh-tools.txt
 create mode 100644 git-sh-tools.sh
diff --git a/.gitignore b/.gitignore
index 966c886..cecf77e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -114,6 +114,7 @@ git-rm
 git-send-email
 git-send-pack
 git-sh-setup
+git-sh-tools
 git-shell
 git-shortlog
 git-show
diff --git a/Documentation/git-sh-tools.txt b/Documentation/git-sh-tools.txt
new file mode 100644
index 0000000..055a10c
--- /dev/null
+++ b/Documentation/git-sh-tools.txt
@@ -0,0 +1,49 @@
+git-sh-tool(1)
+==============
+
+NAME
+----
+git-sh-tools - Common git *tool shell script functions
+
+SYNOPSIS
+--------
+'. "$(git --exec-path)/git-sh-tools"'
+
+DESCRIPTION
+-----------
+
+This is not a command the end user would want to run.  Ever.
+This documentation is meant for people who are studying the
+Porcelain-ish scripts and/or are writing new ones.
+
+The 'git-sh-tools' scriptlet is designed to be sourced (using
+`.`) by other shell scripts to set up some functions for
+working with git merge/diff tools.
+
+Before sourcing it, your script should set up a few variables;
+`TOOL_MODE` is used to define the operation mode for various
+functions.  'diff' and 'merge' are valid values.
+
+FUNCTIONS
+---------
+valid_tool::
+	verifies that the specified merge tool is properly setup.
+
+valid_custom_tool::
+	verifies that a '(diff|merge)tool.<tool>.cmd' configuration exists.
+
+init_merge_tool_path::
+	sets up `$merge_tool_path` according to '(diff|merge)tool.<tool>.path'
+	configurations.
+
+Author
+------
+Written by David Aguilar <davvid@gmail.com>
+
+Documentation
+--------------
+Documentation by David Aguilar and the git-list <git@vger.kernel.org>.
+
+GIT
+---
+Part of the linkgit:git[1] suite
diff --git a/Makefile b/Makefile
index d77fd71..3b7c20f 100644
--- a/Makefile
+++ b/Makefile
@@ -292,6 +292,7 @@ SCRIPT_SH += git-rebase.sh
 SCRIPT_SH += git-repack.sh
 SCRIPT_SH += git-request-pull.sh
 SCRIPT_SH += git-sh-setup.sh
+SCRIPT_SH += git-sh-tools.sh
 SCRIPT_SH += git-stash.sh
 SCRIPT_SH += git-submodule.sh
 SCRIPT_SH += git-web--browse.sh
diff --git a/command-list.txt b/command-list.txt
index fb03a2e..c3b6c87 100644
--- a/command-list.txt
+++ b/command-list.txt
@@ -109,6 +109,7 @@ git-show-branch                         ancillaryinterrogators
 git-show-index                          plumbinginterrogators
 git-show-ref                            plumbinginterrogators
 git-sh-setup                            purehelpers
+git-sh-tools                            purehelpers
 git-stash                               mainporcelain
 git-status                              mainporcelain common
 git-stripspace                          purehelpers
diff --git a/git-sh-tools.sh b/git-sh-tools.sh
new file mode 100644
index 0000000..234bac7
--- /dev/null
+++ b/git-sh-tools.sh
@@ -0,0 +1,50 @@
+# Verifies that the chosen merge tool is properly setup.
+# Built-in merge tools are always valid.
+valid_tool() {
+	case "$1" in
+	kdiff3 | kompare | tkdiff | xxdiff | meld | opendiff | emerge | vimdiff | gvimdiff | ecmerge)
+		;; # happy
+	*)
+		if ! valid_custom_tool "$1"; then
+			return 1
+		fi
+		;;
+	esac
+}
+
+# Verifies that (difftool|mergetool).<tool>.cmd exists
+# Requires $TOOL_MODE to be set.
+valid_custom_tool() {
+	if test "$TOOL_MODE" = "diff"; then
+		merge_tool_cmd="$(git config difftool.$1.cmd)"
+		test -z "$merge_tool_cmd" &&
+		merge_tool_cmd="$(git config mergetool.$1.cmd)"
+		test -n "$merge_tool_cmd"
+	elif test "$TOOL_MODE" = "merge"; then
+		merge_tool_cmd="$(git config mergetool.$1.cmd)"
+		test -n "$merge_tool_cmd"
+	fi
+}
+
+
+# Set up $merge_tool_path for (diff|merge)tool.<tool>.path configurations
+init_merge_tool_path() {
+	if test "$TOOL_MODE" = "diff"; then
+		merge_tool_path=$(git config difftool."$1".path)
+		test -z "$merge_tool_path" &&
+		merge_tool_path=$(git config mergetool."$1".path)
+	elif test "$TOOL_MODE" = "merge"; then
+		merge_tool_path=$(git config mergetool."$1".path)
+	fi
+
+	if test -z "$merge_tool_path" ; then
+		case "$1" in
+			emerge)
+				merge_tool_path=emacs
+				;;
+			*)
+				merge_tool_path=$1
+				;;
+		esac
+	fi
+}
-- 
1.6.1.3
Previous: David AguilarNext: David Aguilar
Message 4 of 19 in “(unknown)”
  1. David AguilarMar 30, 2009
  2. 1/8 mergetool: use tabs consistentlyDavid Aguilar, Mar 30, 2009
  3. 2/8 mergetool: use $( ... ) instead of `backticks`David Aguilar, Mar 30, 2009
  4. 3/8 sh-tools: add a git-sh-tools shell helper scriptDavid Aguilar, Mar 30, 2009
  5. 4/8 mergetool: refactor git-mergetool to use git-sh-toolsDavid Aguilar, Mar 30, 2009
  6. 5/8 difftool: refactor git-difftool to use git-sh-toolsDavid Aguilar, Mar 30, 2009
  7. 6/8 sh-tools: add a run_merge_tool functionDavid Aguilar, Mar 30, 2009
  8. 7/8 mergetool: refactor git-mergetool to use run_merge_toolDavid Aguilar, Mar 30, 2009
  9. 8/8 difftool: refactor git-difftool-helper to use run_merge_toolDavid Aguilar, Mar 30, 2009
  10. Markus HeidelbergMar 30, 2009
  11. Markus HeidelbergMar 30, 2009
  12. David AguilarMar 30, 2009
  13. Junio C HamanoMar 30, 2009
  14. David AguilarMar 30, 2009
  15. Charles BaileyMar 30, 2009
  16. David AguilarMar 31, 2009
  17. Junio C HamanoApr 1, 2009
  18. Markus HeidelbergMar 30, 2009
  19. Junio C HamanoMar 30, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.