[PATCH 2/2] mergetools: fail if display needed but not present

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Prior to this commit, if 'git mergetool' or 'git difftool' were run in a
terminal-only session, they might still try to open a tool that required
a windowed environment.

This commit teaches 'git-mergetool--lib.sh' to test for the presence of
a display prior to opening tools that require one.

NOTE: The DISPLAY variable is not set in msysgit or cygwin Git.  In the
absence of that variable, the script assumes that a window environment
is always available when running msysgit or cygwin.

Signed-off-by: Tim Henigan <tim.henigan@xxxxxxxxx>
---

Only 2 of the current diff/merge tools (vim and emerge) can operate
without a display.

The assumption that a display is always available on msys or cygwin is
probably not optimal.  However, I was not able to find a better work-
around.  It also matches the previous behavior that did not test for
the DISPLAY prior to opening the tool.


 git-mergetool--lib.sh |   23 +++++++++++++++++++++++
 mergetools/defaults   |    4 ++++
 mergetools/emerge     |    4 ++++
 mergetools/vim        |    4 ++++
 4 files changed, 35 insertions(+)

diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh
index 89b16dc..75c8b11 100644
--- a/git-mergetool--lib.sh
+++ b/git-mergetool--lib.sh
@@ -12,6 +12,19 @@ translate_merge_tool_path () {
 	echo "$1"
 }
 
+display_available() {
+	if test -n "$DISPLAY"
+	then
+		return 0
+	fi
+
+	case "$(uname -s)" in
+	MINGW*|CYGWIN*) return 0; break;;
+	esac
+
+	return 1
+}
+
 check_unchanged () {
 	if test "$MERGED" -nt "$BACKUP"
 	then
@@ -190,6 +203,16 @@ get_merge_tool_path () {
 			 "'$merge_tool_path'"
 		exit 1
 	fi
+	if ! display_available
+	then
+		if tool_requires_display
+		then
+			echo >&2 "The $TOOL_MODE tool $merge_tool cannot"\
+			"be run from a terminal-only session.  A window"\
+			"environment is required."
+			exit 1
+		fi
+	fi
 	echo "$merge_tool_path"
 }
 
diff --git a/mergetools/defaults b/mergetools/defaults
index 1d8f2a3..f150227 100644
--- a/mergetools/defaults
+++ b/mergetools/defaults
@@ -7,6 +7,10 @@ can_diff () {
 	return 0
 }
 
+tool_requires_display() {
+	return 0
+}
+
 diff_cmd () {
 	merge_tool_cmd="$(get_merge_tool_cmd "$1")"
 	if test -z "$merge_tool_cmd"
diff --git a/mergetools/emerge b/mergetools/emerge
index f96d9e5..c7eb80b 100644
--- a/mergetools/emerge
+++ b/mergetools/emerge
@@ -1,3 +1,7 @@
+tool_requires_display () {
+	return 1
+}
+
 diff_cmd () {
 	"$merge_tool_path" -f emerge-files-command "$LOCAL" "$REMOTE"
 }
diff --git a/mergetools/vim b/mergetools/vim
index 6817708..ffd9fd6 100644
--- a/mergetools/vim
+++ b/mergetools/vim
@@ -1,3 +1,7 @@
+tool_requires_display () {
+	return 1
+}
+
 diff_cmd () {
 	"$merge_tool_path" -R -f -d \
 		-c 'wincmd l' -c 'cd $GIT_PREFIX' "$LOCAL" "$REMOTE"
-- 
1.7.10.rc2.21.g8cb1a

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]