From e6d7c0f5cf10d8f0cc4df46f23879a28faf19e03 Mon Sep 17 00:00:00 2001 From: Mustafa J Date: Thu, 13 Jun 2024 11:15:38 +0300 Subject: [PATCH 1/3] history.GitLog.log_result: show full commit if no output --- git/history.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/git/history.py b/git/history.py index 0512d92..5438fca 100644 --- a/git/history.py +++ b/git/history.py @@ -90,9 +90,17 @@ def log_result(self, ref): # I'm not certain I should have the file name here; it restricts the # details to just the current file. Depends on what the user expects... # which I'm not sure of. + def check_if_output(result): + if result: + self.details_done(result) + else: + # If there's no output (file was likely renamed), then show the full commit. + self.run_command( + ['git', 'log', '--no-color', '-p', '-1', ref], + self.details_done) self.run_command( ['git', 'log', '--no-color', '-p', '-1', ref, '--', self.get_file_name()], - self.details_done) + check_if_output) def details_done(self, result): self.scratch(result, title="Git Commit Details", From 715151abe5682b78f4896a06ad9522392d00133d Mon Sep 17 00:00:00 2001 From: Mustafa J Date: Thu, 13 Jun 2024 11:33:54 +0300 Subject: [PATCH 2/3] history.GitShow: add --follow --- git/history.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git/history.py b/git/history.py index 5438fca..c5fd7d6 100644 --- a/git/history.py +++ b/git/history.py @@ -120,7 +120,7 @@ def run(self, edit=None): # GitLog Copy-Past self.run_command( ['git', 'log', '--no-color', '--pretty=%s (%h)\a%an <%aE>\a%ad (%ar)', - '--date=local', '--max-count=9000', '--', self.get_file_name()], + '--date=local', '--follow', '--max-count=9000', '--', self.get_file_name()], self.show_done) def show_done(self, result): From 96537b6786c7356c08ef9ddc7082b1c705d4a0cc Mon Sep 17 00:00:00 2001 From: Mustafa J Date: Thu, 13 Jun 2024 16:11:13 +0300 Subject: [PATCH 3/3] history.GitShow: add use_name_at_ref in case of rename --- git/history.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/git/history.py b/git/history.py index c5fd7d6..6f93f06 100644 --- a/git/history.py +++ b/git/history.py @@ -134,10 +134,18 @@ def panel_done(self, picked): item = self.results[picked] # the commit hash is the last thing on the first line, in brackets ref = item[0].split(' ')[-1].strip('()') + + def use_name_at_ref(result): + p = result.strip().split('\n')[-1] + self.run_command( + ['git', 'show', '%s:%s' % (ref, p)], + self.details_done, + ref=ref) + + # In case of rename, before running `git show`, we need to get the path at that ref. self.run_command( - ['git', 'show', '%s:%s' % (ref, self.get_relative_file_path())], - self.details_done, - ref=ref) + ['git', 'log', '--follow', '%s~1..HEAD' % ref, '--name-only', '--oneline', '--', self.get_relative_file_path()], + use_name_at_ref) def details_done(self, result, ref): syntax = self.view.settings().get('syntax')