Exemplo n.º 1
0
 def test_simple(self):
     [c1] = build_commit_graph(self.repo.object_store, [[1]])
     self.repo[b"HEAD"] = c1.id
     porcelain.branch_create(self.repo, b'foo')
     self.assertTrue(b"foo" in porcelain.branch_list(self.repo))
     porcelain.branch_delete(self.repo, b'foo')
     self.assertFalse(b"foo" in porcelain.branch_list(self.repo))
Exemplo n.º 2
0
    def branch(self, branch: str):
        from dulwich.porcelain import Error, branch_create

        try:
            branch_create(self.root_dir, branch)
        except Error as exc:
            raise SCMError(f"Failed to create branch '{branch}'") from exc
Exemplo n.º 3
0
 def test_new_branch(self):
     [c1] = build_commit_graph(self.repo.object_store, [[1]])
     self.repo[b"HEAD"] = c1.id
     porcelain.branch_create(self.repo, b"foo")
     self.assertEqual(
         set([b"master", b"foo"]),
         set(porcelain.branch_list(self.repo)))
Exemplo n.º 4
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()
Exemplo n.º 5
0
def prepare_local_dir(in_dir):
    init(in_dir)
    add(in_dir, in_dir)
    commit(in_dir, "adding files")
    branch_create(in_dir, 'gh-pages')

    r = open_repo(in_dir)
    r.reset_index(r[b"refs/heads/gh-pages"].tree)
    r.refs.set_symbolic_ref(b"HEAD", b"refs/heads/gh-pages")
Exemplo n.º 6
0
 def test_branch_exists(self):
     [c1] = build_commit_graph(self.repo.object_store, [[1]])
     self.repo[b"HEAD"] = c1.id
     porcelain.branch_create(self.repo, b"foo")
     self.assertRaises(KeyError, porcelain.branch_create, self.repo, b"foo")
     porcelain.branch_create(self.repo, b"foo", force=True)
Exemplo n.º 7
0
 def branch_create(self, name):
     git.branch_create(self, name)
Exemplo n.º 8
0
def create_branch(branch_name):
    porcelain.branch_create(REPO_PATH, branch_name)
    print('branch {} created'.format(branch_name))
    porcelain.push(REPO_PATH, URL, branch_name.encode())
    print('branch {} pushed'.format(branch_name))
Exemplo n.º 9
0
 def branch_create(self, name):
     repo = self.repo
     git.branch_create(repo, name)
Exemplo n.º 10
0
if args.sourceDirectory is None:
    sourceRepositories = get_repos(args.sourcePrefix, operator.eq, 1, args.sourceOrg)
    source_path = temp_dir + sourceRepositories[0].name
    dulwich_repo = porcelain.clone(sourceRepositories[0].ssh_url, source_path)
    os.system(f"cd {source_path}; git fetch origin {args.sourceBranch}; git checkout {args.sourceBranch}")
else:
    source_path = args.sourceDirectory

for github_repo in destinationRepositories:
    destination_path = temp_dir + github_repo.name
    dulwich_repo = porcelain.clone(github_repo.ssh_url, destination_path)

    # switch to destination branch
    os.system(f"cd {destination_path}; git fetch origin {args.destinationBranch}; git checkout {args.destinationBranch}")

    porcelain.branch_create(destination_path, args.temporaryBranch)
    switch_branch(dulwich_repo, args.temporaryBranch)

    if args.sourcePrefix == "grace-actions":
        args.script = "python3 " + path.join(source_path, "actions", "run.py")

        # TODO allow relative paths for the request.json file
        args.scriptParameters = args.scriptParameters + f" --action {args.actionType}"
    else:
        args.script = path.join("~/.local/bin", args.script + ".py")

    command = f"{args.script} {args.scriptParameters} --src-dir={source_path} --dst-dir={destination_path}"
    # FIXME fix race condition with transformer for print statements
    termcolor.colored(f"Running transformer with command '{command}'", "yellow")
    process = subprocess.Popen(
        [command],
Exemplo n.º 11
0
     outstream	Output stream (defaults to stdout)
     errstream	Error stream (defaults to stderr)
     Returns	Dictionary with refs on the remote
     """
     porcelain.fetch(repoPath,
                     remote)  # remote should be the host etc from a stanze
 elif command == "createbranch":
     """
     def branch_create(repo, name, objectish=None, force=False):
     Create a branch.
     Parameters	repo	Path to the repository
     name	Name of the new branch
     objectish	Target object to point new branch at (defaults to HEAD)
     force	Force creation of branch, even if it already exists   
     """
     porcelain.branch_create(repoPath, branch)
 elif command == "deletebranch":
     """
     def branch_delete(repo, name):
     Delete a branch.
     Parameters	repo	Path to the repository
     name	Name of the branch
     """
     porcelain.branch_delete(repoPath, branch)
 elif command == "printcommit":
     """
     def print_commit(commit, decode, outstream=sys.stdout):
     Write a human-readable commit log entry.
     Parameters	commit	A Commit object
     outstream	A stream file to write to
     """
Exemplo n.º 12
0
def create_branch(repo, branch, force=False):
    porcelain.branch_create(repo, branch, force=force)