Skip to content

Commit

Permalink
Merge pull request #41 from nikromen/last-bugs
Browse files Browse the repository at this point in the history
Last bugs
  • Loading branch information
nikromen authored Apr 12, 2023
2 parents 243eff5 + c93ba07 commit e725fb0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 0 additions & 4 deletions alpa/cli/local_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion alpa/repository/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand All @@ -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:
Expand Down
8 changes: 7 additions & 1 deletion alpa/repository/branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down

0 comments on commit e725fb0

Please sign in to comment.