]> git.scottworley.com Git - git-cache/blobdiff - test_git_cache.py
Fix bug: Fetch if ancestry check fails
[git-cache] / test_git_cache.py
index ecb11e8e19c9bfd7a1c3ddbab27dd2d5568bdc83..caac6a33289432744717167dc5f0da9c7f397da1 100644 (file)
@@ -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)
 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(
 
 
 def _commit_file(
@@ -159,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')
 
         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)
     def test_fetch_after_cache_deleted(self) -> None:
         d1, rev1 = git_cache.fetch(self.upstream, 'master')
         shutil.rmtree(d1)