Ejemplo n.º 1
0
 def test_set_new_branch(self):
     [c1] = build_commit_graph(self.repo.object_store, [[1]])
     self.repo.refs[b"refs/heads/blah"] = c1.id
     porcelain.update_head(self.repo, "blah", new_branch="bar")
     self.assertEqual(c1.id, self.repo.head())
     self.assertEqual(b'ref: refs/heads/bar',
                      self.repo.refs.read_ref(b'HEAD'))
Ejemplo n.º 2
0
 def test_set_new_branch(self):
     [c1] = build_commit_graph(self.repo.object_store, [[1]])
     self.repo.refs[b"refs/heads/blah"] = c1.id
     porcelain.update_head(self.repo, "blah", new_branch="bar")
     self.assertEqual(c1.id, self.repo.head())
     self.assertEqual(b'ref: refs/heads/bar',
                      self.repo.refs.read_ref(b'HEAD'))
Ejemplo n.º 3
0
def commit_style(repo: Repo, format_rule_name: str) -> Tuple[str, str]:
    """
    Call bash script which commit all changes to `style_name` branch and checkout master back.

    :param repo: Repo instance to the repository for which style were applied.
    :param format_rule_name: Applied format rule name.
    :return: Two commit hashes: where style was applied and where style was disrupt.
    """
    def commit(repo: Repo, msg: str) -> str:
        """Commit everything."""
        for tree_path, entry in repo.open_index().items():
            full_path = os.path.join(repo.path.encode(), tree_path)
            blob = blob_from_path_and_stat(full_path, os.lstat(full_path))
            if blob.id != entry.sha:
                repo.stage(tree_path)
        return repo.do_commit(msg.encode(), b"Source{d} ML Team <*****@*****.**>")

    repopath = repo.path
    base = repo.head()
    branch_create(repopath, format_rule_name, force=True)
    update_head(repopath, format_rule_name)
    style_commit_sha = commit(repo, format_rule_name)
    build_index_from_tree(repo.path, repo.index_path(), repo.object_store, repo[base].tree)
    revert_style_commit_sha = commit(repo, "Revert " + format_rule_name)
    update_head(repopath, b"master")
    return style_commit_sha.decode(), revert_style_commit_sha.decode()
Ejemplo n.º 4
0
 def checkout_branch(self, branch='master'):
     git.update_head(self, branch)
     self.clean()
     co_ref = b'HEAD'
     repo_path = self.path
     from dulwich.repo import Repo
     from dulwich.index import build_index_from_tree
     repo = Repo(repo_path)
     indexfile = repo.index_path()
     obj_sto = repo.object_store
     tree_id = repo[co_ref].tree
     build_index_from_tree(repo_path, indexfile, obj_sto, tree_id)
     x = list(obj_sto.iter_tree_contents(tree_id))
     x = [obj_sto.iter_tree_contents(tree_id)]
Ejemplo n.º 5
0
 def test_set_to_commit_detached(self):
     [c1] = build_commit_graph(self.repo.object_store, [[1]])
     self.repo.refs[b"refs/heads/blah"] = c1.id
     porcelain.update_head(self.repo, c1.id, detached=True)
     self.assertEqual(c1.id, self.repo.head())
     self.assertEqual(c1.id, self.repo.refs.read_ref(b'HEAD'))
Ejemplo n.º 6
0
def pull_branch(branch_name):
    porcelain.pull(REPO_PATH, URL, branch_name.encode())
    porcelain.update_head(REPO_PATH, branch_name)
Ejemplo n.º 7
0
 def test_set_to_commit_detached(self):
     [c1] = build_commit_graph(self.repo.object_store, [[1]])
     self.repo.refs[b"refs/heads/blah"] = c1.id
     porcelain.update_head(self.repo, c1.id, detached=True)
     self.assertEqual(c1.id, self.repo.head())
     self.assertEqual(c1.id, self.repo.refs.read_ref(b'HEAD'))
Ejemplo n.º 8
0
def switch_branch(repo, branch, recover=True):
    porcelain.update_head(repo, branch)
    if recover:
        clean_repo(repo)
        recover_from_head(repo)