Skip to content

Commit cb7b39e

Browse files
authored
Merge pull request #214 from yungwine/mytonctrl2_dev
dev
2 parents 242d066 + 09c9053 commit cb7b39e

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

mytonctrl/mytonctrl.py

Lines changed: 23 additions & 7 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"
@@ -324,18 +332,26 @@ def Upgrade(ton, args):
324332
else:
325333
text = "Upgrade - {red}Error{endc}"
326334
color_print(text)
327-
#end define
328335

329-
def rollback_to_mtc1(ton, args):
336+
337+
def rollback_to_mtc1(local, ton, args):
330338
color_print("{red}Warning: this is dangerous, please make sure you've backed up mytoncore's db.{endc}")
331-
a = input("Do you want to continue? [Y/n]")
339+
a = input("Do you want to continue? [Y/n]\n")
332340
if a.lower() != 'y':
333341
print('aborted.')
334342
return
335343
ton.rollback_modes()
344+
345+
workdir = local.buffer.my_work_dir
346+
version_file_path = os.path.join(workdir, 'VERSION')
347+
if os.path.exists(version_file_path):
348+
os.remove(version_file_path)
349+
336350
rollback_script_path = pkg_resources.resource_filename('mytonctrl', 'migrations/roll_back_001.sh')
337351
run_args = ["bash", rollback_script_path]
338-
exit_code = run_as_root(run_args)
352+
run_as_root(run_args)
353+
local.exit()
354+
339355

340356
def cleanup_validator_db(ton, args):
341357
cleanup_script_path = pkg_resources.resource_filename('mytonctrl', 'scripts/cleanup.sh')

0 commit comments

Comments
 (0)