summaryrefslogtreecommitdiffstats
path: root/serve.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2014-03-25 17:11:13 +0800
committerLunny Xiao <xiaolunwen@gmail.com>2014-03-25 17:11:13 +0800
commitd24a4a142e5de9b2d9701ae93892234122e8b89b (patch)
tree41eb6c5fdc0004d5fc4d561bbf2930699fa79a03 /serve.go
parent6ef3e8b3c9a085e3d99b02ba7bb80fc8126f2f90 (diff)
downloadgitea-d24a4a142e5de9b2d9701ae93892234122e8b89b.tar.gz
gitea-d24a4a142e5de9b2d9701ae93892234122e8b89b.zip
bug fixed
Diffstat (limited to 'serve.go')
-rw-r--r--serve.go55
1 files changed, 28 insertions, 27 deletions
diff --git a/serve.go b/serve.go
index c3eb233c76..f9e915ed84 100644
--- a/serve.go
+++ b/serve.go
@@ -109,20 +109,25 @@ func runServ(k *cli.Context) {
repoName = repoName[:len(repoName)-4]
}
+ isWrite := In(verb, COMMANDS_WRITE)
+ isRead := In(verb, COMMANDS_READONLY)
+
repo, err := models.GetRepositoryByName(user.Id, repoName)
var isExist bool = true
if err != nil {
if err == models.ErrRepoNotExist {
isExist = false
+ if isRead {
+ println("Repository", user.Name+"/"+repoName, "is not exist")
+ return
+ }
} else {
- println("Unavilable repository", err)
+ println("Get repository error:", err)
return
}
}
- isWrite := In(verb, COMMANDS_WRITE)
- isRead := In(verb, COMMANDS_READONLY)
-
+ // access check
switch {
case isWrite:
has, err := models.HasAccess(user.Name, repoName, models.AU_WRITABLE)
@@ -156,12 +161,11 @@ func runServ(k *cli.Context) {
return
}
+ var rep *git.Repository
+ repoPath := models.RepoPath(user.Name, repoName)
if !isExist {
- if isRead {
- println("Repository", user.Name+"/"+repoName, "is not exist")
- return
- } else if isWrite {
- _, err := models.CreateRepository(user, repoName, "", "", "", false, true)
+ if isWrite {
+ _, err = models.CreateRepository(user, repoName, "", "", "", false, true)
if err != nil {
println("Create repository failed")
return
@@ -169,11 +173,11 @@ func runServ(k *cli.Context) {
}
}
- rep, err := git.OpenRepository(models.RepoPath(user.Name, repoName))
- if err != nil {
- println(err.Error())
- return
- }
+ rep, err = git.OpenRepository(repoPath)
+ if err != nil {
+ println(err.Error())
+ return
+ }
refs, err := rep.AllReferencesMap()
if err != nil {
@@ -194,17 +198,14 @@ func runServ(k *cli.Context) {
if err = gitcmd.Run(); err != nil {
println("execute command error:", err.Error())
+ return
}
- if !strings.HasPrefix(cmd, "git-receive-pack") {
+ if isRead {
return
}
- // update
- //w, _ := os.Create("serve.log")
- //defer w.Close()
- //log.SetOutput(w)
-
+ // find push reference name
var t = "ok refs/heads/"
var i int
var refname string
@@ -220,12 +221,17 @@ func runServ(k *cli.Context) {
refname = l[idx+len(t):]
}
}
+ if refname == "" {
+ println("No find any reference name:", b.String())
+ return
+ }
+
var ref *git.Reference
var ok bool
-
var l *list.List
//log.Info("----", refname, "-----")
if ref, ok = refs[refname]; !ok {
+ // for new branch
refs, err = rep.AllReferencesMap()
if err != nil {
println(err.Error())
@@ -280,13 +286,8 @@ func runServ(k *cli.Context) {
repo.Id, repoName, refname, &base.PushCommits{l.Len(), commits}); err != nil {
log.Error("runUpdate.models.CommitRepoAction: %v", err, commits)
} else {
- //log.Info("refname", refname)
- //log.Info("Listen: %v", cmd)
- //fmt.Println("...", cmd)
-
- //runUpdate(k)
c := exec.Command("git", "update-server-info")
- c.Dir = models.RepoPath(user.Name, repoName)
+ c.Dir = repoPath
err := c.Run()
if err != nil {
log.Error("update-server-info: %v", err)