From fff41dc8f5bca08a0660df8cee0dc37518950e6a Mon Sep 17 00:00:00 2001 From: Jiri Kyjovsky Date: Wed, 12 Apr 2023 20:55:47 +0200 Subject: [PATCH 1/2] fix typo --- alpa/repository/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alpa/repository/base.py b/alpa/repository/base.py index c8dd6a8..64d25ca 100644 --- a/alpa/repository/base.py +++ b/alpa/repository/base.py @@ -271,7 +271,7 @@ def _parse_reponame_from_url(url: str) -> str: split = without_git_suffix.split("/") return f"{split[-2]}/{split[-1]}" - return url.split(":")[-1] + return without_git_suffix.split(":")[-1] def full_reponame(self) -> str: logger.debug(f"Trying to find {self.remote_name} in {self.remotes}") From c93ba0799c2289bd3a7fc9cbedbcf7b78ace4235 Mon Sep 17 00:00:00 2001 From: Jiri Kyjovsky Date: Wed, 12 Apr 2023 22:47:14 +0200 Subject: [PATCH 2/2] feat: switch to feat branch when it is relevant --- alpa/cli/local_repo.py | 4 ---- alpa/repository/base.py | 4 ++++ alpa/repository/branch.py | 8 +++++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/alpa/cli/local_repo.py b/alpa/cli/local_repo.py index 45fa378..9c9f43e 100644 --- a/alpa/cli/local_repo.py +++ b/alpa/cli/local_repo.py @@ -108,10 +108,6 @@ def push(pull_request: bool) -> None: ) click.echo(f"PR#{pr.number} created. URL: {pr.html_url}") - # go from feat branch to package branch - local_repo.git_cmd(["switch", local_repo.package]) - local_repo.git_cmd(["branch", "-D", local_repo.feat_branch]) - @click.command("pull") def pull() -> None: diff --git a/alpa/repository/base.py b/alpa/repository/base.py index 64d25ca..c9236e8 100644 --- a/alpa/repository/base.py +++ b/alpa/repository/base.py @@ -292,6 +292,10 @@ def full_reponame(self) -> str: def git_root(self) -> Path: return Path(self.git.git_root) + def is_branch_merged(self, branch: str) -> bool: + ret = self.git_cmd(["fetch", self.remote_name, branch]) + return ret.retval != 0 and "couldn't find remote ref" in ret.stderr + class AlpaRepo(LocalRepo): def __init__(self, repo_path: Path, gh_api: Optional[GithubAPI] = None) -> None: diff --git a/alpa/repository/branch.py b/alpa/repository/branch.py index 2cec531..1b46bdd 100644 --- a/alpa/repository/branch.py +++ b/alpa/repository/branch.py @@ -55,7 +55,13 @@ def switch_to_package(self, package: str) -> None: return None feat_branch = self.get_feat_branch_of_package(package) - branch_to_switch = feat_branch if self.branch_exists(feat_branch) else package + if self.branch_exists(feat_branch) and not self.is_branch_merged(feat_branch): + branch_to_switch = feat_branch + else: + branch_to_switch = package + if self.branch_exists(feat_branch): + self.git_cmd(["branch", "-D", feat_branch]) + result = self.git_cmd(["switch", branch_to_switch]) if result.retval == 0: click.echo(result.stdout.replace("branch", "package"))