Create new branch without a commit?
I read code here and found each create new branch required a commit.
def create(self, name, commit, force=False):
return self._repository.create_branch(name, commit, force)
How create new branch without commit?
you can use this code to create a branch without commit
repo = pygit2.Repository(repo_path)
index = repo.index
tree = index.write_tree()
repo.create_reference_direct('refs/heads/branch_name',tree,False)
Somehow that propose solution is not trivial, isn't there a way to get a commit from an existing branch and use that as the commit parameter to create_branch?
new_branch = repoObj.create_branch(new_branch, repoObj.branches[ws.getRepoTargetBranch(repoName))
I am unclear how to get a Commit object the API, the above give the error that the 2nd param is a branch not a Commit, but can't find how to convert a branch which normally points to a commit to a Commit object, seems something is missing in the API.
I was able to create a branch this way:
commit = repoObj.revparse_single('HEAD') new_branch = repoObj.create_branch(new_branch, commit)
Somehow there should be a default value to "create_branch" which is to take the current commit we are at in the repo...