From fbf29b46889cc672f126c56ba97f4222100bf8bc Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Mon, 7 Apr 2014 13:03:29 -0400 Subject: [PATCH] Proper up-to-date-check; fix when branches are empty. --- gitup/update.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/gitup/update.py b/gitup/update.py index a36a9cb..1484bff 100644 --- a/gitup/update.py +++ b/gitup/update.py @@ -56,6 +56,11 @@ def _fetch_remote(remote): remote.fetch() ### TODO: show progress print(" done.") +def _is_up_to_date(repo, branch, upstream): + """Return whether *branch* is up-to-date with its *upstream*.""" + base = repo.git.merge_base(branch.commit, upstream.commit) + return repo.commit(base) == upstream.commit + def _rebase(repo, name): """Rebase the current HEAD of *repo* onto the branch *name*.""" print(" rebasing...", end="") @@ -101,7 +106,12 @@ def _update_branch(repo, branch, merge, rebase, stasher=None): if not upstream: print(" skipped: no upstream is tracked.") return - if branch.commit == upstream.commit: ### TODO: a better check is possible + try: + branch.commit, upstream.commit + except ValueError: + print(" skipped: branch contains no revisions.") + return + if _is_up_to_date(repo, branch, upstream): print(" up to date.") return if stasher: