Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for diff-highlight #313

Closed
dwijnand opened this issue Jul 21, 2014 · 29 comments
Closed

Add support for diff-highlight #313

dwijnand opened this issue Jul 21, 2014 · 29 comments
Labels

Comments

@dwijnand
Copy link

I would be really nice if tig supported diff-highlight.

@jonas jonas added the component:diff Diff UI label Sep 12, 2014
@dwijnand
Copy link
Author

oh how I miss not having this..

@dwijnand
Copy link
Author

dwijnand commented Mar 4, 2015

So.. I was wondering- how viable is including this? Is it possible to "shell out to perl" for this?

I've negligible experience in C, so I could use any help I can get in implementing this.

Thanks

@jonas
Copy link
Owner

jonas commented Mar 6, 2015 via email

@danielmanesku
Copy link

It would be really nice to have this feature (or even better diff-so-fancy), it saves a lot of time.
It also got some light from git team: https://github.com/blog/2188-git-2-9-has-been-released

@tqmz
Copy link

tqmz commented Sep 19, 2016

Would be nice indeed.

@wikimatze
Copy link

+1 for that feature

@jonas
Copy link
Owner

jonas commented Nov 7, 2016

screen shot 2016-11-07 at 00 29 31

@dwijnand
Copy link
Author

dwijnand commented Nov 7, 2016

What am I doing wrong that I see the following?

image

@jonas
Copy link
Owner

jonas commented Nov 7, 2016

How did you configure it? First of all I assume you are using Git's diff-highlight and not the fancy one?

09:17:19 /opt/tig#master > head $(which diff-highlight)
#!/usr/bin/perl

use 5.008;
use warnings FATAL => 'all';
use strict;

# Highlight by reversing foreground and background. You could do
# other things like bold or underline if you prefer.
my @OLD_HIGHLIGHT = (
    color_config('color.diff-highlight.oldnormal'),
09:17:33 /opt/tig#master > grep diff-highlight ~/.tigrc
set diff-highlight = true

Right now it only understands the standout terminal escape codes used by an "unconfigured" diff-highlight so did you configure anything under color.diff-highlight, i.e. what is the output of git config -l | grep diff-highlight? I might have to set GIT_CONFIG to remove such settings.

@dwijnand
Copy link
Author

dwijnand commented Nov 7, 2016

yeah I seem to have configured things under color.diff-highlight:

$ git config -l | grep diff-highlight
color.diff-highlight.oldnormal=red bold
color.diff-highlight.oldhighlight=red bold 52
color.diff-highlight.newnormal=green bold
color.diff-highlight.newhighlight=green bold 22
core.pager=diff-highlight | less -$LESS -F -x1,5 -X
interactive.difffilter=diff-highlight

[edit]

And I'm using git's diff-highlight and configuring .tigrc with true

jonas added a commit that referenced this issue Nov 7, 2016
Set environment to `GIT_CONFIG=/dev/null` to avoid that diff-highlight
loads custom configuration.

Refs #313
@jonas
Copy link
Owner

jonas commented Nov 7, 2016

@dwijnand OK, thanks, reproduced. I am new to diff-highlight so it's great to learn some tricks. I pushed a new commit to fix this so that it works without support for colors. Will add tests for this when I have some time.

Implementing full support for terminal color escape codes would be nice but I think it would be better to support git's porcelain diff format which would open the doors to have split diff view, color words etc.

@dwijnand
Copy link
Author

dwijnand commented Nov 7, 2016

@jonas thanks!

@gweodoo
Copy link

gweodoo commented Nov 8, 2016

@jonas I have some trouble with your awesome diff-highlight feature.
I'm building tig from master branch (dfa26fd) and also git from master branch (be5a750 --> 2.11.0-rc0+).
I'm enabling the capability from .gitconfig file: [tig] diff-highlight = true

But I have this kind of weird stuff in the diff view:
tig

As you mentioned, I've checked that i'm using Git's diff-highlight without any configuration.
I've also tried with an older version of git and specifying the option in .gitrc directly instead of .gitconfig, but none of them solve my issue.

Do you have any idea ?
Thanks.

@jonas
Copy link
Owner

jonas commented Nov 8, 2016

@gweodoo Do you have the diff-highlight script in your PATH?

dtwlin added a commit to dtwlin/tig that referenced this issue Nov 9, 2016
Fix issue with diff-highlight that the env variable is not null terminated

Refs jonas#313

Signed-off-by: David Lin <dtwlin@google.com>
jonas pushed a commit that referenced this issue Nov 9, 2016
Fix issue with diff-highlight that the env variable is not null terminated

Refs #313

Signed-off-by: David Lin <dtwlin@google.com>
Signed-off-by: Jonas Fonseca <jonas.fonseca@gmail.com>
@jonas
Copy link
Owner

jonas commented Nov 9, 2016

@gweodoo I think (hope) that @dtwlin just fixed the issue you reported.

@tqmz
Copy link

tqmz commented Nov 10, 2016

Confirming this works nicely. Thanks so much!

(Revision: e59bec5, tigrc: set diff-highlight = true with diff-highlight in $PATH.)

@Liooo
Copy link

Liooo commented Nov 20, 2016

Can we use diff-so-fancy now?

@jonas
Copy link
Owner

jonas commented Nov 20, 2016

@Liooo No, not yet. With the infra put in place it should be doable. Do you mind creating a ticket for this?

@Liooo
Copy link

Liooo commented Nov 20, 2016

@jonas of course not!

.. DONE: #542

@danielmanesku
Copy link

I can confirm that this works in tig 2.2.1, but only when used directly from terminal (iTerm2 for instance).
When I am within tmux (2.2), the pieces are not highlighted. Tested with empty tmux.conf, and the issue still reproduces. Does anybody have it working within tmux?

@jonas
Copy link
Owner

jonas commented Jan 4, 2017 via email

@danielmanesku
Copy link

Issue #559 created.
Somehow I got the feeling that everyone is using either tmux or screen, but seems that I was wrong.

@kadrach
Copy link

kadrach commented Feb 21, 2017

@danielmanesku No idea how I'd go about troubleshooting it, but it works perfectly well in tmux for me.

@gweodoo
Copy link

gweodoo commented Mar 24, 2017

@jonas I'm sorry, I'm quite a bit late to respond (almost 5 months)
Indeed, with the fix you mentioned, everything goes well now !
tig being updated automatically twice a week with the master branch, I forgot to check for the fix (and I think Github notification went to /dev/null).

Thanks !

@mapad
Copy link

mapad commented Aug 9, 2017

For those on OSX who installed tig with the HomeBrew command 'brew install tig', somehow this won't work. You need to compile from sources and install before git through 'brew install git', in order to not use git default installed version.

@keimlink
Copy link

keimlink commented Oct 5, 2018

Works on macOS after brew upgrade tig, but I had to remove the default configuration in /usr/local/etc/tigrc so that the new default values are used. Otherwise the diff doesn't use the right colors, because they we not defined previously.

@frouo
Copy link

frouo commented Mar 5, 2021

What is the best / easiest way to get diff-highlight installed on macOS? For the moment I have git installed though xcode-install (because I am iOS developer). I understand I have to install git via brew install git but I would rather not have 2 versions of git on my mac.

Thank you 🙏🏻

@koutcher
Copy link
Collaborator

koutcher commented Mar 5, 2021

Installing git via brew install git just to get diff-highlight would be a little overkill. If the Xcode version of git doesn't come with the contrib directory, just grab the diff-highlight script from /usr/local/opt/git/share/git-core/contrib/diff-highlight on another machine and put it somewhere in your PATH. If you don't have access to another machine, https://raw.githubusercontent.com/git/git/3dbfe2b8ae94cbdae5f3d32581aedaa5510fdc87/contrib/diff-highlight/diff-highlight should be good enough (it was the version before it was split in modules).

@frouo
Copy link

frouo commented Mar 8, 2021

Thank you so much @koutcher !

For others with git installed though Xcode, here are the steps to "install" diff-highlight:

  1. Download the diff-highlight script and put the result in the file /usr/local/bin/diff-highlight:
curl -o /usr/local/bin/diff-highlight https://raw.githubusercontent.com/git/git/3dbfe2b8ae94cbdae5f3d32581aedaa5510fdc87/contrib/diff-highlight/diff-highlight
  1. Make the file executable:
chmod +x /usr/local/bin/diff-highlight
  1. Add diff-highlight in your PATH (or ~/.bash_profile if using bash):
echo 'export PATH="$PATH:/usr/local/bin/diff-highlight"' >> ~/.zshrc
  1. Do not forget to run source command to update your PATH in your current terminal:
source ~/.zshrc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests