当前位置: 首页>>代码示例>>Golang>>正文


Golang Repository.GetCommitOfBranch方法代码示例

本文整理汇总了Golang中github.com/driusan/git.Repository.GetCommitOfBranch方法的典型用法代码示例。如果您正苦于以下问题:Golang Repository.GetCommitOfBranch方法的具体用法?Golang Repository.GetCommitOfBranch怎么用?Golang Repository.GetCommitOfBranch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/driusan/git.Repository的用法示例。


在下文中一共展示了Repository.GetCommitOfBranch方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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.")
}
开发者ID:driusan,项目名称:go-git,代码行数:37,代码来源:merge.go


注:本文中的github.com/driusan/git.Repository.GetCommitOfBranch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。