Exemplo n.º 1
0
    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)
        update_index(gitdir, [quote, letters, digits], write=True)
        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())
Exemplo n.º 2
0
def commit(gitdir: pathlib.Path,
           message: str,
           author: tp.Optional[str] = None) -> str:
    tree = write_tree(gitdir, read_index(gitdir), str(gitdir.parent))
    parent_commit = resolve_head(gitdir)
    commit_hash = commit_tree(gitdir, tree, message, parent_commit, author)
    return commit_hash
Exemplo n.º 3
0
def commit(gitdir: pathlib.Path,
           message: str,
           author: tp.Optional[str] = None) -> str:
    # PUT YOUR CODE HERE
    tree = write_tree(gitdir, read_index(gitdir))
    commit = commit_tree(gitdir, tree, message, author=author)
    return commit
Exemplo n.º 4
0
def commit(gitdir: pathlib.Path,
           message: str,
           author: tp.Optional[str] = None) -> str:
    hash_commit = commit_tree(
        gitdir, write_tree(gitdir, read_index(gitdir), str(gitdir.parent)),
        message, resolve_head(gitdir), author)
    return hash_commit
Exemplo n.º 5
0
    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.update_index(gitdir, [quote, letters, digits], write=True)
        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())
Exemplo n.º 6
0
def commit(gitdir: pathlib.Path, message: str, author: tp.Optional[str] = None) -> str:
    index = read_index(gitdir)
    return commit_tree(
    gitdir=gitdir,
    tree=write_tree(gitdir, index),
    message=message,
    author=author)
Exemplo n.º 7
0
def commit(gitdir: pathlib.Path,
           message: str,
           author: tp.Optional[str] = None) -> str:
    # PUT YOUR CODE HERE
    parent = resolve_head(gitdir)
    tree = write_tree(gitdir, read_index(gitdir), str(gitdir.parent))
    com = commit_tree(gitdir, tree, message, parent, author)
    return com
Exemplo n.º 8
0
def commit(gitdir: pathlib.Path, message: str, author: tp.Optional[str] = None) -> str:
    commit_sha = commit_tree(gitdir, write_tree(gitdir, read_index(gitdir)), message, author=author)
    if is_detached(gitdir):
        ref = gitdir / "HEAD"
    else:
        ref = pathlib.Path(get_ref(gitdir))
    f = open(gitdir / ref, "w")
    f.write(commit_sha)
    f.close()
    return commit_sha
Exemplo n.º 9
0
 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,
     )
     update_index(gitdir, [animals], write=True)
     entries = read_index(gitdir)
     sha = write_tree(gitdir, entries)
     self.assertEqual("dc6b8ea09fb7573a335c5fb953b49b85bb6ca985", sha)
Exemplo n.º 10
0
def commit(gitdir: pathlib.Path,
           message: str,
           author: tp.Optional[str] = None) -> str:
    # делаем сам коммит
    files_in_index = read_index(gitdir)
    tree_hash = write_tree(gitdir, files_in_index)
    parent = resolve_head(gitdir)
    commit_sha = commit_tree(gitdir,
                             tree_hash,
                             message,
                             parent=parent,
                             author=author)
    update_ref(gitdir, get_ref(gitdir), commit_sha)
    return commit_sha
Exemplo n.º 11
0
def commit(gitdir: pathlib.Path,
           message: str,
           author: tp.Optional[str] = None) -> str:
    tree = write_tree(gitdir, read_index(gitdir))
    return commit_tree(gitdir, tree, message, parent=None, author=author)
Exemplo n.º 12
0
def cmd_write_tree(args: argparse.Namespace) -> None:
    gitdir = repo_find()
    entries = read_index(gitdir)
    sha = write_tree(gitdir, entries)
    print(sha)