WIP: make_update: support Github style of remote organization #104479

Closed
Sergey Sharybin wants to merge 1 commits from Sergey:make_update into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
2 changed files with 18 additions and 6 deletions

View File

@ -445,10 +445,17 @@ def external_scripts_update(args: argparse.Namespace,
# automatically and fails when the branch is available in multiple remotes.
if make_utils.git_local_branch_exists(args.git_command, submodule_branch):
call([args.git_command, "checkout", submodule_branch])
elif make_utils.git_remote_exist(args.git_command, "origin"):
call([args.git_command, "checkout", "-t", f"origin/{submodule_branch}"])
elif make_utils.git_remote_exist(args.git_command, "upstream"):
call([args.git_command, "checkout", "-t", f"upstream/{submodule_branch}"])
else:
if make_utils.git_remote_branch_exists(args.git_command, "origin", submodule_branch):
call([args.git_command, "checkout", "-t", f"origin/{submodule_branch}"])
elif make_utils.git_remote_exist(args.git_command, "upstream"):
# For the Github style of upstream workflow create a local branch from
# the upstream, but do not track it, so that we stick to the paradigm
# that no local branches are tracking upstream, preventing possible
# accidental commit to upstream.
call([args.git_command, "checkout", "-b", submodule_branch,
f"upstream/{submodule_branch}", "--no-track"])
# Don't use extra fetch since all remotes of interest have been already fetched
# some lines above.
skip_msg += work_tree_update(args, use_fetch=False)

View File

@ -60,11 +60,16 @@ def git_local_branch_exists(git_command: str, branch: str) -> bool:
)
def git_remote_branch_exists(git_command: str, remote: str, branch: str) -> bool:
return call([git_command, "rev-parse", "--verify", f"remotes/{remote}/{branch}"],
exit_on_error=False, silent=True) == 0
def git_branch_exists(git_command: str, branch: str) -> bool:
return (
git_local_branch_exists(git_command, branch) or
call([git_command, "rev-parse", "--verify", "remotes/upstream/" + branch], exit_on_error=False, silent=True) == 0 or
call([git_command, "rev-parse", "--verify", "remotes/origin/" + branch], exit_on_error=False, silent=True) == 0
git_remote_branch_exists(git_command, "upstream", branch) or
git_remote_branch_exists(git_command, "origin", branch)
)