mirror of
https://github.com/go-gitea/gitea
synced 2024-12-23 09:04:26 +00:00
New err check style
This commit is contained in:
parent
88072a1e9b
commit
8bc502a1ea
@ -47,16 +47,16 @@ func NewRepoContext() {
|
|||||||
zip.Verbose = false
|
zip.Verbose = false
|
||||||
|
|
||||||
// Check if server has basic git setting.
|
// Check if server has basic git setting.
|
||||||
stdout, _, err := com.ExecCmd("git", "config", "--get", "user.name")
|
stdout, stderr, err := com.ExecCmd("git", "config", "--get", "user.name")
|
||||||
if err != nil {
|
if strings.Contains(stderr, "fatal:") {
|
||||||
fmt.Printf("repo.init(fail to get git user.name): %v", err)
|
fmt.Printf("repo.NewRepoContext(fail to get git user.name): %s", stderr)
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
} else if len(stdout) == 0 {
|
} else if err != nil || len(strings.TrimSpace(stdout)) == 0 {
|
||||||
if _, _, err = com.ExecCmd("git", "config", "--global", "user.email", "gogitservice@gmail.com"); err != nil {
|
if _, stderr, 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)
|
fmt.Printf("repo.NewRepoContext(fail to set git user.email): %s", stderr)
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
} else if _, _, err = com.ExecCmd("git", "config", "--global", "user.name", "Gogs"); err != nil {
|
} else if _, stderr, err = com.ExecCmd("git", "config", "--global", "user.name", "Gogs"); err != nil {
|
||||||
fmt.Printf("repo.init(fail to set git user.name): %v", err)
|
fmt.Printf("repo.NewRepoContext(fail to set git user.name): %s", stderr)
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -352,7 +352,6 @@ func CreateRepository(user *User, name, desc, lang, license string, private, mir
|
|||||||
func extractGitBareZip(repoPath string) error {
|
func extractGitBareZip(repoPath string) error {
|
||||||
z, err := zip.Open("conf/content/git-bare.zip")
|
z, err := zip.Open("conf/content/git-bare.zip")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("shi?")
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer z.Close()
|
defer z.Close()
|
||||||
@ -364,21 +363,14 @@ func extractGitBareZip(repoPath string) error {
|
|||||||
func initRepoCommit(tmpPath string, sig *git.Signature) (err error) {
|
func initRepoCommit(tmpPath string, sig *git.Signature) (err error) {
|
||||||
var stderr string
|
var stderr string
|
||||||
if _, stderr, err = com.ExecCmdDir(tmpPath, "git", "add", "--all"); err != nil {
|
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)
|
return errors.New("git add: " + stderr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, stderr, err = com.ExecCmdDir(tmpPath, "git", "commit", fmt.Sprintf("--author='%s <%s>'", sig.Name, sig.Email),
|
if _, stderr, err = com.ExecCmdDir(tmpPath, "git", "commit", fmt.Sprintf("--author='%s <%s>'", sig.Name, sig.Email),
|
||||||
"-m", "Init commit"); err != nil {
|
"-m", "Init commit"); err != nil {
|
||||||
return err
|
|
||||||
} else if strings.Contains(stderr, "fatal:") {
|
|
||||||
return errors.New("git commit: " + stderr)
|
return errors.New("git commit: " + stderr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, stderr, err = com.ExecCmdDir(tmpPath, "git", "push", "origin", "master"); err != nil {
|
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 errors.New("git push: " + stderr)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -134,7 +134,6 @@ func Single(ctx *middleware.Context, params martini.Params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(treename)
|
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(treename)
|
||||||
|
|
||||||
if err != nil && err != git.ErrNotExist {
|
if err != nil && err != git.ErrNotExist {
|
||||||
ctx.Handle(404, "repo.Single(GetTreeEntryByPath)", err)
|
ctx.Handle(404, "repo.Single(GetTreeEntryByPath)", err)
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user