tig icon indicating copy to clipboard operation
tig copied to clipboard

External diff viewer

Open tomaz opened this issue 11 years ago • 10 comments

Can't find a way to use external diff viewer (kaleideoscope for example). Am I missing something or is this not possible?

tomaz avatar Nov 01 '13 06:11 tomaz

There's no global option to open an external diff viewer. Would be a nice feature though.

What is possible today is to remap the key binding for opening a commit diff in Tig so that it calls a shell script that calls your diff viewer:

bind main Enter !/path/to/script %(commit)

If you already have it set up your external diff viewer in Git the above could probably be simplified. On Nov 1, 2013 2:11 AM, "tomaz" [email protected] wrote:

Can't find a way to use external diff viewer (kaleideoscope for example). Am I missing something or is this not possible?

— Reply to this email directly or view it on GitHubhttps://github.com/jonas/tig/issues/219 .

jonas avatar Nov 01 '13 12:11 jonas

Will try the workaround. The option would be very useful IMHO. External tools usually provide nicer visual representation than git diff. Plus having it open in another window simultaneously while writing commit message is big help. At least that's how I function.

I checked the source code and tried few things already, but it didn't work. Would probably need to spend more time with code to better understand. If you won't consider adding this in forseeable future, I can take another look if you can send me some tips that will guide me to proper direction. Especially if binding will not be enough.

On 1. nov. 2013, at 13:34, Jonas Fonseca [email protected] wrote:

There's no global option to open an external diff viewer. Would be a nice feature though.

What is possible today is to remap the key binding for opening a commit diff in Tig so that it calls a shell script that calls your diff viewer:

bind main Enter !/path/to/script %(commit)

If you already have it set up your external diff viewer in Git the above could probably be simplified.

tomaz avatar Nov 01 '13 17:11 tomaz

Is there any more information about setting up the binding? The example given by @jonas above appears to diff all changes for a commit. I'd like to diff a singe file externally, for example, from the status view.

jargv avatar Dec 09 '15 20:12 jargv

@jargv Untested but something like the following:

git difftool --tool vimdiff --no-prompt %(commit) %(file)

jonas avatar Jan 08 '16 13:01 jonas

I've made the following difftool bindings in .tigrc:

bind status <F4> !git difftool -y %(commit) %(file)
bind generic <F5> !git difftool -d --no-symlinks %(commit)

F4 - In status view shows the diff of the selected file F5 - Useful in both log view and status view to see all changed files at once using git's dir-diff

vitalybe avatar Mar 14 '16 14:03 vitalybe

I was playing around with some of the above solutions. They all compare a commit against the HEAD revision, whereas I want to compare against the previous revision. I tried using %(commit)~1 as an argument to the difftool command, but that's not parsed correctly to the external call.

I ended up creating a script, tig-difftool-helper.sh which tailors the arguments to difftool (simplified here):

#!/bin/bash
if [ -z "$2" ]; then
  git difftool -y "${1}" "${1}~1"  # diff against previous commit
else
  git difftool -y "${1}" "${1}~1" -- "$2"  # filebased diff against previous
fi

And these bindings in .tigrc:

# in diff view, diff against previous commit:
bind diff <F4> !tig-difftool-helper.sh %(commit) %(file)
# generic, diff commit against previous commit:
bind generic <F5> !tig-difftool-helper.sh %(commit)
# in status and stage view there's no commit: diff against HEAD (no need for helper):
bind status <F4> !git difftool -y -- %(file)
bind stage <F4> !git difftool -y -- %(file)

kmac avatar Jul 20 '18 14:07 kmac

The external script shouldn’t be necessary, you will find some hints in issue #26.

koutcher avatar Jul 20 '18 19:07 koutcher

@kmac Here is what I did to achieve the same:

# compare commit in log view with its parent per http://stackoverflow.com/questions/436362/shorthand-for-diff-of-git-commit-with-its-parent
bind main <F4> !git difftool -d %(commit)^!

vitalybe avatar Jul 21 '18 19:07 vitalybe

@jonas. Can we support difftastic? It supports syntax tree diff which can be useful for those languages that have auto formatter (e.g. rust lang).

I set it as git external diff, and then git diff --ext-diff works fine. But when running tig --ext-diff, it displayed without any color/highlight.

liming01 avatar Sep 11 '23 16:09 liming01

Duplicated issue? See Issue https://github.com/jonas/tig/issues/542. Also there is this comment that might be interested for you, although it is using delta instead of difftastic.

pablospe avatar Sep 21 '23 13:09 pablospe