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

diff mode doesn't display content #1869

Closed
sudoforge opened this issue Sep 30, 2021 · 5 comments · Fixed by #1891
Closed

diff mode doesn't display content #1869

sudoforge opened this issue Sep 30, 2021 · 5 comments · Fixed by #1891
Labels
bug Something isn't working

Comments

@sudoforge
Copy link

sudoforge commented Sep 30, 2021

Describe the bug you encountered:

After installing bat for the first time, I wanted to test it out in my git repository. Running bat -d <filename> with a file that has been stored in my git repository's index and has a local modification does not output any of the content, modification or not.

➜ git d -- dotfiles/git/.config/git/config
diff --git a/dotfiles/git/.config/git/config b/dotfiles/git/.config/git/config
index 3eb29fd..75bdf05 100644
--- a/dotfiles/git/.config/git/config
+++ b/dotfiles/git/.config/git/config
@@ -23,6 +23,8 @@
   default = simple
 [pull]
   rebase = true
+[log]
+  mailmap = true
 [merge]
   ff = false
   tool = vimdiff


➜ bat -d dotfiles/git/.config/git/config
───────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: dotfiles/git/.config/git/config
───────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
───────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

I am able to replicate this erroneous behavior in a new repository:

➜ mkdir /tmp/bat-diff-issue && cd /tmp/bat-diff-issue


➜ git init
Initialized empty Git repository in /tmp/bat-diff-issue/.git/


➜ echo "foo" > README


➜ git add -A && git commit -m 'initial commit'
[trunk (root-commit) 8e32fca] initial commit
 1 file changed, 1 insertion(+)
 create mode 100644 README


➜ echo "bar" > README


➜ git diff -- README
diff --git a/README b/README
index 257cc56..5716ca5 100644
--- a/README
+++ b/README
@@ -1 +1 @@
-foo
+bar


➜ bat -d README
───────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: README
───────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────
───────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────

What did you expect to happen instead?

I expected to see the modified line(s) with proper highlighting.

How did you install bat?

Through my system package manager.

➜ pacman -Qi bat | head -n5
Name            : bat
Version         : 0.18.3-1
Description     : Cat clone with syntax highlighting and git integration
Architecture    : x86_64
URL             : https://github.com/sharkdp/bat

bat version and environment

Software version

bat 0.18.3 (b146958)

Operating system

Linux 5.14.8-arch1-1

Command-line

bat -d --diagnostic README

Environment variables

SHELL=/usr/bin/zsh
PAGER=<not set>
LESS=<not set>
BAT_PAGER=<not set>
BAT_CACHE_PATH=<not set>
BAT_CONFIG_PATH=<not set>
BAT_OPTS=<not set>
BAT_STYLE=<not set>
BAT_TABS=<not set>
BAT_THEME=<not set>
XDG_CONFIG_HOME=/home/sudoforge/.config
XDG_CACHE_HOME=<not set>
COLORTERM=truecolor
NO_COLOR=<not set>
MANPAGER='nvim +Man'\!''

Config file


Compile time information

  • Profile: release
  • Target triple: x86_64-unknown-linux-gnu
  • Family: unix
  • OS: linux
  • Architecture: x86_64
  • Pointer width: 64
  • Endian: little
  • CPU features: fxsr,sse,sse2
  • Host: x86_64-unknown-linux-gnu

Less version

> less --version
less 590 (PCRE2 regular expressions)
Copyright (C) 1984-2021  Mark Nudelman

less comes with NO WARRANTY, to the extent permitted by law.
For information about the terms of redistribution,
see the file named README in the less distribution.
Home page: https://greenwoodsoftware.com/less
@sudoforge sudoforge added the bug Something isn't working label Sep 30, 2021
@sudoforge sudoforge changed the title diff mode doesn't always work properly diff mode doesn't display content Sep 30, 2021
@sudoforge
Copy link
Author

What's curious here is that LESS is detected as "not set" when running bat -d --diagnostic README:

➜ echo $LESS
-XFRi

However, upon testing, unsetting this has no effect whatsoever.

@eth-p
Copy link
Collaborator

eth-p commented Oct 2, 2021

Thanks for reporting this bug and providing instructions to reproduce it! It definitely looks like something's off with bat's output.

Some other bugged cases:

$ printf "foo\nbar" > README && git add README && git commit -m 'commit'
$ printf "baz\nbar" > README
$ bat -d README
───────┬─────────────────────────────────────────────────────────────────────────────────────────
       │ File: README
───────┼─────────────────────────────────────────────────────────────────────────────────────────
───────┴────────────────────────────────────────────────────────────────────────────────────────
$ printf "1\n2\n3" > README && git add README && git commit -m 'commit'
$ printf "0\n2\n3" > README
$ bat -d README
───────┬─────────────────────────────────────────────────────────────────────────────────────────
       │ File: README
───────┼─────────────────────────────────────────────────────────────────────────────────────────
───────┴────────────────────────────────────────────────────────────────────────────────────────

It looks like bat doesn't detect when the first line is changed.

@sudoforge
Copy link
Author

It looks like bat doesn't detect when the first line is changed.

Just to be explicit here, this issue is present even when lines other than the first are modified.

@sharkdp
Copy link
Owner

sharkdp commented Oct 3, 2021

Thank you for reporting this.

It looks like bat doesn't detect when the first line is changed.

Just to be explicit here, this issue is present even when lines other than the first are modified.

I can only reproduce the bug for the first line modification:

test.sh

seq 5 > README
git commit -am "dummy commit" > /dev/null

for i in $(seq 5); do
    echo "=== $i"
    sed -i -e "s/^$i\$/this line has been modified/" README
    bat --diff README
    git checkout README > /dev/null
done

output:

▶ bash test.sh
=== 1
───────┬─────────────────────────────────────────────
       │ File: README
───────┼─────────────────────────────────────────────
───────┴─────────────────────────────────────────────
=== 2
───────┬─────────────────────────────────────────────
       │ File: README
───────┼─────────────────────────────────────────────
   1   │ 1
   2 ~ │ this line has been modified
   3   │ 3
   4   │ 4
───────┴─────────────────────────────────────────────
=== 3
───────┬─────────────────────────────────────────────
       │ File: README
───────┼─────────────────────────────────────────────
   1   │ 1
   2   │ 2
   3 ~ │ this line has been modified
   4   │ 4
   5   │ 5
───────┴─────────────────────────────────────────────
=== 4
───────┬─────────────────────────────────────────────
       │ File: README
───────┼─────────────────────────────────────────────
   2   │ 2
   3   │ 3
   4 ~ │ this line has been modified
   5   │ 5
───────┴─────────────────────────────────────────────
=== 5
───────┬─────────────────────────────────────────────
       │ File: README
───────┼─────────────────────────────────────────────
   3   │ 3
   4   │ 4
   5 ~ │ this line has been modified
───────┴─────────────────────────────────────────────

@sudoforge
Copy link
Author

Interestingly, I copied a file that I experience the issue with into a temporary "test" repository, and cannot reproduce the error there. I'll dig into bat --diff when I get a chance over the next week and try to pinpoint why we'd be seeing different behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants