def test_write_tree_subdirs(self): gitdir = repo_create(".") mode100644 = stat.S_IFREG | stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH quote = pathlib.Path("quote.txt") self.fs.create_file(quote, contents="that's what she said", st_mode=mode100644) letters = pathlib.Path("alphabeta") / "letters.txt" self.fs.create_file(letters, contents="abcdefg", st_mode=mode100644) digits = pathlib.Path("numbers") / "digits.txt" self.fs.create_file(digits, contents="1234567890", st_mode=mode100644) add(gitdir, [quote, letters, digits]) entries = read_index(gitdir) sha = write_tree(gitdir, entries) self.assertEqual("a9cde03408c68cbb205b038140b4c3a38aa1d01a", sha) alphabeta_tree_sha = "7926bf494dcdb82261e1ca113116610f8d05470b" alphabeta_tree_obj = gitdir / "objects" / alphabeta_tree_sha[: 2] / alphabeta_tree_sha[ 2:] self.assertTrue(alphabeta_tree_obj.exists()) numbers_tree_sha = "32ad3641a773ce34816dece1ce63cc24c8a514d0" numbers_tree_obj = gitdir / "objects" / numbers_tree_sha[: 2] / numbers_tree_sha[ 2:] self.assertTrue(numbers_tree_obj.exists())
def test_cat_tree_file(self): gitdir = repo.repo_create(".") mode100644 = stat.S_IFREG | stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH quote = pathlib.Path("quote.txt") self.fs.create_file(quote, contents="that's what she said", st_mode=mode100644) letters = pathlib.Path("alphabeta") / "letters.txt" self.fs.create_file(letters, contents="abcdefg", st_mode=mode100644) digits = pathlib.Path("numbers") / "digits.txt" self.fs.create_file(digits, contents="1234567890", st_mode=mode100644) index.add(gitdir, [quote, letters, digits]) entries = index.read_index(gitdir) sha = tree.write_tree(gitdir, entries) self.assertEqual("a9cde03408c68cbb205b038140b4c3a38aa1d01a", sha) expected_output = "\n".join( [ "040000 tree 7926bf494dcdb82261e1ca113116610f8d05470b\talphabeta", "040000 tree 32ad3641a773ce34816dece1ce63cc24c8a514d0\tnumbers", "100644 blob 7e774cf533c51803125d4659f3488bd9dffc41a6\tquote.txt", ] ) with patch("sys.stdout", new=io.StringIO()) as out: objects.cat_file(sha, pretty=True) self.assertEqual(expected_output, out.getvalue().strip())
def test_write_tree(self): gitdir = repo_create(".") animals = pathlib.Path("animals.txt") mode100644 = stat.S_IFREG | stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH self.fs.create_file( animals, contents="Big blue basilisks bawl in the basement\n", st_mode=mode100644, ) add(gitdir, [animals]) entries = read_index(gitdir) sha = write_tree(gitdir, entries) self.assertEqual("dc6b8ea09fb7573a335c5fb953b49b85bb6ca985", sha)
def test_add(self): gitdir = repo_create(".") index = gitdir / "index" quote = pathlib.Path("quote.txt") self.fs.create_file(quote, contents="that's what she said") self.assertFalse(index.exists()) add(gitdir, [quote]) self.assertTrue(index.exists()) entries = read_index(gitdir) self.assertEqual(1, len(entries)) expected_sha = "7e774cf533c51803125d4659f3488bd9dffc41a6" obj_path = gitdir / "objects" / expected_sha[:2] / expected_sha[2:] self.assertTrue(obj_path.exists())
def test_add_many(self): gitdir = repo_create(".") index = gitdir / "index" letters = pathlib.Path("letters.txt") self.fs.create_file(letters, contents="abcdefg") digits = pathlib.Path("digits.txt") self.fs.create_file(digits, contents="1234567890") self.assertFalse(index.exists()) add(gitdir, [letters, digits]) self.assertTrue(index.exists()) entries = read_index(gitdir) self.assertEqual(2, len(entries)) names = [e.name for e in entries] self.assertEqual(["digits.txt", "letters.txt"], names)
def test_add_subdirs(self): gitdir = repo_create(".") index = gitdir / "index" quote = pathlib.Path("quote.txt") self.fs.create_file(quote, contents="that's what she said") letters = pathlib.Path("alphabeta") / "letters.txt" self.fs.create_file(letters, contents="abcdefg") digits = pathlib.Path("numbers") / "digits.txt" self.fs.create_file(digits, contents="1234567890") self.assertFalse(index.exists()) add(gitdir, [quote, letters, digits]) self.assertTrue(index.exists()) entries = read_index(gitdir) self.assertEqual(3, len(entries)) names = [e.name for e in entries] self.assertEqual( ["alphabeta/letters.txt", "numbers/digits.txt", "quote.txt"], names)