X-Git-Url: http://git.scottworley.com/git-cache/blobdiff_plain/bef7ce53ce70499b4f13985cc9d4b64e2d8aace4..866f291808c96e89c86adaa63634d89a58526ec7:/test_git_cache.py?ds=inline diff --git a/test_git_cache.py b/test_git_cache.py index 7408cad..caac6a3 100644 --- a/test_git_cache.py +++ b/test_git_cache.py @@ -10,7 +10,7 @@ import git_cache def _git(directory: str, *args: str) -> bytes: p = subprocess.run(['git', '-C', directory] + list(args), stdout=subprocess.PIPE, check=True) - return p.stdout + return bytes(p.stdout) def _commit_file( @@ -37,6 +37,8 @@ class TestGitCache(unittest.TestCase): os.environ['GIT_AUTHOR_EMAIL'] = 'test_git_cache@example.com' os.environ['GIT_COMMITTER_EMAIL'] = 'test_git_cache@example.com' + os.environ['BACKOFF_MAX_TIME'] = '0' + self.tempdir = tempfile.TemporaryDirectory(prefix='git_cache_test-') self.upstream = os.path.join(self.tempdir.name, 'upstream') subprocess.run(['git', 'init', self.upstream], check=True) @@ -157,6 +159,17 @@ class TestGitCache(unittest.TestCase): d = git_cache.ensure_rev_available(self.upstream, 'otherbranch', rev) self.assertEqual(_git(d, 'show', '%s:foofile' % rev), b'foo') + def test_catch_up(self) -> None: + _git(self.upstream, 'checkout', '-b', 'otherbranch') + _commit_file(self.upstream, 'foofile', 'foo', 'Foo') + rev = _git(self.upstream, 'log', '--format=%H', '-n1').strip().decode() + d = git_cache.ensure_rev_available(self.upstream, 'otherbranch', rev) + self.assertEqual(_git(d, 'show', '%s:foofile' % rev), b'foo') + _git(self.upstream, 'checkout', 'master') + _git(self.upstream, 'merge', '--ff-only', 'otherbranch') + d = git_cache.ensure_rev_available(self.upstream, 'master', rev) + self.assertEqual(_git(d, 'show', '%s:foofile' % rev), b'foo') + def test_fetch_after_cache_deleted(self) -> None: d1, rev1 = git_cache.fetch(self.upstream, 'master') shutil.rmtree(d1)