Browse Source

fix #1169

- prevent create reop on existed path
tags/v0.9.99
Unknwon 8 years ago
parent
commit
6f8e388b55
4 changed files with 21 additions and 2 deletions
  1. 6
    1
      models/repo.go
  2. 1
    1
      modules/git/repo_tag.go
  3. 8
    0
      modules/git/utils.go
  4. 6
    0
      modules/middleware/org.go

+ 6
- 1
models/repo.go View File

@@ -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 {

+ 1
- 1
modules/git/repo_tag.go View File

@@ -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

+ 8
- 0
modules/git/utils.go View File

@@ -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)
}

+ 6
- 0
modules/middleware/org.go View File

@@ -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 {

Loading…
Cancel
Save