diff options
-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 | ||||
-rw-r--r-- | tests.branching/branch-creates-new-system-branch-not-from-master.stdout | 1 | ||||
-rw-r--r-- | tests.branching/branch-creates-new-system-branch.stdout | 1 | ||||
-rw-r--r-- | tests.branching/branch-works-anywhere.stdout | 4 | ||||
-rw-r--r-- | tests.branching/checkout-existing-branch.stdout | 1 | ||||
-rw-r--r-- | tests.branching/checkout-works-anywhere.stdout | 2 | ||||
-rw-r--r-- | tests.branching/edit-works-after-branch-root-was-renamed.stdout | 2 |
11 files changed, 30 insertions, 16 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' diff --git a/tests.branching/branch-creates-new-system-branch-not-from-master.stdout b/tests.branching/branch-creates-new-system-branch-not-from-master.stdout index 948c5d19..d80f81d7 100644 --- a/tests.branching/branch-creates-new-system-branch-not-from-master.stdout +++ b/tests.branching/branch-creates-new-system-branch-not-from-master.stdout @@ -3,7 +3,6 @@ d . d ./.morph d ./.morph/cache d ./.morph/cache/gits -d ./.morph/cache/gits/file_morphs d ./newbranch d ./newbranch/.morph-system-branch d ./newbranch/test:morphs diff --git a/tests.branching/branch-creates-new-system-branch.stdout b/tests.branching/branch-creates-new-system-branch.stdout index bc4bf568..7c6b3065 100644 --- a/tests.branching/branch-creates-new-system-branch.stdout +++ b/tests.branching/branch-creates-new-system-branch.stdout @@ -3,7 +3,6 @@ d . d ./.morph d ./.morph/cache d ./.morph/cache/gits -d ./.morph/cache/gits/file_morphs d ./newbranch d ./newbranch/.morph-system-branch d ./newbranch/test:morphs diff --git a/tests.branching/branch-works-anywhere.stdout b/tests.branching/branch-works-anywhere.stdout index 3470a804..41f30440 100644 --- a/tests.branching/branch-works-anywhere.stdout +++ b/tests.branching/branch-works-anywhere.stdout @@ -3,7 +3,6 @@ d . d ./.morph d ./.morph/cache d ./.morph/cache/gits -d ./.morph/cache/gits/file_morphs d ./branch1 d ./branch1/.morph-system-branch d ./branch1/test:morphs @@ -16,7 +15,6 @@ d . d ./.morph d ./.morph/cache d ./.morph/cache/gits -d ./.morph/cache/gits/file_morphs d ./branch1 d ./branch1/.morph-system-branch d ./branch1/test:morphs @@ -36,7 +34,6 @@ d . d ./.morph d ./.morph/cache d ./.morph/cache/gits -d ./.morph/cache/gits/file_morphs d ./branch1 d ./branch1/.morph-system-branch d ./branch1/test:morphs @@ -63,7 +60,6 @@ d . d ./.morph d ./.morph/cache d ./.morph/cache/gits -d ./.morph/cache/gits/file_morphs d ./branch1 d ./branch1/.morph-system-branch d ./branch1/test:morphs diff --git a/tests.branching/checkout-existing-branch.stdout b/tests.branching/checkout-existing-branch.stdout index 60fca613..50bd01ab 100644 --- a/tests.branching/checkout-existing-branch.stdout +++ b/tests.branching/checkout-existing-branch.stdout @@ -3,7 +3,6 @@ d . d ./.morph d ./.morph/cache d ./.morph/cache/gits -d ./.morph/cache/gits/file_morphs d ./master d ./master/.morph-system-branch d ./master/test:morphs diff --git a/tests.branching/checkout-works-anywhere.stdout b/tests.branching/checkout-works-anywhere.stdout index 6e82072a..15ae3686 100644 --- a/tests.branching/checkout-works-anywhere.stdout +++ b/tests.branching/checkout-works-anywhere.stdout @@ -3,7 +3,6 @@ d . d ./.morph d ./.morph/cache d ./.morph/cache/gits -d ./.morph/cache/gits/file_morphs d ./master d ./master/.morph-system-branch d ./master/test:morphs @@ -16,7 +15,6 @@ d . d ./.morph d ./.morph/cache d ./.morph/cache/gits -d ./.morph/cache/gits/file_morphs d ./master d ./master/.morph-system-branch d ./master/test:morphs diff --git a/tests.branching/edit-works-after-branch-root-was-renamed.stdout b/tests.branching/edit-works-after-branch-root-was-renamed.stdout index 549c1c34..1436414d 100644 --- a/tests.branching/edit-works-after-branch-root-was-renamed.stdout +++ b/tests.branching/edit-works-after-branch-root-was-renamed.stdout @@ -2,8 +2,6 @@ d . d ./.morph d ./.morph/cache d ./.morph/cache/gits -d ./.morph/cache/gits/file_hello -d ./.morph/cache/gits/file_morphs d ./master d ./master/.morph-system-branch d ./master/my-renamed-morphs |