Skip to content

Commit

Permalink
Merge pull request #988 from Morg42/githubplugin
Browse files Browse the repository at this point in the history
githubplugin: fix detection of clean/ahead/behind
  • Loading branch information
Morg42 authored Dec 22, 2024
2 parents e321dc1 + 81e5859 commit 0fac7fa
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion githubplugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,15 +678,17 @@ def is_repo_clean(self, name: str, exc=False) -> bool:

# abort if worktree isn't clean
if local.is_dirty() or local.untracked_files != []:
self.logger.debug(f'repo {name}: dirty: {local.is_dirty()}, untracked files: {local.untracked_files}')
self.repos[name]['clean'] = False
return False

# get remote and local branch heads
try:
remote = self.gh.get_repo(entry['owner'], entry['gh_repo'])
r_branch = remote.get_branch(branch=entry['branch'])
l_head = local.heads[entry['branch']].commit.hexsha
r_head = r_branch.commit.sha

l_head = local.heads[entry['branch']].commit.hexsha
except AttributeError:
if exc:
f = self.loggerr
Expand All @@ -699,6 +701,16 @@ def is_repo_clean(self, name: str, exc=False) -> bool:
return False

clean = l_head == r_head
if not clean:
try:
_ = list(repo.iter_commits(r_head))
# as clean is excluded, we must be ahead. Possibly out changes are not saved, so stay as "not clean""
pass
except git.exc.GitCommandError:
# commit not in local, we are not clean and not ahead, so we are behind
# being beind with clean worktree means nothing gets lost or overwritten. Allow operations
clean = True

self.repos[name]['clean'] = clean
return clean

Expand Down

0 comments on commit 0fac7fa

Please sign in to comment.