From 795468d307af24bf0dd53931d088b1e10721b0d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Kristian=20Lyhne=20Th=C3=B8gersen?= Date: Sat, 5 Sep 2026 12:45:14 +0200 Subject: [PATCH 1/4] fix: Get the name of the remote if there are more than 1 --- zmk/repo.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/zmk/repo.py b/zmk/repo.py index fe625e9..a4492f5 100644 --- a/zmk/repo.py +++ b/zmk/repo.py @@ -127,9 +127,33 @@ def get_modules(self) -> Generator[Module, None, None]: def get_remote_url(self) -> str: """Get the remote URL for the checked out Git branch.""" - remote = self.git("remote", capture_output=True).strip() + remote = self._get_tracking_remote() return self.git("remote", "get-url", remote, capture_output=True).strip() + def _get_tracking_remote(self) -> str: + """Get the name of the remote tracked by the checked out Git branch.""" + try: + upstream = self.git( + "rev-parse", + "--abbrev-ref", + "--symbolic-full-name", + "@{upstream}", + capture_output=True, + ).strip() + return upstream.split("/", 1)[0] + except subprocess.CalledProcessError: + pass # No upstream configured for the current branch. + + remotes = [ + line + for line in self.git("remote", capture_output=True).splitlines() + if line.strip() + ] + if not remotes: + raise RuntimeError("This repo has no Git remotes configured.") + + return "origin" if "origin" in remotes else remotes[0] + def get_remote(self) -> Remote: """Get a Remote object for the checked out Git branch's remote URL.""" return Remote(self.get_remote_url()) From c5c44e155c4389e6120b640cc957d0c1c696965b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Th=C3=B8gersen?= Date: Mon, 14 Sep 2026 16:36:53 +0200 Subject: [PATCH 2/4] Update zmk/repo.py Document the `_get_tracking_remote` method Co-authored-by: Joel Spadin --- zmk/repo.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/zmk/repo.py b/zmk/repo.py index a4492f5..6a0b6ce 100644 --- a/zmk/repo.py +++ b/zmk/repo.py @@ -131,7 +131,15 @@ def get_remote_url(self) -> str: return self.git("remote", "get-url", remote, capture_output=True).strip() def _get_tracking_remote(self) -> str: - """Get the name of the remote tracked by the checked out Git branch.""" + """ + Get the name of the remote tracked by the checked out Git branch. + + If the checked out branch does not have a remote-tracking branch, or if + no branch is checked out, this falls back to "origin" if it exists, else + the first defined remote. + + :raise: RuntimeError if the repo has no remotes + """ try: upstream = self.git( "rev-parse", From 119b88727c4eaf5690d19dea73b64dab5ae85c1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Kristian=20Lyhne=20Th=C3=B8gersen?= Date: Mon, 14 Sep 2026 16:34:39 +0200 Subject: [PATCH 3/4] apply review suggestions --- zmk/repo.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/zmk/repo.py b/zmk/repo.py index 6a0b6ce..d3b62ae 100644 --- a/zmk/repo.py +++ b/zmk/repo.py @@ -148,15 +148,11 @@ def _get_tracking_remote(self) -> str: "@{upstream}", capture_output=True, ).strip() - return upstream.split("/", 1)[0] + return upstream.split("/", maxsplit=1)[0] except subprocess.CalledProcessError: pass # No upstream configured for the current branch. - remotes = [ - line - for line in self.git("remote", capture_output=True).splitlines() - if line.strip() - ] + remotes = self.git("remote", capture_output=True).splitlines() if not remotes: raise RuntimeError("This repo has no Git remotes configured.") From adb37511bf7ca71f8e754bb702aeffaf4505fabb Mon Sep 17 00:00:00 2001 From: Joel Spadin Date: Sun, 20 Sep 2026 12:31:15 -0500 Subject: [PATCH 4/4] Fix formatting errors --- zmk/repo.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/zmk/repo.py b/zmk/repo.py index d3b62ae..b5547b1 100644 --- a/zmk/repo.py +++ b/zmk/repo.py @@ -131,15 +131,15 @@ def get_remote_url(self) -> str: return self.git("remote", "get-url", remote, capture_output=True).strip() def _get_tracking_remote(self) -> str: - """ - Get the name of the remote tracked by the checked out Git branch. + """ + Get the name of the remote tracked by the checked out Git branch. - If the checked out branch does not have a remote-tracking branch, or if - no branch is checked out, this falls back to "origin" if it exists, else - the first defined remote. + If the checked out branch does not have a remote-tracking branch, or if + no branch is checked out, this falls back to "origin" if it exists, else + the first defined remote. - :raise: RuntimeError if the repo has no remotes - """ + :raise: RuntimeError if the repo has no remotes + """ try: upstream = self.git( "rev-parse",