diff --git a/git/history.py b/git/history.py index 0512d92..6f93f06 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", @@ -112,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): @@ -126,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')