Commit fde6ebc0 authored by echel0n's avatar echel0n

Added git diff checking to determine commits ahead and behind when comparing...

Added git diff checking to determine commits ahead and behind when comparing local and remote branches before performing version updates.
parent 5f87d7e4
......@@ -404,6 +404,8 @@ class UpdateManager(object):
class GitUpdateManager(UpdateManager):
def __init__(self):
self.type = "git"
self._num_commits_behind = 0
self._num_commits_ahead = 0
@property
def version(self):
......@@ -459,6 +461,16 @@ class GitUpdateManager(UpdateManager):
sickrage.app.log.debug("GIT CMD OUTPUT: {}".format(output.strip()))
return
# get number of commits behind and ahead (option --count not supported git < 1.7.2)
output, __, exit_status = self._git_cmd(self._git_path, 'rev-list --left-right origin/{}...HEAD'.format(self.current_branch))
if exit_status == 0 and output:
try:
self._num_commits_behind = int(output.count("<"))
self._num_commits_ahead = int(output.count(">"))
except Exception:
sickrage.app.log.debug("Unable to determine number of commits ahead or behind for git install, failed new version check.")
return
# get latest commit_hash from remote
output, __, exit_status = self._git_cmd(self._git_path, 'rev-parse --verify --quiet origin/{}'.format(self.current_branch))
if exit_status == 0 and output:
......@@ -466,14 +478,13 @@ class GitUpdateManager(UpdateManager):
def set_newest_text(self):
if self.version != self.get_newest_version:
newest_text = _(
'There is a newer version available, version {} &mdash; <a href=\"{}\">Update Now</a>').format(
newest_text = _('There is a newer version available, version {} &mdash; <a href=\"{}\">Update Now</a>').format(
self.get_newest_version, self.get_update_url())
sickrage.app.newest_version_string = newest_text
def need_update(self):
try:
return (False, True)[self.version != self.get_newest_version]
return (False, True)[self.version != self.get_newest_version and self._num_commits_behind]
except Exception as e:
sickrage.app.log.warning("Unable to contact server, can't check for update: " + repr(e))
return False
......@@ -484,14 +495,12 @@ class GitUpdateManager(UpdateManager):
on the call's success.
"""
if not self.install_requirements(self.current_branch):
return False
# remove untracked files and performs a hard reset on git branch to avoid update issues
if sickrage.app.config.git_reset:
# self.clean() # This is removing user data and backups
self.reset()
if not self.install_requirements(self.current_branch):
return False
__, __, exit_status = self._git_cmd(self._git_path, 'pull -f {} {}'.format(sickrage.app.config.git_remote,
self.current_branch))
if exit_status == 0:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment