From 6f8e388b5530e85f141ea3aa345b1c6842fbe1f5 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Sun, 26 Jul 2015 19:22:17 +0800 Subject: [PATCH] fix #1169 - prevent create reop on existed path --- models/repo.go | 7 ++++++- modules/git/repo_tag.go | 2 +- modules/git/utils.go | 8 ++++++++ modules/middleware/org.go | 6 ++++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/models/repo.go b/models/repo.go index 35f63e12a8..f339f1737a 100644 --- a/models/repo.go +++ b/models/repo.go @@ -423,13 +423,18 @@ func createUpdateHook(repoPath string) error { // InitRepository initializes README and .gitignore if needed. func initRepository(e Engine, repoPath string, u *User, repo *Repository, initReadme bool, repoLang, license string) error { + // Somehow the directory could exist. + if com.IsExist(repoPath) { + return fmt.Errorf("initRepository: path already exists: %s", repoPath) + } + // Init bare new repository. os.MkdirAll(repoPath, os.ModePerm) _, stderr, err := process.ExecDir(-1, repoPath, fmt.Sprintf("initRepository(git init --bare): %s", repoPath), "git", "init", "--bare") if err != nil { - return errors.New("git init --bare: " + stderr) + return fmt.Errorf("git init --bare: %s", err) } if err := createUpdateHook(repoPath); err != nil { diff --git a/modules/git/repo_tag.go b/modules/git/repo_tag.go index ed994d48ae..45a1df7083 100644 --- a/modules/git/repo_tag.go +++ b/modules/git/repo_tag.go @@ -27,7 +27,7 @@ func (repo *Repository) GetTags() ([]string, error) { } stdout, stderr, err := com.ExecCmdDir(repo.Path, "git", "tag", "-l") if err != nil { - return nil, errors.New(stderr) + return nil, concatenateError(err, stderr) } tags := strings.Split(stdout, "\n") return tags[:len(tags)-1], nil diff --git a/modules/git/utils.go b/modules/git/utils.go index 6abbca557b..78792aaf5e 100644 --- a/modules/git/utils.go +++ b/modules/git/utils.go @@ -7,6 +7,7 @@ package git import ( "bytes" "container/list" + "fmt" "os" "path/filepath" "strings" @@ -67,3 +68,10 @@ func isFile(filePath string) bool { } return !f.IsDir() } + +func concatenateError(err error, stderr string) error { + if len(stderr) == 0 { + return err + } + return fmt.Errorf("%v: %s", err, stderr) +} diff --git a/modules/middleware/org.go b/modules/middleware/org.go index 0e544fe4a2..1ac4bcf1ae 100644 --- a/modules/middleware/org.go +++ b/modules/middleware/org.go @@ -47,6 +47,12 @@ func OrgAssignment(redirect bool, args ...bool) macaron.Handler { org := ctx.Org.Organization ctx.Data["Org"] = org + // Force redirection when username is actually a user. + if !org.IsOrganization() { + ctx.Redirect("/" + org.Name) + return + } + if ctx.IsSigned { ctx.Org.IsOwner = org.IsOwnedBy(ctx.User.Id) if ctx.Org.IsOwner {