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


Golang Repo.Checkout方法代码示例

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


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

示例1: runPrePush

func (a *application) runPrePush(repo scm.Repo) (err error) {
	previous := scm.Head
	// Will be "" if the current checkout was detached.
	previousRef := repo.Ref(scm.Head)
	curr := previous
	stashed := false
	defer func() {
		if curr != previous {
			p := previousRef
			if p == "" {
				p = string(previous)
			}
			if err2 := repo.Checkout(p); err == nil {
				err = err2
			}
		}
		if stashed {
			if err2 := repo.Restore(); err == nil {
				err = err2
			}
		}
	}()

	bio := bufio.NewReader(os.Stdin)
	line := ""
	triedToStash := false
	for {
		if line, err = bio.ReadString('\n'); err != nil {
			break
		}
		matches := rePrePush.FindStringSubmatch(line[:len(line)-1])
		if len(matches) != 5 {
			return fmt.Errorf("unexpected stdin for pre-push: %q", line)
		}
		from := scm.Commit(matches[4])
		to := scm.Commit(matches[2])
		if to == gitNilCommit {
			// It's being deleted.
			continue
		}
		if to != curr {
			// Stash, checkout, run tests.
			if !triedToStash {
				// Only try to stash once.
				triedToStash = true
				if stashed, err = repo.Stash(); err != nil {
					return
				}
			}
			curr = to
			if err = repo.Checkout(string(to)); err != nil {
				return
			}
		}
		if from == gitNilCommit {
			from = scm.Initial
		}
		change, err := repo.Between(to, from, a.config.IgnorePatterns)
		if err != nil {
			return err
		}
		if err = a.runChecks(change, []checks.Mode{checks.PrePush}, &sync.WaitGroup{}); err != nil {
			return err
		}
	}
	if err == io.EOF {
		err = nil
	}
	return
}
开发者ID:nodirt,项目名称:pre-commit-go,代码行数:70,代码来源:main.go


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