sharkdp / bat

A cat(1) clone with wings.
Apache License 2.0
48.46k stars 1.23k forks source link

`bat --diff` doesn't display differences in repositories that do/used to use `core.sparseCheckoutCone` #2044

Open sudoforge opened 2 years ago

sudoforge commented 2 years ago

Describe the bug you encountered:

bat --diff doesn't display the file contents after a repository has been made sparse, even if that sparse checkout is disabled.

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's package manager.

➜ pacman -Qi bat | head -n5
Name            : bat
Version         : 0.19.0-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.19.0 (59a8f58b)

Operating system

Linux 5.16.2-arch1-1

Command-line

bat --diff --diagnostic README

Environment variables

SHELL=/usr/bin/zsh
PAGER=<not set>
LESS=-XFRi
LANG=en_US.UTF-8
LC_ALL=<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='nvr -s -c '\''Man'\!''\'' -'

Config file

Compile time information

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

Fully reproducible walkthrough

➜ git init $(mktemp -d)
Initialized empty Git repository in /tmp/tmp.lzFlKEMcwS/.git/

➜ cd tmp.lzFlKEMcwS

➜ cat <<EOF > README
heredoc> a
heredoc> b
heredoc> c
heredoc> d
heredoc> EOF

➜ git add . && git commit -m 'initial commit'
[trunk (root-commit) 9aebbcd] initial commit
 1 file changed, 4 insertions(+)
 create mode 100644 README

➜ cat <<EOF > README
heredoc> 1
heredoc> 2
heredoc> 3
heredoc> 4
heredoc> EOF

➜ git diff
diff --git a/README b/README
index d68dd40..94ebaf9 100644
--- a/README
+++ b/README
@@ -1,4 +1,4 @@
-a
-b
-c
-d
+1
+2
+3
+4

➜ bat --diff README
───────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: README
───────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1 ~ │ 1
   2 ~ │ 2
   3 ~ │ 3
   4 ~ │ 4
───────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

➜ git sparse-checkout set

➜ bat --diff README
───────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: README
───────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1 ~ │ 1
   2 ~ │ 2
   3 ~ │ 3
   4 ~ │ 4
───────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

➜ git sparse-checkout set --cone

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

➜ git sparse-checkout disable

➜ bat --diff README
───────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: README
───────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
───────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
sudoforge commented 2 years ago

As a thought, this is likely the same cause of #1869, an issue I previously reported.