Check if branch exists locally or upstream before branching out

This commit is contained in:
Waqar Ahmed
2021-08-16 13:24:55 +05:00
parent d111089179
commit 80fca3d4ef
3 changed files with 23 additions and 2 deletions

View File

@@ -30,6 +30,10 @@ def branch_exists_in_repository(origin, branch):
return bool(re.findall(fr'/{branch}\n', cp.stdout, re.M))
def branch_checked_out_locally(path, branch):
return bool(run(['git', '-C', path, '--list', branch], log=False).stdout.strip())
def create_branch(path, base_branch, new_branch):
run(['git', '-C', path, 'checkout', '-b', new_branch, base_branch])