diff options
author | Richard Maw <richard.maw@gmail.com> | 2014-08-30 22:22:48 +0100 |
---|---|---|
committer | Richard Maw <richard.maw@codethink.co.uk> | 2014-09-02 17:31:17 +0100 |
commit | 66ec3928392d09cba6037fc6c665cb1aa02e86e1 (patch) | |
tree | 11ad39373466065a3058fab42372381e517e11ec /morphlib/gitdir.py | |
parent | f96452965e8065466bdd7188e66dded581bdc1a7 (diff) | |
download | morph-66ec3928392d09cba6037fc6c665cb1aa02e86e1.tar.gz |
Use git's remotes to determine unpushed branchesbaserock/richardmaw/less-ls-remote
Rather than using `git ls-remote` every time to see if there are changes
at the remote end, use a local cache.
Git already solves this problem with its refs/remotes/$foo branch
namespace, so we can just use that instead.
In addition, the detection of which upstream branch to use has been
improved; it now uses git's notion of which the upstream branch of your
current branch is, which saves effort in the implementation, and allows
the name of the local branch to differ from that of the remote branch.
This now won't notice if the branch you currently have checked out had
commits pushed from another source, but for some use-cases this is
preferable, as the result equivalent to if you had built before the
other push.
It may make sense to further extend this logic to check that the local
branch is not ahead of the remote branch, instead of requiring them to
be equal.
Diffstat (limited to 'morphlib/gitdir.py')
-rw-r--r-- | morphlib/gitdir.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/morphlib/gitdir.py b/morphlib/gitdir.py index 40ac643f..9fef4f1e 100644 --- a/morphlib/gitdir.py +++ b/morphlib/gitdir.py @@ -515,6 +515,22 @@ class GitDirectory(object): else: return 'refs/heads/' + ref + def get_upstream_of_branch(self, branch): # pragma: no cover + try: + out = morphlib.git.gitcmd( + self._runcmd, 'rev-parse', '--abbrev-ref', + '%s@{upstream}' % branch).strip() + return out + except cliapp.AppException as e: + emsg = str(e) + if 'does not point to a branch' in emsg: + # ref wasn't a branch, can't have upstream + # treat it the same as no upstream for convenience + return None + elif 'No upstream configured for branch' in emsg: + return None + raise + def resolve_ref_to_commit(self, ref): return self._rev_parse('%s^{commit}' % ref) |