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

More Git features? #440

Closed
jetzerb opened this issue Dec 3, 2018 · 6 comments
Closed

More Git features? #440

jetzerb opened this issue Dec 3, 2018 · 6 comments
Labels
feature-request New feature or request

Comments

@jetzerb
Copy link

jetzerb commented Dec 3, 2018

Feature requests for more git integration. Some ideas:

Show git blame info

Show abbreviated commit id, user, date of change) along with the syntax highlighting.

Show git diff info

Go one step further and show the diff between the current version and the immediately-preceding version. Something roughly equivalent to git diff -U1000 1a2b3c4d FileName.foo | bat -l foo but with good highlighting on the modified lines in addition to syntax highlighting.

  • -U option to git diff specifies number of lines of context. I just threw in a big number here, but the idea would be that we can see the entire file regardless of how big it is.
  • 1a2b3c4d represents the previous commit to the file. Maybe make a --diff option that takes 0, 1, or 2 arguments:
    • --diff: diff from the previous commit to current version
    • --diff 1a2b3c4d: diff from specified commit to current version
    • --diff 1a2b3c4d 2b3c4d5e: diff from first commit to second

Bat As Git Pager

Or perhaps it's easier to come at git diff from the other side, and make bat smart enough to do syntax highlighting when it is specified as git's pager. Result would be similar to that achieved with diff-so-fancy, but with syntax highlighting specific to each file in the diff.

@sharkdp sharkdp added the question Further information is requested label Dec 7, 2018
@sharkdp
Copy link
Owner

sharkdp commented Dec 7, 2018

Thank you for the feedback.

Show git blame info

I don't really see a huge need for having git blame info within bat, but if this is easy to implement and somebody wants to work on that, I'd consider integrating this.

Show git diff info
Go one step further and show the diff between the current version and the immediately-preceding version.

We already do that - in a minimal form.
I am not planning to turn bat into a full-blown diff or git diff alternative. That's simply too far from its original goal. There is also a huge difference in complexity between showing the git-modification markers and showing an actual diff.

Something roughly equivalent to git diff -U1000 1a2b3c4d FileName.foo | bat -l foo but with good highlighting on the modified lines in addition to syntax highlighting.

So how would that look like? How do you display both the syntax highlighting as well as the additions/deletions.

-U option to git diff specifies number of lines of context

Please see the related issue #23 where we plan to do something similar for bat.

  • 1a2b3c4d represents the previous commit to the file

Passing SHA-1s/branches/tags/etc. to diff against sounds like a useful idea. However, we would probably always display the current version of the file and simply change the target to show the diff/modifications against.

Or perhaps it's easier to come at git diff from the other side, and make bat smart enough to do syntax highlighting when it is specified as git's pager.

This has been requested in #274 as well.

Unfortunately, there is no way to get git to communicate the filename to the pager (if possible). This means that it is not possible to reliably get the language of the file. See also: #334 (comment)

There is also a fundamental problem with this approach: Syntax highlighting only works if you know the whole context (think of multiline comments). To do it right, you would have to syntax-highlight the original file, the current version of the file and then show the syntax-highlighted diff. If you just use bat as a pager for git diff, you don't have the full context for both files.

@jetzerb
Copy link
Author

jetzerb commented Dec 7, 2018

Sorry for the duplicate-ish post...Evidently I don't know how to search the issues list or I would have found some subset of issues 23, 274, and 334.

A couple thoughts

  • git difftool does provide filenames to the diff tool. I know nothing of the internals of git, but there may be something similar lurking around within git diff that could be leveraged(?)
  • git diff includes a signature that bat could look for to determine the file type
diff --git a/path/to/file.ext b/path/to/file.ext
index 1a2b3c4d..2b3c4d5e 100644
--- a/path/to/file.ext
+++ b/path/to/file.ext

Regarding the required context for the syntax highlighting to work: my ideal use case is really an extension of the existing git integration, so we're talking about the entire file being available to bat:

  • where bat currently shows a green +, no change is necessary. That's the decoration required to show the change from the previous version
  • where bat currently shows a red -, I would like it to show the removed line(s) in a dim gray (no syntax highlighting required)
  • where bat currently shows a yellow ~, I would like to see the ~ replaced with one or more - lines in a dim gray followed by one or more + lines with the syntax highlighting

Somehow bat already knows where lines have been removed, changed, or added, so my hope was that it wouldn't be difficult to insert blocks of text holding the previous incarnation of the affected lines into the overall syntax-highlighted file.

@bendem
Copy link

bendem commented Dec 10, 2018

Also related to #369 (using bat as a git pager)

@sharkdp
Copy link
Owner

sharkdp commented Dec 14, 2018

Regarding the required context for the syntax highlighting to work: my ideal use case is really an extension of the existing git integration, so we're talking about the entire file being available to bat:

  • where bat currently shows a green +, no change is necessary. That's the decoration required to show the change from the previous version
  • where bat currently shows a red -, I would like it to show the removed line(s) in a dim gray (no syntax highlighting required)
  • where bat currently shows a yellow ~, I would like to see the ~ replaced with one or more - lines in a dim gray followed by one or more + lines with the syntax highlighting

Somehow bat already knows where lines have been removed, changed, or added, so my hope was that it wouldn't be difficult to insert blocks of text holding the previous incarnation of the affected lines into the overall syntax-highlighted file.

Ok, I think that could work. Basically we just do what we do now but print the old lines in addition (grayed out). We do not need git diff or git difftool for this. bat uses libgit to get that kind of information.

@sharkdp sharkdp added feature-request New feature or request and removed question Further information is requested labels Dec 14, 2018
@sharkdp
Copy link
Owner

sharkdp commented Dec 14, 2018

@jetzerb I'm going to close this ticket as it includes three requests at once which is difficult to track. It would be great if you could open a new ticket for the feature request concerning the dim gray lines. If you want to further discuss the other two points (git blame, using bat as a git pager), please use the existing tickets or open new tickets as appropriate. Thank you.

@sharkdp sharkdp closed this as completed Dec 14, 2018
@jetzerb
Copy link
Author

jetzerb commented Dec 14, 2018

Sweet. I don't know how much info you can get out of libgit, but if you can highlight the bits of text in the old lines that have changed, that would be even better. Like diff-so-fancy does.
image

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

No branches or pull requests

3 participants