Skip to content

Commit

Permalink
Revup cherry-pick attempts to fetch
Browse files Browse the repository at this point in the history
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
  • Loading branch information
aaron-skydio authored and jerry-skydio committed Jul 11, 2023
1 parent 917438e commit 01c4e38
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions revup/cherry_pick.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import argparse
import asyncio
import logging

from revup import git
Expand All @@ -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
Expand Down

0 comments on commit 01c4e38

Please sign in to comment.