Skip to content

Commit dd5ed10

Browse files
committed
Fixed Git.push() to specify which remote branch to push to (based on local branch)
1 parent 21c39c9 commit dd5ed10

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

mbed/mbed.py

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,20 @@ def commit():
435435
popen([git_cmd, 'commit', '-a'] + (['-v'] if verbose else ['-q']))
436436

437437
def push(repo, all=None):
438-
popen([git_cmd, 'push'] + (['--all'] if all else []) + (['-v'] if verbose else ['-q']))
438+
if all:
439+
popen([git_cmd, 'push', '--all'] + (['-v'] if verbose else ['-q']))
440+
else:
441+
remote = Git.getremote()
442+
branch = Git.getbranch()
443+
if remote and branch:
444+
popen([git_cmd, 'push', remote, branch] + (['-v'] if verbose else ['-q']))
445+
else:
446+
err = "Unable to push outgoing changes for \"%s\" in \"%s\".\n" % (repo.name, repo.path)
447+
if not remote:
448+
error(err+"The local repository is not associated with a remote one.\n", 1)
449+
if not branch:
450+
error(err+"Working set is not on a branch.\n", 1)
451+
439452

440453
def pull(repo):
441454
popen([git_cmd, 'fetch', '--all'] + (['-v'] if verbose else ['-q']))
@@ -467,15 +480,8 @@ def untracked():
467480
return pquery([git_cmd, 'ls-files', '--others', '--exclude-standard']).splitlines()
468481

469482
def outgoing():
470-
# Find the default remote
471-
remote = None
472-
remotes = Git.getremotes('push')
473-
for r in remotes:
474-
remote = r[0]
475-
# Prefer origin which is the default when you clone locally
476-
if r[0] == "origin":
477-
break
478-
483+
# Get default remote
484+
remote = Git.getremote()
479485
if not remote:
480486
return -1
481487

@@ -499,6 +505,17 @@ def outgoing():
499505
def isdetached():
500506
return Git.getbranch() == "HEAD"
501507

508+
# Finds default remote
509+
def getremote(rtype='fetch'):
510+
remote = None
511+
remotes = Git.getremotes('push')
512+
for r in remotes:
513+
remote = r[0]
514+
# Prefer origin which is Git's default remote when cloning
515+
if r[0] == "origin":
516+
break
517+
return remote
518+
502519
# Finds all associated remotes for the specified remote type
503520
def getremotes(rtype='fetch'):
504521
result = []

0 commit comments

Comments
 (0)