Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cherry-pick: Only fetch if remote branch doesn't exist #169

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions revup/cherry_pick.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
import asyncio
import logging

from revup import git
Expand All @@ -14,11 +15,19 @@ async def find_branch_fetch_if_necessary(git_ctx: git.Git, branch_to_pick: str)
Returns the ref for the local or remote branch
"""
remote_branch_to_pick = git_ctx.ensure_branch_prefix(branch_to_pick)
branch_exists = await git_ctx.is_branch_or_commit(branch_to_pick)

if not branch_exists:
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 branch_exists:
return branch_to_pick
elif remote_branch_exists:
logging.info(f"Couldn't find '{branch_to_pick}', assuming '{remote_branch_to_pick}'")
return remote_branch_to_pick
else:
logging.info(
f"Couldn't find '{branch_to_pick}', trying to fetch from remote '{git_ctx.remote_name}'"
f"Couldn't find '{branch_to_pick}', assuming '{remote_branch_to_pick}'"
" and trying to fetch from remote"
)

await git_ctx.git(
Expand All @@ -32,12 +41,9 @@ async def find_branch_fetch_if_necessary(git_ctx: git.Git, branch_to_pick: str)
)

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
return remote_branch_to_pick
else:
raise RevupUsageException(f"Couldn't find ref '{branch_to_pick}'")

return branch_to_pick
raise RevupUsageException(f"Couldn't find ref '{branch_to_pick}' in local or remote!")


async def main(args: argparse.Namespace, git_ctx: git.Git) -> int:
Expand Down
Loading