-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only check and config git on web subcommand but not others (#7236)
* only check and config git on web subcommand but not others * add Init in git tests
- Loading branch information
Showing
4 changed files
with
35 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,26 +91,30 @@ func init() { | |
if version.Compare(gitVersion, GitVersionRequired, "<") { | ||
panic(fmt.Sprintf("Git version not supported. Requires version > %v", GitVersionRequired)) | ||
} | ||
} | ||
|
||
// Init initializes git module | ||
func Init() error { | ||
// Git requires setting user.name and user.email in order to commit changes. | ||
for configKey, defaultValue := range map[string]string{"user.name": "Gitea", "user.email": "[email protected]"} { | ||
if stdout, stderr, err := process.GetManager().Exec("git.Init(get setting)", GitExecutable, "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.GetManager().Exec("git.Init(set "+configKey+")", "git", "config", "--global", configKey, defaultValue); gerr != nil { | ||
panic(fmt.Sprintf("Failed to set git %s(%s): %s", configKey, gerr, stderr)) | ||
return fmt.Errorf("Failed to set git %s(%s): %s", configKey, gerr, stderr) | ||
} | ||
} else { | ||
panic(fmt.Sprintf("Failed to get git %s(%s): %s", configKey, err, stderr)) | ||
return fmt.Errorf("Failed to get git %s(%s): %s", configKey, err, stderr) | ||
} | ||
} | ||
} | ||
|
||
// Set git some configurations. | ||
if _, stderr, err := process.GetManager().Exec("git.Init(git config --global core.quotepath false)", | ||
GitExecutable, "config", "--global", "core.quotepath", "false"); err != nil { | ||
panic(fmt.Sprintf("Failed to execute 'git config --global core.quotepath false': %s", stderr)) | ||
return fmt.Errorf("Failed to execute 'git config --global core.quotepath false': %s", stderr) | ||
} | ||
return nil | ||
} | ||
|
||
// Fsck verifies the connectivity and validity of the objects in the database | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2019 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package git | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func fatalTestError(fmtStr string, args ...interface{}) { | ||
fmt.Fprintf(os.Stderr, fmtStr, args...) | ||
os.Exit(1) | ||
} | ||
|
||
func TestMain(m *testing.M) { | ||
if err := Init(); err != nil { | ||
fatalTestError("Init failed: %v", err) | ||
} | ||
|
||
exitStatus := m.Run() | ||
os.Exit(exitStatus) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters