Skip to content

Commit 07acc06

Browse files
committed
Fix gitea_api.Git.get_branch_head() to raise a proper exception if the HEAD cannot be retrieved
1 parent fc83822 commit 07acc06

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

osc/gitea_api/git.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,10 @@ def get_branch_head(self, branch: Optional[str] = None) -> str:
156156
if not branch:
157157
branch = self.current_branch
158158

159-
return self._run_git(["rev-parse", f"refs/heads/{branch}"])
159+
try:
160+
return self._run_git(["rev-parse", f"refs/heads/{branch}"], mute_stderr=True)
161+
except subprocess.CalledProcessError:
162+
raise exceptions.GitObsRuntimeError(f"Unable to retrieve HEAD from branch '{branch}'. Does the branch exist?")
160163

161164
def branch_exists(self, branch: str) -> bool:
162165
try:

0 commit comments

Comments
 (0)