本文整理汇总了Golang中github.com/maruel/pre-commit-go/scm.Repo.HEAD方法的典型用法代码示例。如果您正苦于以下问题:Golang Repo.HEAD方法的具体用法?Golang Repo.HEAD怎么用?Golang Repo.HEAD使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/maruel/pre-commit-go/scm.Repo
的用法示例。
在下文中一共展示了Repo.HEAD方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: runPreCommit
func runPreCommit(repo scm.Repo, config *checks.Config) error {
// First, stash index and work dir, keeping only the to-be-committed changes
// in the working directory.
stashed, err := repo.Stash()
if err != nil {
return err
}
// Run the checks.
var change scm.Change
change, err = repo.Between(scm.Current, repo.HEAD(), config.IgnorePatterns)
if change != nil {
err = runChecks(config, change, []checks.Mode{checks.PreCommit}, &sync.WaitGroup{})
}
// If stashed is false, everything was in the index so no stashing was needed.
if stashed {
if err2 := repo.Restore(); err == nil {
err = err2
}
}
return err
}
示例2: runPrePush
func runPrePush(repo scm.Repo, config *checks.Config) (err error) {
previous := repo.HEAD()
// Will be "" if the current checkout was detached.
previousRef := repo.Ref()
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.GitInitialCommit
}
change, err := repo.Between(to, from, config.IgnorePatterns)
if err != nil {
return err
}
if err = runChecks(config, change, []checks.Mode{checks.PrePush}, &sync.WaitGroup{}); err != nil {
return err
}
}
if err == io.EOF {
err = nil
}
return
}