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


Golang ReadOnlyRepo.Root方法代码示例

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


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

示例1: loadConfig

// loadConfig loads the on disk configuration or use the default configuration
// if none is found. See CONFIGURATION.md for the logic.
func loadConfig(repo scm.ReadOnlyRepo, path string) (string, *checks.Config) {
	if filepath.IsAbs(path) {
		if config := loadConfigFile(path); config != nil {
			return path, config
		}
	} else {
		// <repo root>/.git/<path>
		if scmDir, err := repo.ScmDir(); err == nil {
			file := filepath.Join(scmDir, path)
			if config := loadConfigFile(file); config != nil {
				return file, config
			}
		}

		// <repo root>/<path>
		file := filepath.Join(repo.Root(), path)
		if config := loadConfigFile(file); config != nil {
			return file, config
		}

		if user, err := user.Current(); err == nil && user.HomeDir != "" {
			if runtime.GOOS == "windows" {
				// ~/<path>
				file = filepath.Join(user.HomeDir, path)
			} else {
				// ~/.config/<path>
				file = filepath.Join(user.HomeDir, ".config", path)
			}
			if config := loadConfigFile(file); config != nil {
				return file, config
			}
		}
	}
	return "<N/A>", checks.New(version)
}
开发者ID:nodirt,项目名称:pre-commit-go,代码行数:37,代码来源:main.go

示例2: Capture

// Capture sets GOPATH and executes a subprocess.
func (o *Options) Capture(r scm.ReadOnlyRepo, args ...string) (string, int, time.Duration, error) {
	o.LeaseRunToken()
	defer o.ReturnRunToken()

	start := time.Now()
	out, exitCode, err := internal.Capture(r.Root(), []string{"GOPATH=" + r.GOPATH()}, args...)
	return out, exitCode, time.Since(start), err
}
开发者ID:nodirt,项目名称:pre-commit-go,代码行数:9,代码来源:config.go

示例3: cmdInfo

// cmdInfo displays the current configuration used.
func (a *application) cmdInfo(repo scm.ReadOnlyRepo, modes []checks.Mode, configPath string) error {
	fmt.Printf("File: %s\n", configPath)
	fmt.Printf("Repo: %s\n", repo.Root())

	fmt.Printf("MinVersion: %s\n", a.config.MinVersion)
	content, err := yaml.Marshal(a.config.IgnorePatterns)
	if err != nil {
		return err
	}
	fmt.Printf("IgnorePatterns:\n%s", content)

	if len(modes) == 0 {
		modes = checks.AllModes
	}
	for _, mode := range modes {
		settings := a.config.Modes[mode]
		maxLen := 0
		for _, checks := range settings.Checks {
			for _, check := range checks {
				if l := len(check.GetName()); l > maxLen {
					maxLen = l
				}
			}
		}
		fmt.Printf("\n%s:\n  %-*s %d seconds\n", mode, maxLen+1, "Limit:", settings.Options.MaxDuration)
		for _, checks := range settings.Checks {
			for _, check := range checks {
				name := check.GetName()
				fmt.Printf("  %s:%s %s\n", name, strings.Repeat(" ", maxLen-len(name)), check.GetDescription())
				content, err := yaml.Marshal(check)
				if err != nil {
					return err
				}
				options := strings.TrimSpace(string(content))
				if options == "{}" {
					// It means there's no options.
					options = "<no option>"
				}
				lines := strings.Join(strings.Split(options, "\n"), "\n    ")
				fmt.Printf("    %s\n", lines)
			}
		}
	}
	return nil
}
开发者ID:nodirt,项目名称:pre-commit-go,代码行数:46,代码来源:main.go

示例4: capture

// capture sets GOPATH.
func capture(r scm.ReadOnlyRepo, args ...string) (string, int, error) {
	return internal.Capture(r.Root(), []string{"GOPATH=" + r.GOPATH()}, args...)
}
开发者ID:jjpeters67,项目名称:pre-commit-go,代码行数:4,代码来源:utils.go


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