Skip to content

Commit e2b9789

Browse files
committed
feat(git): add guess_default_branch function
1 parent c44e2fe commit e2b9789

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

commitizen/git.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,3 +310,10 @@ def _get_log_as_str_list(start: str | None, end: str, args: str) -> list[str]:
310310
if not c.out:
311311
return []
312312
return c.out.split(f"{delimiter}\n")
313+
314+
315+
def guess_default_branch() -> str:
316+
c = cmd.run("git branch --format '%(refname:short)' --list master main")
317+
if c.return_code != 0:
318+
raise GitCommandError(c.err)
319+
return c.out.strip()

0 commit comments

Comments
 (0)