mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-23 13:55:27 +00:00
bug fixed
This commit is contained in:
parent
d374b13d44
commit
fc1419d763
37
serve.go
37
serve.go
|
@ -5,20 +5,17 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"container/list"
|
||||
//"container/list"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/gogits/gogs/modules/log"
|
||||
|
||||
"github.com/gogits/git"
|
||||
//"github.com/gogits/git"
|
||||
"github.com/gogits/gogs/models"
|
||||
"github.com/gogits/gogs/modules/base"
|
||||
)
|
||||
|
@ -115,11 +112,11 @@ func runServ(k *cli.Context) {
|
|||
isWrite := In(verb, COMMANDS_WRITE)
|
||||
isRead := In(verb, COMMANDS_READONLY)
|
||||
|
||||
repo, err := models.GetRepositoryByName(user.Id, repoName)
|
||||
var isExist bool = true
|
||||
//repo, err := models.GetRepositoryByName(user.Id, repoName)
|
||||
//var isExist bool = true
|
||||
if err != nil {
|
||||
if err == models.ErrRepoNotExist {
|
||||
isExist = false
|
||||
//isExist = false
|
||||
if isRead {
|
||||
println("Repository", user.Name+"/"+repoName, "is not exist")
|
||||
return
|
||||
|
@ -168,6 +165,7 @@ func runServ(k *cli.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
/*
|
||||
var rep *git.Repository
|
||||
repoPath := models.RepoPath(user.Name, repoName)
|
||||
if !isExist {
|
||||
|
@ -194,14 +192,20 @@ func runServ(k *cli.Context) {
|
|||
log.Error(err.Error())
|
||||
return
|
||||
}
|
||||
*/
|
||||
|
||||
os.Setenv("userName", user.Name)
|
||||
os.Setenv("userId", strconv.Itoa(int(user.Id)))
|
||||
//os.Setenv("repoId", repoId)
|
||||
os.Setenv("repoName", repoName)
|
||||
|
||||
gitcmd := exec.Command(verb, rRepo)
|
||||
gitcmd.Dir = base.RepoRootPath
|
||||
|
||||
var s string
|
||||
b := bytes.NewBufferString(s)
|
||||
//var s string
|
||||
//b := bytes.NewBufferString(s)
|
||||
|
||||
gitcmd.Stdout = io.MultiWriter(os.Stdout, b)
|
||||
gitcmd.Stdout = os.Stdout
|
||||
//gitcmd.Stdin = io.MultiReader(os.Stdin, b)
|
||||
gitcmd.Stdin = os.Stdin
|
||||
gitcmd.Stderr = os.Stderr
|
||||
|
@ -213,16 +217,13 @@ func runServ(k *cli.Context) {
|
|||
}
|
||||
|
||||
//if isRead {
|
||||
return
|
||||
// return
|
||||
//}
|
||||
|
||||
time.Sleep(time.Second)
|
||||
log.Info(s)
|
||||
|
||||
// find push reference name
|
||||
//var t = "ok refs/heads/"
|
||||
//var i int
|
||||
var refname string
|
||||
//var refname string
|
||||
/*for {
|
||||
l, err := b.ReadString('\n')
|
||||
if err != nil {
|
||||
|
@ -237,7 +238,7 @@ func runServ(k *cli.Context) {
|
|||
}
|
||||
*/
|
||||
|
||||
refs2, err := rep.AllReferencesMap()
|
||||
/*refs2, err := rep.AllReferencesMap()
|
||||
for name, ref := range refs2 {
|
||||
if ref2, ok := refs[name]; ok {
|
||||
if ref.Oid.Equal(ref2.Oid) {
|
||||
|
@ -323,5 +324,5 @@ func runServ(k *cli.Context) {
|
|||
if err != nil {
|
||||
log.Error("update-server-info: %v", err)
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
|
92
update.go
92
update.go
|
@ -6,9 +6,17 @@ package main
|
|||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"strconv"
|
||||
"container/list"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
//"github.com/gogits/gogs/modules/log"
|
||||
"github.com/gogits/gogs/models"
|
||||
"github.com/gogits/gogs/modules/base"
|
||||
"github.com/qiniu/log"
|
||||
"github.com/gogits/git"
|
||||
)
|
||||
|
||||
var CmdUpdate = cli.Command{
|
||||
|
@ -31,16 +39,30 @@ func runUpdate(c *cli.Context) {
|
|||
defer w.Close()
|
||||
|
||||
log.SetOutput(w)
|
||||
for i, arg := range c.Args() {
|
||||
log.Info(i, arg)
|
||||
|
||||
|
||||
|
||||
args := c.Args()
|
||||
if len(args) != 3 {
|
||||
log.Error("received less 3 parameters")
|
||||
return
|
||||
}
|
||||
|
||||
refName := args[0]
|
||||
oldCommitId := args[1]
|
||||
newCommitId := args[2]
|
||||
|
||||
userName := os.Getenv("userName")
|
||||
//userId := os.Getenv("userId")
|
||||
userId := os.Getenv("userId")
|
||||
//repoId := os.Getenv("repoId")
|
||||
//repoName := os.Getenv("repoName")
|
||||
repoName := os.Getenv("repoName")
|
||||
|
||||
log.Info("username", userName)
|
||||
/*f := models.RepoPath(userName, repoName)
|
||||
f := models.RepoPath(userName, repoName)
|
||||
|
||||
gitUpdate := exec.Command("git", "update-server-info")
|
||||
gitUpdate.Dir = f
|
||||
gitUpdate.Run()
|
||||
|
||||
repo, err := git.OpenRepository(f)
|
||||
if err != nil {
|
||||
|
@ -48,13 +70,45 @@ func runUpdate(c *cli.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
ref, err := repo.LookupReference("HEAD")
|
||||
ref, err := repo.LookupReference(refName)
|
||||
if err != nil {
|
||||
log.Error("runUpdate.Ref repoId: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
lastCommit, err := repo.LookupCommit(ref.Oid)
|
||||
oldOid, err := git.NewOidFromString(oldCommitId)
|
||||
if err != nil {
|
||||
log.Error("runUpdate.Ref repoId: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
oldCommit, err := repo.LookupCommit(oldOid)
|
||||
if err != nil {
|
||||
log.Error("runUpdate.Ref repoId: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
newOid, err := git.NewOidFromString(newCommitId)
|
||||
if err != nil {
|
||||
log.Error("runUpdate.Ref repoId: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
newCommit, err := repo.LookupCommit(newOid)
|
||||
if err != nil {
|
||||
log.Error("runUpdate.Ref repoId: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
var l *list.List
|
||||
// if a new branch
|
||||
if strings.HasPrefix(oldCommitId, "0000000") {
|
||||
l, err = ref.AllCommits()
|
||||
|
||||
} else {
|
||||
l = ref.CommitsBetween(newCommit, oldCommit)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Error("runUpdate.Commit repoId: %v", err)
|
||||
return
|
||||
|
@ -65,18 +119,28 @@ func runUpdate(c *cli.Context) {
|
|||
log.Error("runUpdate.Parse userId: %v", err)
|
||||
return
|
||||
}
|
||||
sRepoId, err := strconv.Atoi(repoId)
|
||||
|
||||
repos, err := models.GetRepositoryByName(int64(sUserId), repoName)
|
||||
if err != nil {
|
||||
log.Error("runUpdate.Parse repoId: %v", err)
|
||||
log.Error("runUpdate.GetRepositoryByName userId: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
commits := make([][]string, 0)
|
||||
commits = append(commits, []string{lastCommit.Id().String(), lastCommit.Message()})
|
||||
var maxCommits = 3
|
||||
for e := l.Front(); e != nil; e = e.Next() {
|
||||
commit := e.Value.(*git.Commit)
|
||||
commits = append(commits, []string{commit.Id().String(), commit.Message()})
|
||||
if len(commits) >= maxCommits {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
//commits = append(commits, []string{lastCommit.Id().String(), lastCommit.Message()})
|
||||
if err = models.CommitRepoAction(int64(sUserId), userName,
|
||||
int64(sRepoId), repoName, commits); err != nil {
|
||||
repos.Id, repoName, refName, &base.PushCommits{l.Len(), commits}); err != nil {
|
||||
log.Error("runUpdate.models.CommitRepoAction: %v", err)
|
||||
} else {
|
||||
l := exec.Command("exec", "git", "update-server-info")
|
||||
l.Run()
|
||||
}*/
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue