本文整理汇总了Golang中github.com/driusan/git.Repository.GetCommit方法的典型用法代码示例。如果您正苦于以下问题:Golang Repository.GetCommit方法的具体用法?Golang Repository.GetCommit怎么用?Golang Repository.GetCommit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/driusan/git.Repository
的用法示例。
在下文中一共展示了Repository.GetCommit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: resetIndexFromCommit
func resetIndexFromCommit(repo *libgit.Repository, commitId string) error {
// If the index doesn't exist, idx is a new index, so ignore
// the path error that ReadIndex is returning
idx, _ := ReadIndex(repo)
com, err := repo.GetCommit(commitId)
if err != nil {
fmt.Printf("%s\n", err)
return err
}
treeId := com.TreeId()
tree := libgit.NewTree(repo, treeId)
if tree == nil {
panic("Error retriving tree for commit")
}
idx.ResetIndex(repo, tree)
writeIndex(repo, idx, "index")
return nil
}
示例2: Merge
func Merge(repo *libgit.Repository, args []string) {
if len(args) != 1 {
fmt.Fprintf(os.Stderr, "Usage: go-git merge branchname\n")
return
}
commit, err := repo.GetCommitOfBranch(args[0])
if err != nil {
fmt.Fprintf(os.Stderr, "Invalid branch: %s\n", args[0])
return
}
head, err := getHeadId(repo)
if err != nil {
panic(err)
}
// The current branch is an ancestor of HEAD. This
// is a fast-forward.
if headCom, err := repo.GetCommit(head); err == nil {
if isAncestor(headCom, fmt.Sprintf("%s", commit.Id)) {
fmt.Fprintf(os.Stderr, "Already up-to-date.\n")
return
}
}
// Head is an ancestor of the current branch.
if isAncestor(commit, head) {
hb := getHeadBranch(repo)
newId := fmt.Sprintf("%s", commit.Id)
ioutil.WriteFile(".git/refs/heads/"+hb, []byte(newId), 0644)
resetIndexFromCommit(repo, newId)
fmt.Printf("Hooray! A Fast forward on %s! New should should be %s\n", hb, commit.Id)
return
}
panic("Only fast forward commits are currently supported.")
}