本文整理匯總了Golang中github.com/maruel/pre-commit-go/scm.Repo.Ref方法的典型用法代碼示例。如果您正苦於以下問題:Golang Repo.Ref方法的具體用法?Golang Repo.Ref怎麽用?Golang Repo.Ref使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/maruel/pre-commit-go/scm.Repo
的用法示例。
在下文中一共展示了Repo.Ref方法的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
}