Skip to content

Commit

Permalink
Fix: Empty compare target
Browse files Browse the repository at this point in the history
Fixes #560

Setting compare target to `origin` may cause a `None` target to be
applied. GitGutter no longer knows that to compare against and raises
exceptions.

This commit fixes `on_branch_name()` to set a new compare target if the
given value is empty and ensures the handler to use sane fallback values
in case compare target values are empty.
  • Loading branch information
deathaxe committed Mar 20, 2021
1 parent 832d031 commit 7484554
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
7 changes: 4 additions & 3 deletions modules/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,10 @@ def set_against_origin(git_gutter, **kwargs):
by the GitGutterCommand object.
"""
def on_branch_name(status):
if not status or not status.get('remote'):
sublime.message_dialog('Current branch has not tracking remote!')
git_gutter.git_handler.set_compare_against(status.get('remote'), True)
remote = status.get('remote') if status else None
if remote:
git_gutter.git_handler.set_compare_against(remote, True)
sublime.message_dialog('Current branch has no tracking remote!')

git_gutter.git_handler.git_branch_status().then(on_branch_name)

Expand Down
11 changes: 7 additions & 4 deletions modules/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,11 @@ def get_compare_against(self):
The reference to compare the view against.
"""
# Interactively specified compare target overrides settings.
if self._git_tree in self._compare_against_mapping:
return self._compare_against_mapping[self._git_tree]
# Project settings and Preferences override plugin settings if set.
return self.settings.get('compare_against', 'HEAD')
result = self._compare_against_mapping.get(self._git_tree)
if not result:
# Project settings and Preferences override plugin settings if set.
result = self.settings.get('compare_against', 'HEAD')
return result

def set_compare_against(self, compare_against, refresh=False):
"""Apply a new branch/commit/tag string the view is compared to.
Expand All @@ -239,6 +240,8 @@ def set_compare_against(self, compare_against, refresh=False):
from 'git show-ref' to compare the view against
refresh (bool): True to force git diff and update GUI
"""
if not compare_against:
return
self._compare_against_mapping[self._git_tree] = compare_against
# force refresh if live_mode and focus_change_mode are disabled
refresh |= (not self.settings.get('live_mode') and
Expand Down

0 comments on commit 7484554

Please sign in to comment.