Skip to content

Commit c2a2806

Browse files
committed
gitcmds: rename default_remote() to upstream_remote()
Make the function more general and rename it to better reflect its purpose. Signed-off-by: David Aguilar <davvid@gmail.com>
1 parent 1129adb commit c2a2806

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

cola/gitcmds.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,24 @@ def add(items, u=False):
3232
items, lambda paths: add('--', force=True, verbose=True, u=u, *paths))
3333

3434

35+
def get_branch(branch):
36+
if branch is None:
37+
branch = current_branch()
38+
return branch
39+
40+
3541
def get_config(config):
3642
if config is None:
3743
config = gitcfg.current()
3844
return config
3945

4046

41-
def default_remote(config=None):
42-
"""Return the remote tracked by the current branch."""
47+
48+
def upstream_remote(branch=None, config=None):
49+
"""Return the remote associated with the specified branch"""
4350
config = get_config(config)
44-
return config.get('branch.%s.remote' % current_branch())
51+
branch = get_branch(branch)
52+
return config.get('branch.%s.remote' % branch)
4553

4654

4755
def remote_url(remote, push=False, config=None):

cola/widgets/remote.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def __init__(self, model, action, title, parent=None, icon=None):
262262
self.top_layout, self.options_layout)
263263
self.setLayout(self.main_layout)
264264

265-
default_remote = gitcmds.default_remote() or 'origin'
265+
default_remote = gitcmds.upstream_remote() or 'origin'
266266

267267
remotes = self.model.remotes
268268
if default_remote in remotes:

test/gitcmds_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ def test_branch_list_remote(self):
3232
self.git('remote', 'rm', 'origin')
3333
self.assertEqual(gitcmds.branch_list(remote=True), [])
3434

35-
def test_default_remote(self):
36-
"""Test default_remote()."""
37-
self.assertEqual(gitcmds.default_remote(config=self.config), None)
35+
def test_upstream_remote(self):
36+
"""Test getting the configured upstream remote"""
37+
self.assertEqual(gitcmds.upstream_remote(config=self.config), None)
3838
self.git('config', 'branch.master.remote', 'test')
3939
self.config.reset()
40-
self.assertEqual(gitcmds.default_remote(config=self.config), 'test')
40+
self.assertEqual(gitcmds.upstream_remote(config=self.config), 'test')
4141

4242
def test_tracked_branch(self):
4343
"""Test tracked_branch()."""

0 commit comments

Comments
 (0)