當前位置: 首頁>>代碼示例>>Golang>>正文


Golang git.GetVersion函數代碼示例

本文整理匯總了Golang中github.com/gogits/gogs/modules/git.GetVersion函數的典型用法代碼示例。如果您正苦於以下問題:Golang GetVersion函數的具體用法?Golang GetVersion怎麽用?Golang GetVersion使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了GetVersion函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: NewRepoContext

func NewRepoContext() {
	zip.Verbose = false

	// Check Git installation.
	if _, err := exec.LookPath("git"); err != nil {
		log.Fatal(4, "Fail to test 'git' command: %v (forgotten install?)", err)
	}

	// Check Git version.
	ver, err := git.GetVersion()
	if err != nil {
		log.Fatal(4, "Fail to get Git version: %v", err)
	}

	reqVer, err := git.ParseVersion("1.7.1")
	if err != nil {
		log.Fatal(4, "Fail to parse required Git version: %v", err)
	}
	if ver.LessThan(reqVer) {
		log.Fatal(4, "Gogs requires Git version greater or equal to 1.7.1")
	}

	// Check if server has basic git setting and set if not.
	if stdout, stderr, err := process.Exec("NewRepoContext(get setting)", "git", "config", "--get", "user.name"); err != nil || strings.TrimSpace(stdout) == "" {
		// ExitError indicates user.name is not set
		if _, ok := err.(*exec.ExitError); ok || strings.TrimSpace(stdout) == "" {
			stndrdUserName := "Gogs"
			stndrdUserEmail := "[email protected]"
			if _, stderr, gerr := process.Exec("NewRepoContext(set name)", "git", "config", "--global", "user.name", stndrdUserName); gerr != nil {
				log.Fatal(4, "Fail to set git user.name(%s): %s", gerr, stderr)
			}
			if _, stderr, gerr := process.Exec("NewRepoContext(set email)", "git", "config", "--global", "user.email", stndrdUserEmail); gerr != nil {
				log.Fatal(4, "Fail to set git user.email(%s): %s", gerr, stderr)
			}
			log.Info("Git user.name and user.email set to %s <%s>", stndrdUserName, stndrdUserEmail)
		} else {
			log.Fatal(4, "Fail to get git user.name(%s): %s", err, stderr)
		}
	}

	// Set git some configurations.
	if _, stderr, err := process.Exec("NewRepoContext(git config --global core.quotepath false)",
		"git", "config", "--global", "core.quotepath", "false"); err != nil {
		log.Fatal(4, "Fail to execute 'git config --global core.quotepath false': %s", stderr)
	}

}
開發者ID:ericcapricorn,項目名稱:gogs,代碼行數:47,代碼來源:repo.go

示例2: NewRepoContext

func NewRepoContext() {
	zip.Verbose = false

	// Check Git installation.
	if _, err := exec.LookPath("git"); err != nil {
		log.Fatal(4, "Fail to test 'git' command: %v (forgotten install?)", err)
	}

	// Check Git version.
	ver, err := git.GetVersion()
	if err != nil {
		log.Fatal(4, "Fail to get Git version: %v", err)
	}

	reqVer, err := git.ParseVersion("1.7.1")
	if err != nil {
		log.Fatal(4, "Fail to parse required Git version: %v", err)
	}
	if ver.LessThan(reqVer) {
		log.Fatal(4, "Gogs requires Git version greater or equal to 1.7.1")
	}

	// Git requires setting user.name and user.email in order to commit changes.
	for configKey, defaultValue := range map[string]string{"user.name": "Gogs", "user.email": "[email protected]"} {
		if stdout, stderr, err := process.Exec("NewRepoContext(get setting)", "git", "config", "--get", configKey); err != nil || strings.TrimSpace(stdout) == "" {
			// ExitError indicates this config is not set
			if _, ok := err.(*exec.ExitError); ok || strings.TrimSpace(stdout) == "" {
				if _, stderr, gerr := process.Exec("NewRepoContext(set "+configKey+")", "git", "config", "--global", configKey, defaultValue); gerr != nil {
					log.Fatal(4, "Fail to set git %s(%s): %s", configKey, gerr, stderr)
				}
				log.Info("Git config %s set to %s", configKey, defaultValue)
			} else {
				log.Fatal(4, "Fail to get git %s(%s): %s", configKey, err, stderr)
			}
		}
	}

	// Set git some configurations.
	if _, stderr, err := process.Exec("NewRepoContext(git config --global core.quotepath false)",
		"git", "config", "--global", "core.quotepath", "false"); err != nil {
		log.Fatal(4, "Fail to execute 'git config --global core.quotepath false': %s", stderr)
	}

}
開發者ID:frankkorrell,項目名稱:gogs,代碼行數:44,代碼來源:repo.go

示例3: NewRepoContext

func NewRepoContext() {
	zip.Verbose = false

	// Check Git installation.
	if _, err := exec.LookPath("git"); err != nil {
		log.Fatal(4, "Fail to test 'git' command: %v (forgotten install?)", err)
	}

	// Check Git version.
	ver, err := git.GetVersion()
	if err != nil {
		log.Fatal(4, "Fail to get Git version: %v", err)
	}
	if ver.Major < 2 && ver.Minor < 8 {
		log.Fatal(4, "Gogs requires Git version greater or equal to 1.8.0")
	}

	// Check if server has basic git setting.
	stdout, stderr, err := process.Exec("NewRepoContext(get setting)", "git", "config", "--get", "user.name")
	if err != nil {
		log.Fatal(4, "Fail to get git user.name: %s", stderr)
	} else if err != nil || len(strings.TrimSpace(stdout)) == 0 {
		if _, stderr, err = process.Exec("NewRepoContext(set email)", "git", "config", "--global", "user.email", "[email protected]"); err != nil {
			log.Fatal(4, "Fail to set git user.email: %s", stderr)
		} else if _, stderr, err = process.Exec("NewRepoContext(set name)", "git", "config", "--global", "user.name", "Gogs"); err != nil {
			log.Fatal(4, "Fail to set git user.name: %s", stderr)
		}
	}

	// Set git some configurations.
	if _, stderr, err = process.Exec("NewRepoContext(git config --global core.quotepath false)",
		"git", "config", "--global", "core.quotepath", "false"); err != nil {
		log.Fatal(4, "Fail to execute 'git config --global core.quotepath false': %s", stderr)
	}

}
開發者ID:hogehoge999,項目名稱:gogs,代碼行數:36,代碼來源:repo.go

示例4: init

func init() {
	git.GetVersion()
}
開發者ID:Janfred,項目名稱:gogs,代碼行數:3,代碼來源:release.go


注:本文中的github.com/gogits/gogs/modules/git.GetVersion函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。