1
0
mirror of https://github.com/go-gitea/gitea.git synced 2024-11-04 08:17:24 -05:00

bug fixed

This commit is contained in:
Lunny Xiao 2014-03-25 17:11:13 +08:00
parent 6ef3e8b3c9
commit d24a4a142e

View File

@ -109,20 +109,25 @@ func runServ(k *cli.Context) {
repoName = repoName[:len(repoName)-4] repoName = repoName[:len(repoName)-4]
} }
isWrite := In(verb, COMMANDS_WRITE)
isRead := In(verb, COMMANDS_READONLY)
repo, err := models.GetRepositoryByName(user.Id, repoName) repo, err := models.GetRepositoryByName(user.Id, repoName)
var isExist bool = true var isExist bool = true
if err != nil { if err != nil {
if err == models.ErrRepoNotExist { if err == models.ErrRepoNotExist {
isExist = false isExist = false
if isRead {
println("Repository", user.Name+"/"+repoName, "is not exist")
return
}
} else { } else {
println("Unavilable repository", err) println("Get repository error:", err)
return return
} }
} }
isWrite := In(verb, COMMANDS_WRITE) // access check
isRead := In(verb, COMMANDS_READONLY)
switch { switch {
case isWrite: case isWrite:
has, err := models.HasAccess(user.Name, repoName, models.AU_WRITABLE) has, err := models.HasAccess(user.Name, repoName, models.AU_WRITABLE)
@ -156,12 +161,11 @@ func runServ(k *cli.Context) {
return return
} }
var rep *git.Repository
repoPath := models.RepoPath(user.Name, repoName)
if !isExist { if !isExist {
if isRead { if isWrite {
println("Repository", user.Name+"/"+repoName, "is not exist") _, err = models.CreateRepository(user, repoName, "", "", "", false, true)
return
} else if isWrite {
_, err := models.CreateRepository(user, repoName, "", "", "", false, true)
if err != nil { if err != nil {
println("Create repository failed") println("Create repository failed")
return return
@ -169,7 +173,7 @@ func runServ(k *cli.Context) {
} }
} }
rep, err := git.OpenRepository(models.RepoPath(user.Name, repoName)) rep, err = git.OpenRepository(repoPath)
if err != nil { if err != nil {
println(err.Error()) println(err.Error())
return return
@ -194,17 +198,14 @@ func runServ(k *cli.Context) {
if err = gitcmd.Run(); err != nil { if err = gitcmd.Run(); err != nil {
println("execute command error:", err.Error()) println("execute command error:", err.Error())
}
if !strings.HasPrefix(cmd, "git-receive-pack") {
return return
} }
// update if isRead {
//w, _ := os.Create("serve.log") return
//defer w.Close() }
//log.SetOutput(w)
// find push reference name
var t = "ok refs/heads/" var t = "ok refs/heads/"
var i int var i int
var refname string var refname string
@ -220,12 +221,17 @@ func runServ(k *cli.Context) {
refname = l[idx+len(t):] refname = l[idx+len(t):]
} }
} }
if refname == "" {
println("No find any reference name:", b.String())
return
}
var ref *git.Reference var ref *git.Reference
var ok bool var ok bool
var l *list.List var l *list.List
//log.Info("----", refname, "-----") //log.Info("----", refname, "-----")
if ref, ok = refs[refname]; !ok { if ref, ok = refs[refname]; !ok {
// for new branch
refs, err = rep.AllReferencesMap() refs, err = rep.AllReferencesMap()
if err != nil { if err != nil {
println(err.Error()) println(err.Error())
@ -280,13 +286,8 @@ func runServ(k *cli.Context) {
repo.Id, repoName, refname, &base.PushCommits{l.Len(), commits}); err != nil { repo.Id, repoName, refname, &base.PushCommits{l.Len(), commits}); err != nil {
log.Error("runUpdate.models.CommitRepoAction: %v", err, commits) log.Error("runUpdate.models.CommitRepoAction: %v", err, commits)
} else { } else {
//log.Info("refname", refname)
//log.Info("Listen: %v", cmd)
//fmt.Println("...", cmd)
//runUpdate(k)
c := exec.Command("git", "update-server-info") c := exec.Command("git", "update-server-info")
c.Dir = models.RepoPath(user.Name, repoName) c.Dir = repoPath
err := c.Run() err := c.Run()
if err != nil { if err != nil {
log.Error("update-server-info: %v", err) log.Error("update-server-info: %v", err)