Skip to content

Commit

Permalink
Issue #573: Prioritise origin remote when inferring remote (#577)
Browse files Browse the repository at this point in the history
  • Loading branch information
amalota authored Jul 13, 2022
1 parent fe6e7b6 commit 24bcc6a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
12 changes: 6 additions & 6 deletions git_machete/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2058,19 +2058,19 @@ def __derive_remote_and_github_org_and_repo(self, branch_used_for_tracking_data:
'If that is the case, you can provide repository information explicitly, via these 3 git config keys: '
'`machete.github.{remote,organization,repository}`\n'))

if len(remote_and_github_org_and_repo) == 1:
return remote_and_github_org_and_repo[list(remote_and_github_org_and_repo.keys())[0]]

if 'origin' in remote_and_github_org_and_repo:
return remote_and_github_org_and_repo['origin']

if len(remote_and_github_org_and_repo) > 1 and branch_used_for_tracking_data is not None:
remote_for_fetching_of_branch = self.__git.get_combined_remote_for_fetching_of_branch(
branch=branch_used_for_tracking_data,
remotes=list(remote_and_github_org_and_repo.keys()))
if remote_for_fetching_of_branch is not None:
return remote_and_github_org_and_repo[remote_for_fetching_of_branch]

if len(remote_and_github_org_and_repo) == 1:
return remote_and_github_org_and_repo[list(remote_and_github_org_and_repo.keys())[0]]

if 'origin' in remote_and_github_org_and_repo:
return remote_and_github_org_and_repo['origin']

raise MacheteException(
f'Multiple non-origin remotes correspond to GitHub in this repository: '
f'{", ".join(remote_and_github_org_and_repo.keys())} -> aborting. \n'
Expand Down
20 changes: 20 additions & 0 deletions tests/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,26 @@ def test_github_create_pr_with_multiple_non_origin_remotes(self) -> None:
indent=''
)

# branch feature_3 present in only one remote: origin_2 with tracking data, origin remote present - takes priority
(
self.repo_sandbox.add_remote('origin', self.repo_sandbox.remote_path)
.check_out('feature_3')
.new_branch('feature_5')
.commit('introduce feature 5')
.push(remote='origin_2')
)

expected_result = """
Added branch `feature_5` onto `feature_3`
Fetching origin...
Creating a PR from `feature_5` to `feature_3`... OK, see www.github.com
"""
assert_command(
['github', 'create-pr'],
expected_result,
indent=''
)

git_api_state_for_test_checkout_prs = MockGitHubAPIState(
[
{
Expand Down

0 comments on commit 24bcc6a

Please sign in to comment.