Skip to content

Commit 0aaf638

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 3e3a289 commit 0aaf638

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/cmd-diff

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,17 @@ TMP_REPO = 'tmp/repo'
4949

5050
DIFF_CACHE = 'tmp/diff-cache'
5151

52+
USE_DIFFTOOL = False
53+
5254

5355
def main():
5456
args = parse_args()
5557
builds = Builds()
5658

59+
# Modify the USE_DIFFTOOL global based on the --difftool argument
60+
global USE_DIFFTOOL
61+
USE_DIFFTOOL = args.difftool
62+
5763
latest_build = builds.get_latest()
5864

5965
os.makedirs(DIFF_CACHE, exist_ok=True)
@@ -109,6 +115,7 @@ def parse_args():
109115
parser.add_argument("--to", dest='diff_to', help="Second build ID")
110116
parser.add_argument("--gc", action='store_true', help="Delete cached diff content")
111117
parser.add_argument("--arch", dest='arch', help="Architecture of builds")
118+
parser.add_argument("--difftool", action='store_true', help="Use git difftool")
112119

113120
for differ in DIFFERS:
114121
parser.add_argument("--" + differ.name, action='store_true', default=False,
@@ -420,7 +427,10 @@ def diff_cmd_outputs(cmd, path_from, path_to, strategy='template'):
420427

421428

422429
def git_diff(arg_from, arg_to):
423-
runcmd(['git', 'diff', '--no-index', arg_from, arg_to], check=False)
430+
subcmd = 'diff'
431+
if USE_DIFFTOOL:
432+
subcmd = 'difftool'
433+
runcmd(['git', subcmd, '--no-index', arg_from, arg_to], check=False)
424434

425435

426436
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)