From 4b89de53f74a95181411c312cf88d5256ada4d30 Mon Sep 17 00:00:00 2001 From: Arksine Date: Tue, 16 Mar 2021 10:33:27 -0400 Subject: [PATCH] update_manager: add "primary_branch" option Git clients may specify a branch other than "master" as the primary to pass the validation checks. Signed-off-by: Eric Callahan --- moonraker/plugins/update_manager.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/moonraker/plugins/update_manager.py b/moonraker/plugins/update_manager.py index 48f0aad..15da32a 100644 --- a/moonraker/plugins/update_manager.py +++ b/moonraker/plugins/update_manager.py @@ -449,6 +449,7 @@ class GitUpdater: self.name = config.get_name().split()[-1] if path is None: path = os.path.expanduser(config.get('path')) + self.primary_branch = config.get("primary_branch", "master") self.repo_path = path self.repo = GitRepo(cmd_helper, path, self.name) self.init_evt = Event() @@ -547,7 +548,7 @@ class GitUpdater: async def _update_repo_state(self, need_fetch=True): self.is_valid = False await self.repo.initialize(need_fetch=need_fetch) - invalids = self.repo.report_invalids(self.origin) + invalids = self.repo.report_invalids(self.origin, self.primary_branch) if invalids: msgs = '\n'.join(invalids) self._log_info( @@ -914,16 +915,17 @@ class GitRepo: f"Is Detached: {self.head_detached}\n" f"Commits Behind: {len(self.commits_behind)}") - def report_invalids(self, valid_origin): + def report_invalids(self, valid_origin, primary_branch): invalids = [] upstream_url = self.upstream_url.lower() if upstream_url[-4:] != ".git": upstream_url += ".git" if upstream_url != valid_origin: invalids.append(f"Unofficial remote url: {self.upstream_url}") - if self.git_branch != "master" or self.git_remote != "origin": + if self.git_branch != primary_branch or self.git_remote != "origin": invalids.append( - "Repo not on default remote branch: " + "Repo not on valid remote branch, expected: " + f"origin/{primary_branch}, detected: " f"{self.git_remote}/{self.git_branch}") if self.head_detached: invalids.append("Detached HEAD detected")