summaryrefslogtreecommitdiff
path: root/morphlib/cachedrepo_tests.py
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2014-06-30 13:47:06 +0000
committerSam Thursfield <sam.thursfield@codethink.co.uk>2014-07-07 15:06:22 +0100
commitc029130068e3a08c51dd551fda88cc5302671d53 (patch)
tree185e204a874c085b625d2ca536593ceba3f26833 /morphlib/cachedrepo_tests.py
parent770a6cb434ac31238eb2eee526e235728ce07aff (diff)
downloadmorph-c029130068e3a08c51dd551fda88cc5302671d53.tar.gz
Fix Morph failing to update some cached git repos
I was getting the following error when running the 'do-release.py' script: ERROR:root:Command failed: morph --quiet --trove-host=git.baserock.org list-artifacts baserock:baserock/definitions sam/auto-release minimal-system-x86_32-generic ERROR: Ref d67a0e110187abd560a1de63fa172894a52839d5 is an invalid reference for repo git://git.baserock.org/delta/linux The commit that it wants did actually exist in git.baserock.org and the logs show that Morph hadn't done a `git remote update` to get the commit locally. This turned out to be because it'd had already looked up a different ref in linux.git. It hadn't needed to run 'git remote update', but it *had* added linux.git to a "don't need to update this repo again" list. Oops! I've moved the code in question to the cachedrepo module so that the repo object keeps that of whether it should be updated. The bug is now fixed. As a side effect this patch fixes the spurious 'Updating repo file:///...' messages, which were printed even though repos with file:/// URLs are never updated.
Diffstat (limited to 'morphlib/cachedrepo_tests.py')
-rw-r--r--morphlib/cachedrepo_tests.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/morphlib/cachedrepo_tests.py b/morphlib/cachedrepo_tests.py
index 8afe2063..74c16591 100644
--- a/morphlib/cachedrepo_tests.py
+++ b/morphlib/cachedrepo_tests.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Codethink Limited
+# Copyright (C) 2012-2014 Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -31,6 +31,7 @@ class CachedRepoTests(unittest.TestCase):
"kind": "chunk"
}'''
+ known_commit = 'a4da32f5a81c8bc6d660404724cedc3bc0914a75'
bad_sha1_known_to_rev_parse = 'cafecafecafecafecafecafecafecafecafecafe'
def rev_parse(self, ref):
@@ -247,9 +248,24 @@ class CachedRepoTests(unittest.TestCase):
self.repo = morphlib.cachedrepo.CachedRepo(
object(), 'local:repo', 'file:///local/repo/', '/local/repo/')
self.repo._update = self.update_with_failure
+ self.assertFalse(self.repo.requires_update_for_ref(self.known_commit))
self.repo.update()
def test_clone_checkout(self):
self.repo.clone_checkout('master', '/.DOES_NOT_EXIST')
self.assertEqual(self.clone_target, '/.DOES_NOT_EXIST')
self.assertEqual(self.clone_ref, 'master')
+
+ def test_no_need_to_update_repo_for_existing_sha1(self):
+ # If the SHA1 is present locally already there's no need to update.
+ # If it's a named ref then it might have changed in the remote, so we
+ # must still update.
+ self.assertFalse(self.repo.requires_update_for_ref(self.known_commit))
+ self.assertTrue(self.repo.requires_update_for_ref('named_ref'))
+
+ def test_no_need_to_update_repo_if_already_updated(self):
+ self.repo._update = self.update_successfully
+
+ self.assertTrue(self.repo.requires_update_for_ref('named_ref'))
+ self.repo.update()
+ self.assertFalse(self.repo.requires_update_for_ref('named_ref'))