Skip to content

Commit f78b206

Browse files
committed
check branch exists before update
1 parent 08bd78e commit f78b206

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

mytonctrl/mytonctrl.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,18 @@ def check_git(input_args, default_repo, text):
272272
need_repo = local_repo
273273
if need_branch is None:
274274
need_branch = local_branch
275-
#end if
276-
275+
check_branch_exists(need_author, need_repo, need_branch)
277276
return need_author, need_repo, need_branch
278-
#end define
277+
278+
279+
def check_branch_exists(author, repo, branch):
280+
url = f"https://github.com/{author}/{repo}.git"
281+
args = ["git", "ls-remote", "--heads", url, branch]
282+
process = subprocess.run(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=3)
283+
output = process.stdout.decode("utf-8")
284+
if branch not in output:
285+
raise Exception(f"Branch {branch} not found in {url}")
286+
279287

280288
def Update(local, args):
281289
repo = "mytonctrl"

0 commit comments

Comments
 (0)