summaryrefslogtreecommitdiff
path: root/morphlib
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2014-06-19 17:38:09 +0100
committerSam Thursfield <sam.thursfield@codethink.co.uk>2014-06-19 17:38:09 +0100
commitfdfde37bdf5330316c96fd296b038ff4d870c010 (patch)
treeadc814e7a3eb0d3dfbf4a406d6deb3fe5b8f77f3 /morphlib
parentd5ee8bdc636f5830f897b1846522b64bd5f06ebf (diff)
parent375027c23eb0f8163615e9c1c97a40ef92504db9 (diff)
downloadmorph-fdfde37bdf5330316c96fd296b038ff4d870c010.tar.gz
Merge branch 'sam/only-update-git-when-needed-v2'
Reviewed-By: Adam Coldrick <adam.coldrick@codethink.co.uk> Reviewed-By: Pedro Alvarez <pedro.alvarez@codethink.co.uk>
Diffstat (limited to 'morphlib')
-rw-r--r--morphlib/app.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/morphlib/app.py b/morphlib/app.py
index 5b11d269..07e6348f 100644
--- a/morphlib/app.py
+++ b/morphlib/app.py
@@ -305,12 +305,20 @@ class Morph(cliapp.Application):
or cloning the repository into the local repo cache.
'''
absref = None
+
+ def cached_repo_requires_update_for_ref(repo, ref):
+ # Named refs that are valid SHA1s will confuse this code.
+ ref_can_change = not morphlib.git.is_valid_sha1(ref)
+ return (ref_can_change or not repo.ref_exists(ref))
+
if lrc.has_repo(reponame):
repo = lrc.get_repo(reponame)
- if update:
- self.status(msg='Updating cached git repository %(reponame)s',
- reponame=reponame)
+ if update and cached_repo_requires_update_for_ref(repo, ref):
+ self.status(msg='Updating cached git repository %(reponame)s '
+ 'for ref %(ref)s', reponame=reponame, ref=ref)
repo.update()
+ # If the user passed --no-git-update, and the ref is a SHA1 not
+ # available locally, this call will raise an exception.
absref, tree = repo.resolve_ref(ref)
elif rrc is not None:
try: