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 := "******" stndrdUserEmail := "*****@*****.**" 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) } }
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": "*****@*****.**"} { 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) } }
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", "*****@*****.**"); 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) } }
func init() { git.GetVersion() }