summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-04-22 22:34:49 -0400
committerUnknown <joe2010xtmf@163.com>2014-04-22 22:34:49 -0400
commit8bc502a1ead4d59e1940946c74ff48c8e6457633 (patch)
tree343cc2c624680aa0e5d487f6fd66e9daa0314c69 /models
parent88072a1e9b43d1760e6f9015c09d4221646080ca (diff)
downloadgitea-8bc502a1ead4d59e1940946c74ff48c8e6457633.tar.gz
gitea-8bc502a1ead4d59e1940946c74ff48c8e6457633.zip
New err check style
Diffstat (limited to 'models')
-rw-r--r--models/repo.go24
1 files changed, 8 insertions, 16 deletions
diff --git a/models/repo.go b/models/repo.go
index 19fe6e2887..2011ed7de1 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -47,16 +47,16 @@ func NewRepoContext() {
zip.Verbose = false
// Check if server has basic git setting.
- stdout, _, err := com.ExecCmd("git", "config", "--get", "user.name")
- if err != nil {
- fmt.Printf("repo.init(fail to get git user.name): %v", err)
+ stdout, stderr, err := com.ExecCmd("git", "config", "--get", "user.name")
+ if strings.Contains(stderr, "fatal:") {
+ fmt.Printf("repo.NewRepoContext(fail to get git user.name): %s", stderr)
os.Exit(2)
- } else if len(stdout) == 0 {
- if _, _, err = com.ExecCmd("git", "config", "--global", "user.email", "gogitservice@gmail.com"); err != nil {
- fmt.Printf("repo.init(fail to set git user.email): %v", err)
+ } else if err != nil || len(strings.TrimSpace(stdout)) == 0 {
+ if _, stderr, err = com.ExecCmd("git", "config", "--global", "user.email", "gogitservice@gmail.com"); err != nil {
+ fmt.Printf("repo.NewRepoContext(fail to set git user.email): %s", stderr)
os.Exit(2)
- } else if _, _, err = com.ExecCmd("git", "config", "--global", "user.name", "Gogs"); err != nil {
- fmt.Printf("repo.init(fail to set git user.name): %v", err)
+ } else if _, stderr, err = com.ExecCmd("git", "config", "--global", "user.name", "Gogs"); err != nil {
+ fmt.Printf("repo.NewRepoContext(fail to set git user.name): %s", stderr)
os.Exit(2)
}
}
@@ -352,7 +352,6 @@ func CreateRepository(user *User, name, desc, lang, license string, private, mir
func extractGitBareZip(repoPath string) error {
z, err := zip.Open("conf/content/git-bare.zip")
if err != nil {
- fmt.Println("shi?")
return err
}
defer z.Close()
@@ -364,21 +363,14 @@ func extractGitBareZip(repoPath string) error {
func initRepoCommit(tmpPath string, sig *git.Signature) (err error) {
var stderr string
if _, stderr, err = com.ExecCmdDir(tmpPath, "git", "add", "--all"); err != nil {
- return err
- } else if strings.Contains(stderr, "fatal:") {
return errors.New("git add: " + stderr)
}
-
if _, stderr, err = com.ExecCmdDir(tmpPath, "git", "commit", fmt.Sprintf("--author='%s <%s>'", sig.Name, sig.Email),
"-m", "Init commit"); err != nil {
- return err
- } else if strings.Contains(stderr, "fatal:") {
return errors.New("git commit: " + stderr)
}
if _, stderr, err = com.ExecCmdDir(tmpPath, "git", "push", "origin", "master"); err != nil {
- return err
- } else if strings.Contains(stderr, "fatal:") {
return errors.New("git push: " + stderr)
}
return nil