• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang scm.Repo类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: cmdRunHook

// cmdRunHook runs the checks in a git repository.
//
// Use a precise "stash, run checks, unstash" to ensure that the check is
// properly run on the data in the index.
func (a *application) cmdRunHook(repo scm.Repo, mode string, noUpdate bool) error {
	switch checks.Mode(mode) {
	case checks.PreCommit:
		return a.runPreCommit(repo)

	case checks.PrePush:
		return a.runPrePush(repo)

	case checks.ContinuousIntegration:
		// Always runs all tests on CI.
		change, err := repo.Between(scm.Current, scm.Initial, a.config.IgnorePatterns)
		if err != nil {
			return err
		}
		mode := []checks.Mode{checks.ContinuousIntegration}

		// This is a special case, some users want reproducible builds and in this
		// case they do not want any external reference and want to enforce
		// noUpdate, but many people may not care (yet). So default to fetching but
		// it can be overriden.
		var prereqReady sync.WaitGroup
		errCh := make(chan error, 1)
		prereqReady.Add(1)
		go func() {
			defer prereqReady.Done()
			errCh <- a.cmdInstallPrereq(repo, mode, noUpdate)
		}()
		err = a.runChecks(change, mode, &prereqReady)
		if err2 := <-errCh; err2 != nil {
			return err2
		}
		return err

	default:
		return errors.New("unsupported hook type for run-hook")
	}
}
开发者ID:nodirt,项目名称:pre-commit-go,代码行数:41,代码来源:main.go


示例2: 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
}
开发者ID:Hanxueying,项目名称:pre-commit-go,代码行数:21,代码来源:main.go


示例3: runPreCommit

func (a *application) runPreCommit(repo scm.Repo) error {
	// First, stash index and work dir, keeping only the to-be-committed changes
	// in the working directory.
	// TODO(maruel): When running for an git commit --amend run, use HEAD~1.
	stashed, err := repo.Stash()
	if err != nil {
		return err
	}
	// Run the checks.
	var change scm.Change
	change, err = repo.Between(scm.Current, scm.Head, a.config.IgnorePatterns)
	if change != nil {
		err = a.runChecks(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
}
开发者ID:nodirt,项目名称:pre-commit-go,代码行数:22,代码来源:main.go


示例4: 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类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang subcommands.Application类代码示例发布时间:2022-05-23
下一篇:
Golang scm.ReadOnlyRepo类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap