From 01c4e38a56b7761863e6641c6386856e7315a74c Mon Sep 17 00:00:00 2001 From: Aaron Miller Date: Thu, 1 Jun 2023 16:39:27 -0700 Subject: [PATCH] Revup cherry-pick attempts to fetch Will only attempt to fetch if the branch isn't found locally, and will still fail if it isn't found after fetching Topic: cherry-pick-fetch Reviewers: jerry,brian-k --- revup/cherry_pick.py | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/revup/cherry_pick.py b/revup/cherry_pick.py index b4d223a..ca1679d 100644 --- a/revup/cherry_pick.py +++ b/revup/cherry_pick.py @@ -1,5 +1,4 @@ import argparse -import asyncio import logging from revup import git @@ -13,17 +12,28 @@ async def main(args: argparse.Namespace, git_ctx: git.Git) -> int: """ branch_to_pick = args.branch[0] remote_branch_to_pick = git_ctx.ensure_branch_prefix(branch_to_pick) - branch_exists, remote_branch_exists = await asyncio.gather( - git_ctx.is_branch_or_commit(branch_to_pick), - git_ctx.is_branch_or_commit(remote_branch_to_pick), - ) - if remote_branch_exists and not branch_exists: - logging.warning( - f"Couldn't find '{branch_to_pick}', assuming you meant '{remote_branch_to_pick}'" + branch_exists = await git_ctx.is_branch_or_commit(branch_to_pick) + + if not branch_exists: + logging.info( + f"Couldn't find '{branch_to_pick}', trying to fetch from remote '{git_ctx.remote_name}'" + ) + + await git_ctx.git( + "fetch", + "--no-write-fetch-head", + "--no-auto-maintenance", + "--quiet" if git_ctx.sh.quiet else "--verbose", + "--force", + git_ctx.remote_name, + f"{branch_to_pick}:remotes/{git_ctx.remote_name}/{branch_to_pick}", ) - branch_to_pick = remote_branch_to_pick - elif not branch_exists: - raise RevupUsageException(f"Couldn't find ref '{branch_to_pick}'") + + if await git_ctx.is_branch_or_commit(remote_branch_to_pick): + logging.info(f"Found '{remote_branch_to_pick}'") + branch_to_pick = remote_branch_to_pick + else: + raise RevupUsageException(f"Couldn't find ref '{branch_to_pick}'") if args.base_branch: base_branch = args.base_branch