internal/cmd: git_wrapper: wrap difftool and mergetool - #181
Merged
Conversation
Both take diff's pathspecs, so a numeric shortcut should expand the same way it does for `diff` today. Currently `git difftool 1` reaches git verbatim and fails with "ambiguous argument '1'", while `git diff 1` works -- a surprising inconsistency, since the two commands take the same arguments. mergetool is included because scmpuff numbers conflicted files during a merge, which is exactly when selecting one by number is most useful. This is the request in mroth#83, where the workaround given was to use $e1 directly. Neither command has stash's ambiguity: for `stash pop 1` a number is a stash index, but difftool and mergetool only ever take paths. The new testscripts invoke zsh with -f. zsh reads /etc/zshenv for every shell, including non-interactive ones, and on some systems (nix-darwin, for one) that file prepends profile directories to PATH. That shadows the scmpuff binary under test with an installed copy, so the zsh leg silently exercises the wrong binary. Existing wrapper tests do not notice, because every subcommand they cover is present in both versions; a test for a newly added subcommand is the first that can detect the substitution.
Owner
|
@marcuslannister this looks great! I wasn't aware of the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #83.
git diff 1expands the shortcut, butgit difftool 1fails withfatal: ambiguous argument '1'. The two commands take the same pathspecarguments, so the difference is surprising.
difftoolsimply is not in thewrapper's dispatch list.
This adds
difftoolandmergetoolto the--relativebranch.mergetoolis included because scmpuff numbers conflicted files during amerge — precisely when picking one by number is most useful. That is the
request in #83, where the suggested workaround was to use
$e1directly.Neither command has the ambiguity that makes
stasha special case in #160:for
stash pop 1a number is a stash index, butdifftoolandmergetoolonly ever take paths.
Tests
Two testscripts, covering bash, zsh and fish:
command-shell-wrapper-difftool-by-number.txtar— uses--extcmd=echosono real diff tool is needed, and asserts the tool receives the relative
worktree path.
command-shell-wrapper-mergetool-by-number.txtar— builds a real mergeconflict and resolves it with a stub tool, so nothing interactive runs.
Note on
zsh -fThe new scripts invoke zsh with
-f, which the existing wrapper tests do not.zsh reads
/etc/zshenvfor every shell, including non-interactive ones. Onsome systems that file prepends profile directories to
PATH— nix-darwindoes this, and I hit it locally. The effect is that the zsh leg silently runs
an installed scmpuff instead of the binary under test.
The current wrapper tests cannot detect this, because every subcommand they
cover (
add,reset,restore) exists in both the installed and theunder-test version, so the results agree either way. A test for a newly added
subcommand is the first one that can catch the substitution — which is how I
found it.
-fmakes the zsh leg hermetic.Happy to drop the
-fif you would rather keep the scripts uniform, or toapply it to the existing scripts in a separate change.