summaryrefslogtreecommitdiffstats
path: root/models/update.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2014-06-28 14:58:59 +0800
committerLunny Xiao <xiaolunwen@gmail.com>2014-06-28 14:58:59 +0800
commit86e2627175ceaed544dabbbef40d9197995c2bd4 (patch)
tree820eb7762ca0d3fa4f14e657a1ce2aa9f4b73617 /models/update.go
parente5ae41e21f7fa1e25f04a28d907b89c78196c824 (diff)
parentee9b7f322ff4c4c14952c2f83fb03e90fa583cad (diff)
downloadgitea-86e2627175ceaed544dabbbef40d9197995c2bd4.tar.gz
gitea-86e2627175ceaed544dabbbef40d9197995c2bd4.zip
Merge branch 'master' of github.com:gogits/gogs
Conflicts: models/update.go routers/repo/http.go
Diffstat (limited to 'models/update.go')
-rw-r--r--models/update.go27
1 files changed, 14 insertions, 13 deletions
diff --git a/models/update.go b/models/update.go
index 188e6cb9c7..0231b6af38 100644
--- a/models/update.go
+++ b/models/update.go
@@ -6,6 +6,7 @@ package models
import (
"container/list"
+ "fmt"
"os/exec"
"strings"
@@ -15,13 +16,13 @@ import (
"github.com/gogits/gogs/modules/log"
)
-func Update(refName, oldCommitId, newCommitId, userName, repoUserName, repoName string, userId int64) {
+func Update(refName, oldCommitId, newCommitId, userName, repoUserName, repoName string, userId int64) error {
//fmt.Println(refName, oldCommitId, newCommitId)
//fmt.Println(userName, repoUserName, repoName)
isNew := strings.HasPrefix(oldCommitId, "0000000")
if isNew &&
strings.HasPrefix(newCommitId, "0000000") {
- log.GitLogger.Fatal("old rev and new rev both 000000")
+ return fmt.Errorf("old rev and new rev both 000000")
}
f := RepoPath(repoUserName, repoName)
@@ -33,18 +34,17 @@ func Update(refName, oldCommitId, newCommitId, userName, repoUserName, repoName
isDel := strings.HasPrefix(newCommitId, "0000000")
if isDel {
log.GitLogger.Info("del rev", refName, "from", userName+"/"+repoName+".git", "by", userId)
- return
+ return nil
}
repo, err := git.OpenRepository(f)
if err != nil {
- log.GitLogger.Fatal("runUpdate.Open repoId: %v", err)
+ return fmt.Errorf("runUpdate.Open repoId: %v", err)
}
newCommit, err := repo.GetCommit(newCommitId)
if err != nil {
- log.GitLogger.Fatal("runUpdate GetCommit of newCommitId: %v", err)
- return
+ return fmt.Errorf("runUpdate GetCommit of newCommitId: %v", err)
}
var l *list.List
@@ -52,28 +52,27 @@ func Update(refName, oldCommitId, newCommitId, userName, repoUserName, repoName
if isNew {
l, err = newCommit.CommitsBefore()
if err != nil {
- log.GitLogger.Fatal("Find CommitsBefore erro: %v", err)
+ return fmt.Errorf("Find CommitsBefore erro: %v", err)
}
} else {
l, err = newCommit.CommitsBeforeUntil(oldCommitId)
if err != nil {
- log.GitLogger.Fatal("Find CommitsBeforeUntil erro: %v", err)
- return
+ return fmt.Errorf("Find CommitsBeforeUntil erro: %v", err)
}
}
if err != nil {
- log.GitLogger.Fatal("runUpdate.Commit repoId: %v", err)
+ return fmt.Errorf("runUpdate.Commit repoId: %v", err)
}
ru, err := GetUserByName(repoUserName)
if err != nil {
- log.GitLogger.Fatal("runUpdate.GetUserByName: %v", err)
+ return fmt.Errorf("runUpdate.GetUserByName: %v", err)
}
repos, err := GetRepositoryByName(ru.Id, repoName)
if err != nil {
- log.GitLogger.Fatal("runUpdate.GetRepositoryByName userId: %v", err)
+ return fmt.Errorf("runUpdate.GetRepositoryByName userId: %v", err)
}
// if tags push
@@ -104,6 +103,7 @@ func Update(refName, oldCommitId, newCommitId, userName, repoUserName, repoName
return
}
+ // if commits push
commits := make([]*base.PushCommit, 0)
var maxCommits = 3
var actEmail string
@@ -126,6 +126,7 @@ func Update(refName, oldCommitId, newCommitId, userName, repoUserName, repoName
//commits = append(commits, []string{lastCommit.Id().String(), lastCommit.Message()})
if err = CommitRepoAction(userId, ru.Id, userName, actEmail,
repos.Id, repoUserName, repoName, refName, &base.PushCommits{l.Len(), commits}); err != nil {
- log.GitLogger.Fatal("runUpdate.models.CommitRepoAction: %s/%s:%v", repoUserName, repoName, err)
+ return fmt.Errorf("runUpdate.models.CommitRepoAction: %s/%s:%v", repoUserName, repoName, err)
}
+ return nil
}