Skip to content

Commit

Permalink
fix: Get branch remote from config
Browse files Browse the repository at this point in the history
This prefers to get the upstream defined from the config but it will
fallback to origin if none is found.
  • Loading branch information
sijis committed Feb 2, 2020
1 parent 083dac6 commit 917d271
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions dulwich/porcelain.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,10 +940,10 @@ def pull(repo, remote_location=None, refspecs=None,
# Open the repo
with open_repo_closing(repo) as r:
if remote_location is None:
# TODO(jelmer): Retrieve remote to use from config rather than
# using default.
section = (b'remote', b'origin')
config = r.get_config()
remote_name = get_branch_remote(r.path)
section = (b'remote', remote_name)

if config.has_section(section):
url = config.get(section, 'url')
remote_location = url.decode()
Expand Down Expand Up @@ -1242,6 +1242,26 @@ def active_branch(repo):
return active_ref[len(LOCAL_BRANCH_PREFIX):]


def get_branch_remote(repo):
"""Return the active branch's remote name, if any.
Args:
repo: Repository to open
Returns:
remote name
Raises:
KeyError: if the repository does not have a working tree
"""
with open_repo_closing(repo) as r:
branch_name = active_branch(r.path)
config = r.get_config()
try:
remote_name = config.get((b'branch', branch_name), 'remote')
except KeyError:
remote_name = b'origin'
return remote_name


def fetch(repo, remote_location, remote_name=b'origin', outstream=sys.stdout,
errstream=default_bytes_err_stream, message=None, depth=None,
prune=False, prune_tags=False, **kwargs):
Expand Down

0 comments on commit 917d271

Please sign in to comment.