Skip to contentSkip to conversation

mergetool: support setting path to tool as config var mergetool.<tool>.path

PATCH In review Steffen Prohaska 3 participants 7 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mergetool: support setting path to tool as config var mergetool.<tool>.path

This commit adds a mechanism to provide absolute paths to the external programs called by 'git mergetool'. A path can be specified in the configuation variable mergetool.<tool>.path. The configuration variable is similar to how we name branches and remotes. It is extensible if we need to specify more details about a tool.

The mechanism added by this patch is orthogonal to the existing merge.tool configuration variable:
1) merge.tool selects a tool from a list of known programs for which command line arguments and the mechanism for returning merge results is know.
2) mergetool.<tool>.path provides details on how to locate the selected tool in the filesystem. Paths for several tools can be configured simultaneously.

The mechanism is especially useful on Windows, where external programs are unlikely to be in PATH.

---
 Documentation/git-mergetool.txt |    6 ++
 git-mergetool.sh                |   97 +++++++++++++++++++++-----------------
 2 files changed, 60 insertions(+), 43 deletions(-)

This updated patch is based on the the comments and suggestions by Theodor, Frank, and Johannes.

Steffen

Documentation/git-mergetool.txt +6 -0
index 6c32c6d..17a33e7 100644
@@ -31,6 +31,12 @@ If a merge resolution program is not specified, 'git mergetool'
 will use the configuration variable merge.tool.  If the
 configuration variable merge.tool is not set, 'git mergetool'
 will pick a suitable default.
++
+You can explicitly provide a full path to the tool by setting the
+configuration variable mergetool.<tool>.path. For example, you
+can configure the absolute path to kdiff3 by setting
+mergetool.kdiff3.path. Otherise, 'git mergetool' assumes the tool
+is available in PATH.
 
 Author
 ------
git-mergetool.sh +54 -43

174 lines not on this page · raw message

Signature · 1 line
1.5.3.3.127.g40d17
#1 lore raw

Hi,

Quoted 5 lines · Steffen Prohaska

This commit adds a mechanism to provide absolute paths to the external programs called by 'git mergetool'. A path can be specified in the configuation variable mergetool.<tool>.path. The configuration variable is similar to how we name branches and remotes. It is extensible if we need to specify more details about a tool.

Okay, let's step back a bit.

What does mergetool do? It calls different merge helpers, each with its own convention how to call it. For example, tkdiff is called either as

		tkdiff -a "$BASE" -o "$path" -- "$LOCAL" "$REMOTE"

or as

		tkdiff -o "$path" -- "$LOCAL" "$REMOTE"

depending if there is a base or not. Another example is gvimdiff:

		gvimdiff -f -- "$LOCAL" "$path" "$REMOTE"

which seems not to care if there is a base.

Now, would it not be much better if we had a way to specify the tool and the convention indepentently? Like

merge.tkdiff.path = C:\bla\blub\wish.exe C:\blub\bleh\tkdiff.tcl merge.tkdiff.options = -o %p -- %l %r merge.tkdiff.optionsWithBase = -a %b -o %p -- %l %r

and have defaults for the tools we have in git-mergetool.sh _already_?

Ciao,
Dscho

#2 lore raw
Quoted 27 lines · Johannes Schindelin

Hi,

Quoted 5 lines · Steffen Prohaska

This commit adds a mechanism to provide absolute paths to the external programs called by 'git mergetool'. A path can be specified in the configuation variable mergetool.<tool>.path. The configuration variable is similar to how we name branches and remotes. It is extensible if we need to specify more details about a tool.

Okay, let's step back a bit.

What does mergetool do? It calls different merge helpers, each with its own convention how to call it. For example, tkdiff is called either as

		tkdiff -a "$BASE" -o "$path" -- "$LOCAL" "$REMOTE"

or as

		tkdiff -o "$path" -- "$LOCAL" "$REMOTE"

depending if there is a base or not. Another example is gvimdiff:

		gvimdiff -f -- "$LOCAL" "$path" "$REMOTE"

which seems not to care if there is a base.

Quoted 8 lines

Now, would it not be much better if we had a way to specify the tool and the convention indepentently? Like

merge.tkdiff.path = C:\bla\blub\wish.exe C:\blub\bleh\tkdiff.tcl merge.tkdiff.options = -o %p -- %l %r merge.tkdiff.optionsWithBase = -a %b -o %p -- %l %r

and have defaults for the tools we have in git-mergetool.sh _already_?

If you provide a generic mechanism to call an external tool, there's no need to name the tool. A single mechanism (let's call it external) would be sufficient, like

mergetool.external.path = c:\any\path\merge.exe mergetool.external.arg2way = %l %r --merge2 --to=%p mergetool.external.arg3way = %b %l %r --merge3 --to=%p

But this places the burdon on the user to figure out the command line syntax and specify it correctly using git-config. Things like proper escaping may be a hassel.

The solution I'm proposing is more user-friendly. Only the information that is hard to figure out automatically and is easy to provide by the user is asked for. The user only needs to tell the path to the executable.

git-mergetool 'knows' about the correct command line syntax. There's no need to ask the user. The command line syntax is fixed and know. No option here. "git mergetool" could, for example, know that a certain tool just doesn't support 3-way.

And the code of git-mergetool is also quite easy. The only input validation that is needed is to check if mergetool.<tool>.path points to a valid executable. If we provide a complex syntax for specifying command line options we may have to do a lot more of input validation and processing.

I strongly favor my solution of including the command line syntax in git-mergetool, and only ask the user for the path. I'm not against a generic mechanism to configure any tool. However, I do not plan to implement it.

If someone plans to develop a generic mechanism I see two options:
1) What's explained above.
2) _Define_ the parameters passed to the external command and ask the user to write a wrapper script to call his tool of choice. Similar to
what
GIT_EXTERNAL_DIFF does. Wrapper scripts would go to contrib/.

Both solutions would require more work from the user than needed.

Steffen

#3 lore raw

Hi,

Quoted 41 lines · Steffen Prohaska
Quoted 26 lines · Johannes Schindelin
Quoted 6 lines · Steffen Prohaska

This commit adds a mechanism to provide absolute paths to the external programs called by 'git mergetool'. A path can be specified in the configuation variable mergetool.<tool>.path. The configuration variable is similar to how we name branches and remotes. It is extensible if we need to specify more details about a tool.

Okay, let's step back a bit.

What does mergetool do? It calls different merge helpers, each with its own convention how to call it. For example, tkdiff is called either as

		tkdiff -a "$BASE" -o "$path" -- "$LOCAL" "$REMOTE"

or as

		tkdiff -o "$path" -- "$LOCAL" "$REMOTE"

depending if there is a base or not. Another example is gvimdiff:

		gvimdiff -f -- "$LOCAL" "$path" "$REMOTE"

which seems not to care if there is a base.

Quoted 8 lines

Now, would it not be much better if we had a way to specify the tool and the convention indepentently? Like

merge.tkdiff.path = C:\bla\blub\wish.exe C:\blub\bleh\tkdiff.tcl merge.tkdiff.options = -o %p -- %l %r merge.tkdiff.optionsWithBase = -a %b -o %p -- %l %r

and have defaults for the tools we have in git-mergetool.sh _already_?

If you provide a generic mechanism to call an external tool, there's no need to name the tool. A single mechanism (let's call it external) would be sufficient, like

Quoted 6 lines

mergetool.external.path = c:\any\path\merge.exe mergetool.external.arg2way = %l %r --merge2 --to=%p mergetool.external.arg3way = %b %l %r --merge3 --to=%p

But this places the burdon on the user to figure out the command line syntax and specify it correctly using git-config.

Guess why I did not want to have a single mechanism. I did _not_ propose to place the burden on the user to figure out the command line.

Besides, I do not want to do away with the automatic detection of the tool, which _implies_ having a list of defaults for the command line syntax, which in turn _commands_ having the name instead of "external".

While your solution is an obvious short term fix, I maintain that my proposal is the Right Thing in the long run.

Ciao,
Dscho

#4 lore raw
Quoted 55 lines · Johannes Schindelin

Hi,

Quoted 41 lines · Steffen Prohaska
Quoted 26 lines · Johannes Schindelin
Quoted 6 lines · Steffen Prohaska

This commit adds a mechanism to provide absolute paths to the external programs called by 'git mergetool'. A path can be specified in the configuation variable mergetool.<tool>.path. The configuration variable is similar to how we name branches and remotes. It is extensible if we need to specify more details about a tool.

Okay, let's step back a bit.

What does mergetool do? It calls different merge helpers, each with its own convention how to call it. For example, tkdiff is called either as

		tkdiff -a "$BASE" -o "$path" -- "$LOCAL" "$REMOTE"

or as

		tkdiff -o "$path" -- "$LOCAL" "$REMOTE"

depending if there is a base or not. Another example is gvimdiff:

		gvimdiff -f -- "$LOCAL" "$path" "$REMOTE"

which seems not to care if there is a base.

Quoted 8 lines

Now, would it not be much better if we had a way to specify the tool and the convention indepentently? Like

merge.tkdiff.path = C:\bla\blub\wish.exe C:\blub\bleh\tkdiff.tcl merge.tkdiff.options = -o %p -- %l %r merge.tkdiff.optionsWithBase = -a %b -o %p -- %l %r

and have defaults for the tools we have in git-mergetool.sh _already_?

If you provide a generic mechanism to call an external tool, there's no need to name the tool. A single mechanism (let's call it external) would be sufficient, like

Quoted 6 lines

mergetool.external.path = c:\any\path\merge.exe mergetool.external.arg2way = %l %r --merge2 --to=%p mergetool.external.arg3way = %b %l %r --merge3 --to=%p

But this places the burdon on the user to figure out the command line syntax and specify it correctly using git-config.

Guess why I did not want to have a single mechanism. I did _not_ propose to place the burden on the user to figure out the command line.

Quoted 6 lines

Besides, I do not want to do away with the automatic detection of the tool, which _implies_ having a list of defaults for the command line syntax, which in turn _commands_ having the name instead of "external".

While your solution is an obvious short term fix, I maintain that my proposal is the Right Thing in the long run.

I did not intend to replace everything with an external mechanism. What I wanted to say is the following: If you add a generic mechanism in addition to the known tools it is sufficient to add a single generic mechanism called 'external'. You could then choose from the list of known tools or you could choose 'external' and provide everything needed as described above.

Steffen

#5 lore raw
In reply to Steffen Prohaska
Quoted 3 lines · Steffen Prohaska

This commit adds a mechanism to provide absolute paths to the external programs called by 'git mergetool'. A path can be specified in the configuation variable mergetool.<tool>.path.

Any news on this patch?
Will you apply it (or recommend that Junio does)?

Steffen

#6 lore raw
Quoted 7 lines · Steffen Prohaska
Quoted 4 lines

This commit adds a mechanism to provide absolute paths to the external programs called by 'git mergetool'. A path can be specified in the configuation variable mergetool.<tool>.path.

Any news on this patch?
Will you apply it (or recommend that Junio does)?

Hmm, for some reason I never received the v2 version of the patch. I see Johannes' comments to it, but not the original e-mail for some reason. It doesn't seem to be in the spam filter, so I'm not sure what happened.

Can you resend, please? Thanks!!

- Ted