tokarchuk/v1.17
Lunny Xiao 11 years ago
parent bc1abb010d
commit 922a189f40
  1. 41
      update.go

@ -40,24 +40,33 @@ func runUpdate(c *cli.Context) {
log.SetOutput(w) log.SetOutput(w)
args := c.Args() args := c.Args()
//log.Info(args)
if len(args) != 3 { if len(args) != 3 {
log.Error("received less 3 parameters") log.Error("received less 3 parameters")
return return
} }
refName := args[0] refName := args[0]
if refName == "" {
log.Error("refName is empty, shouldn't use")
return
}
oldCommitId := args[1] oldCommitId := args[1]
newCommitId := args[2] newCommitId := args[2]
isNew := strings.HasPrefix(oldCommitId, "0000000")
if isNew &&
strings.HasPrefix(newCommitId, "0000000") {
log.Error("old rev and new rev both 000000")
return
}
userName := os.Getenv("userName") userName := os.Getenv("userName")
userId := os.Getenv("userId") userId := os.Getenv("userId")
//repoId := os.Getenv("repoId") //repoId := os.Getenv("repoId")
repoName := os.Getenv("repoName") repoName := os.Getenv("repoName")
log.Info("username", userName)
log.Info("repoName", repoName)
f := models.RepoPath(userName, repoName) f := models.RepoPath(userName, repoName)
log.Info("f", f)
gitUpdate := exec.Command("git", "update-server-info") gitUpdate := exec.Command("git", "update-server-info")
gitUpdate.Dir = f gitUpdate.Dir = f
@ -69,43 +78,39 @@ func runUpdate(c *cli.Context) {
return return
} }
ref, err := repo.LookupReference(refName) newOid, err := git.NewOidFromString(newCommitId)
if err != nil { if err != nil {
log.Error("runUpdate.Ref repoId: %v", err) log.Error("runUpdate.Ref repoId: %v", err)
return return
} }
oldOid, err := git.NewOidFromString(oldCommitId) newCommit, err := repo.LookupCommit(newOid)
if err != nil { if err != nil {
log.Error("runUpdate.Ref repoId: %v", err) log.Error("runUpdate.Ref repoId: %v", err)
return return
} }
oldCommit, err := repo.LookupCommit(oldOid) var l *list.List
// if a new branch
if isNew {
l, err = repo.CommitsBefore(newCommit.Id())
if err != nil { if err != nil {
log.Error("runUpdate.Ref repoId: %v", err) log.Error("Find CommitsBefore erro:", err)
return return
} }
} else {
newOid, err := git.NewOidFromString(newCommitId) oldOid, err := git.NewOidFromString(oldCommitId)
if err != nil { if err != nil {
log.Error("runUpdate.Ref repoId: %v", err) log.Error("runUpdate.Ref repoId: %v", err)
return return
} }
newCommit, err := repo.LookupCommit(newOid) oldCommit, err := repo.LookupCommit(oldOid)
if err != nil { if err != nil {
log.Error("runUpdate.Ref repoId: %v", err) log.Error("runUpdate.Ref repoId: %v", err)
return return
} }
l = repo.CommitsBetween(newCommit, oldCommit)
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 { if err != nil {

Loading…
Cancel
Save