diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2012-11-12 15:58:27 +0000 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2012-11-12 17:09:44 +0000 |
commit | a5b913a83db94380fc91d15571f55cbf7b5c741b (patch) | |
tree | 9d03bffd2d010ec8f554c06e86cf2adb8bf1f632 /morphlib | |
parent | 1cc7a313d4a7c4dd348da1aab0e3b6108b6b48b9 (diff) | |
download | morph-a5b913a83db94380fc91d15571f55cbf7b5c741b.tar.gz |
Avoid caching repos that are on the local machine anyway
Currently the message is still displayed "Updating xxx" but no
update is actually done.
Diffstat (limited to 'morphlib')
-rw-r--r-- | morphlib/cachedrepo.py | 7 | ||||
-rw-r--r-- | morphlib/cachedrepo_tests.py | 6 | ||||
-rw-r--r-- | morphlib/git.py | 7 | ||||
-rw-r--r-- | morphlib/localrepocache.py | 10 | ||||
-rw-r--r-- | morphlib/localrepocache_tests.py | 5 |
5 files changed, 30 insertions, 5 deletions
diff --git a/morphlib/cachedrepo.py b/morphlib/cachedrepo.py index c40cb657..0b5ce60f 100644 --- a/morphlib/cachedrepo.py +++ b/morphlib/cachedrepo.py @@ -102,6 +102,7 @@ class CachedRepo(object): self.original_name = original_name self.url = url self.path = path + self.is_mirror = not url.startswith('file://') def resolve_ref(self, ref): '''Attempts to resolve a ref into its SHA1 and tree SHA1. @@ -223,6 +224,9 @@ class CachedRepo(object): ''' + if not self.is_mirror: + return + try: self._update() except cliapp.AppException, e: @@ -260,7 +264,8 @@ class CachedRepo(object): def _copy_repository(self, source_dir, target_dir): # pragma: no cover try: - morphlib.git.copy_repository(self._runcmd, source_dir, target_dir) + morphlib.git.copy_repository( + self._runcmd, source_dir, target_dir, self.is_mirror) except cliapp.AppException: raise CopyError(self, target_dir) diff --git a/morphlib/cachedrepo_tests.py b/morphlib/cachedrepo_tests.py index 0ca0882f..81673880 100644 --- a/morphlib/cachedrepo_tests.py +++ b/morphlib/cachedrepo_tests.py @@ -246,6 +246,12 @@ class CachedRepoTests(unittest.TestCase): self.repo._update = self.update_with_failure self.assertRaises(cachedrepo.UpdateError, self.repo.update) + def test_no_update_if_local(self): + self.repo = cachedrepo.CachedRepo( + object(), 'local:repo', 'file:///local/repo/', '/local/repo/') + self.repo._update = self.update_with_failure + self.repo.update() + def test_clone_checkout(self): self.repo.clone_checkout('master', '/.DOES_NOT_EXIST') self.assertEqual(self.clone_target, '/.DOES_NOT_EXIST') diff --git a/morphlib/git.py b/morphlib/git.py index 973e4af7..7985b815 100644 --- a/morphlib/git.py +++ b/morphlib/git.py @@ -175,13 +175,18 @@ def set_remote(runcmd, gitdir, name, url): return runcmd(['git', 'remote', 'set-url', name, url], cwd=gitdir) -def copy_repository(runcmd, repo, destdir): +def copy_repository(runcmd, repo, destdir, is_mirror=True): '''Copies a cached repository into a directory using cp. This also fixes up the repository afterwards, so that it can contain code etc. It does not leave any given branch ready for use. ''' + if is_mirror == False: + runcmd(['cp', '-a', os.path.join(repo, '.git'), + os.path.join(destdir, '.git')]) + return + runcmd(['cp', '-a', repo, os.path.join(destdir, '.git')]) # core.bare should be false so that git believes work trees are possible runcmd(['git', 'config', 'core.bare', 'false'], cwd=destdir) diff --git a/morphlib/localrepocache.py b/morphlib/localrepocache.py index ae5fa655..465e9f03 100644 --- a/morphlib/localrepocache.py +++ b/morphlib/localrepocache.py @@ -193,9 +193,13 @@ class LocalRepoCache(object): return quote_url(url) def _cache_name(self, url): - basename = self._escape(url) - path = os.path.join(self._cachedir, basename) - return path + scheme, netloc, path, query, fragment = urlparse.urlsplit(url) + if scheme == 'file': + return path + else: + basename = self._escape(url) + path = os.path.join(self._cachedir, basename) + return path def has_repo(self, reponame): '''Have we already got a cache of a given repo?''' diff --git a/morphlib/localrepocache_tests.py b/morphlib/localrepocache_tests.py index 26a92616..6c5410ce 100644 --- a/morphlib/localrepocache_tests.py +++ b/morphlib/localrepocache_tests.py @@ -163,3 +163,8 @@ class LocalRepoCacheTests(unittest.TestCase): def test_noremote_error_message_contains_repo_name(self): e = morphlib.localrepocache.NoRemote(self.repourl, []) self.assertTrue(self.repourl in str(e)) + + def test_avoids_caching_local_repo(self): + self.lrc.cache_repo('file:///local/repo') + cached = self.lrc.get_repo('file:///local/repo') + assert cached.path == '/local/repo' |