4646from mytoncore .telemetry import is_host_virtual
4747from mytonctrl .migrate import run_migrations
4848from mytonctrl .utils import GetItemFromList , timestamp2utcdatetime , fix_git_config , is_hex , GetColorInt , \
49- pop_user_from_args
49+ pop_user_from_args , pop_arg_from_args
5050
5151import sys , getopt , os
5252
@@ -280,15 +280,30 @@ def check_git(input_args, default_repo, text, default_branch='master'):
280280 fix_git_config (git_path )
281281 default_author = "ton-blockchain"
282282
283- # Get author, repo, branch
283+ branch = pop_arg_from_args (input_args , '--branch' )
284+
285+ if '--url' in input_args :
286+ git_url = pop_arg_from_args (input_args , '--url' )
287+ if branch is None :
288+ if '#' in git_url :
289+ ref_fragment = git_url .rsplit ('#' , 1 )[1 ]
290+ if not ref_fragment :
291+ raise Exception ("--url fragment after # is empty" )
292+ branch = ref_fragment
293+ else :
294+ branch = default_branch
295+ if '#' in git_url :
296+ git_url = git_url .split ('#' , 1 )[0 ]
297+ return None , None , branch , git_url
298+
284299 local_author , local_repo = get_git_author_and_repo (git_path )
285300 local_branch = get_git_branch (git_path )
286301
287302 # Set author, repo, branch
288303 data = GetAuthorRepoBranchFromArgs (input_args )
289304 need_author = data .get ("author" )
290305 need_repo = data .get ("repo" )
291- need_branch = data .get ("branch" )
306+ need_branch = data .get ("branch" ) or branch
292307
293308 # Check if remote repo is different from default
294309 if ((need_author is None and local_author != default_author ) or
@@ -306,7 +321,7 @@ def check_git(input_args, default_repo, text, default_branch='master'):
306321 if need_branch is None :
307322 need_branch = local_branch
308323 check_branch_exists (need_author , need_repo , need_branch )
309- return need_author , need_repo , need_branch
324+ return need_author , need_repo , need_branch , None
310325#end define
311326
312327def check_branch_exists (author , repo , branch ):
@@ -323,8 +338,7 @@ def check_branch_exists(author, repo, branch):
323338
324339def Update (local , args ):
325340 repo = "mytonctrl"
326- author , repo , branch = check_git (args , repo , "update" )
327-
341+ author , repo , branch , _ = check_git (args , repo , "update" ) # todo: implement --url for update
328342 # Run script
329343 update_script_path = pkg_resources .resource_filename ('mytonctrl' , 'scripts/update.sh' )
330344 runArgs = ["bash" , update_script_path , "-a" , author , "-r" , repo , "-b" , branch ]
@@ -345,8 +359,8 @@ def Upgrade(local, ton, args: list):
345359 branch = args [args .index ('--btc-teleport' ) + 1 ]
346360 upgrade_btc_teleport (local , ton , reinstall = True , branch = branch , user = user )
347361 return
348- repo = "ton"
349- author , repo , branch = check_git (args , repo , "upgrade" )
362+
363+ author , repo , branch , git_url = check_git (args , default_repo = "ton" , text = "upgrade" )
350364
351365 # bugfix if the files are in the wrong place
352366 liteClient = ton .GetSettings ("liteClient" )
@@ -376,7 +390,11 @@ def Upgrade(local, ton, args: list):
376390
377391 # Run script
378392 upgrade_script_path = pkg_resources .resource_filename ('mytonctrl' , 'scripts/upgrade.sh' )
379- runArgs = ["bash" , upgrade_script_path , "-a" , author , "-r" , repo , "-b" , branch ]
393+ if git_url :
394+ runArgs = ["bash" , upgrade_script_path , "-g" , git_url , "-b" , branch ]
395+ else :
396+ runArgs = ["bash" , upgrade_script_path , "-a" , author , "-r" , repo , "-b" , branch ]
397+
380398 exitCode = run_as_root (runArgs )
381399 if ton .using_validator ():
382400 upgrade_btc_teleport (local , ton )
0 commit comments