From 81e58593ef26c987b1b06e2899115340c09bdb0d Mon Sep 17 00:00:00 2001 From: Morg42 <43153739+Morg42@users.noreply.github.com> Date: Sun, 22 Dec 2024 13:48:36 +0100 Subject: [PATCH] githubplugin: fix detection of clean/ahead/behind --- githubplugin/__init__.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/githubplugin/__init__.py b/githubplugin/__init__.py index b1c6e7921..c860a969f 100644 --- a/githubplugin/__init__.py +++ b/githubplugin/__init__.py @@ -678,6 +678,7 @@ 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 @@ -685,8 +686,9 @@ def is_repo_clean(self, name: str, exc=False) -> bool: 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 @@ -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