Skip to content

Commit 35357e0

Browse files
committed
cmd-diff: support git difftool so we can utilize vimdiff
Having vimdiff is a lot more powerful to me because you can manually do a few things in the terminal to massage the files on each side of the diff to give you more information (i.e. narrow in on exactly what diff you are interested in). Let's add a --difftool boolean flag to trigger `git difftool`, which will allow diffs to be displayed using vimdiff. Additionally include vim-enhanced so we have `vimdiff` installed and at our disposal.
1 parent be27517 commit 35357e0

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/cmd-diff

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,20 @@ TMP_REPO = 'tmp/repo'
5454

5555
DIFF_CACHE = 'tmp/diff-cache'
5656

57+
# Global variable that can be set once and direct the underlying code to leverage
58+
# a difftool with git diffing or not. This could be an argument passed around to
59+
# underlying functions, but decided to just implement it as a global variable for now.
60+
USE_DIFFTOOL = False
61+
5762

5863
def main():
5964
args = parse_args()
6065
builds = Builds()
6166

67+
# Modify the USE_DIFFTOOL global based on the --difftool argument
68+
global USE_DIFFTOOL
69+
USE_DIFFTOOL = args.difftool
70+
6271
latest_build = builds.get_latest()
6372

6473
os.makedirs(DIFF_CACHE, exist_ok=True)
@@ -114,6 +123,7 @@ def parse_args():
114123
parser.add_argument("--to", dest='diff_to', help="Second build ID")
115124
parser.add_argument("--gc", action='store_true', help="Delete cached diff content")
116125
parser.add_argument("--arch", dest='arch', help="Architecture of builds")
126+
parser.add_argument("--difftool", action='store_true', help="Use git difftool")
117127

118128
for differ in DIFFERS:
119129
parser.add_argument("--" + differ.name, action='store_true', default=False,
@@ -424,7 +434,10 @@ def diff_cmd_outputs(cmd, path_from, path_to, strategy: DiffCmdOutputStrategy =
424434

425435

426436
def git_diff(arg_from, arg_to):
427-
runcmd(['git', 'diff', '--no-index', arg_from, arg_to], check=False)
437+
subcmd = 'diff'
438+
if USE_DIFFTOOL:
439+
subcmd = 'difftool'
440+
runcmd(['git', subcmd, '--no-index', arg_from, arg_to], check=False)
428441

429442

430443
def cache_dir(dir):

src/deps.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,6 @@ python3-libguestfs
111111

112112
# For generating kubernetes YAML files (e.g Konflux resources)
113113
kustomize
114+
115+
# For vimdiff
116+
vim-enhanced

0 commit comments

Comments
 (0)