Fix make update
when local branch exists #105234
|
@ -432,7 +432,13 @@ def external_scripts_update(args: argparse.Namespace,
|
||||||
# Switch to branch and pull.
|
# Switch to branch and pull.
|
||||||
if submodule_branch:
|
if submodule_branch:
|
||||||
if make_utils.git_branch(args.git_command) != submodule_branch:
|
if make_utils.git_branch(args.git_command) != submodule_branch:
|
||||||
if make_utils.git_remote_exist(args.git_command, "origin"):
|
# If the local branch exists just check out to it.
|
||||||
|
# If there is no local branch but only remote specify an explicit remote.
|
||||||
|
# Without this explicit specification Git attempts to set-up tracking
|
||||||
|
# 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}"])
|
call([args.git_command, "checkout", "-t", f"origin/{submodule_branch}"])
|
||||||
elif make_utils.git_remote_exist(args.git_command, "upstream"):
|
elif make_utils.git_remote_exist(args.git_command, "upstream"):
|
||||||
call([args.git_command, "checkout", "-t", f"upstream/{submodule_branch}"])
|
call([args.git_command, "checkout", "-t", f"upstream/{submodule_branch}"])
|
||||||
|
|
|
@ -54,9 +54,15 @@ def check_output(cmd: Sequence[str], exit_on_error: bool = True) -> str:
|
||||||
return output.strip()
|
return output.strip()
|
||||||
|
|
||||||
|
|
||||||
|
def git_local_branch_exists(git_command: str, branch: str) -> bool:
|
||||||
|
return (
|
||||||
|
call([git_command, "rev-parse", "--verify", branch], exit_on_error=False, silent=True) == 0
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def git_branch_exists(git_command: str, branch: str) -> bool:
|
def git_branch_exists(git_command: str, branch: str) -> bool:
|
||||||
return (
|
return (
|
||||||
call([git_command, "rev-parse", "--verify", branch], exit_on_error=False, silent=True) == 0 or
|
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/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
|
call([git_command, "rev-parse", "--verify", "remotes/origin/" + branch], exit_on_error=False, silent=True) == 0
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue