Browse Source

Mirror fix on #248

Unknown 5 years ago
parent
commit
47d29a1ee0
5 changed files with 22 additions and 17 deletions
  1. 3 1
      cmd/update.go
  2. 1 1
      gogs.go
  3. 13 13
      models/update.go
  4. 4 1
      routers/repo/http.go
  5. 1 1
      templates/VERSION

+ 3 - 1
cmd/update.go

@@ -42,5 +42,7 @@ func runUpdate(c *cli.Context) {
42 42
 	repoUserName := os.Getenv("repoUserName")
43 43
 	repoName := os.Getenv("repoName")
44 44
 
45
-	models.Update(args[0], args[1], args[2], userName, repoUserName, repoName, userId)
45
+	if err := models.Update(args[0], args[1], args[2], userName, repoUserName, repoName, userId); err != nil {
46
+		log.GitLogger.Fatal(err.Error())
47
+	}
46 48
 }

+ 1 - 1
gogs.go

@@ -17,7 +17,7 @@ import (
17 17
 	"github.com/gogits/gogs/modules/setting"
18 18
 )
19 19
 
20
-const APP_VER = "0.4.5.0622 Alpha"
20
+const APP_VER = "0.4.5.0623 Alpha"
21 21
 
22 22
 func init() {
23 23
 	runtime.GOMAXPROCS(runtime.NumCPU())

+ 13 - 13
models/update.go

@@ -6,6 +6,7 @@ package models
6 6
 
7 7
 import (
8 8
 	"container/list"
9
+	"fmt"
9 10
 	"os/exec"
10 11
 	"strings"
11 12
 
@@ -15,11 +16,11 @@ import (
15 16
 	"github.com/gogits/gogs/modules/log"
16 17
 )
17 18
 
18
-func Update(refName, oldCommitId, newCommitId, userName, repoUserName, repoName string, userId int64) {
19
+func Update(refName, oldCommitId, newCommitId, userName, repoUserName, repoName string, userId int64) error {
19 20
 	isNew := strings.HasPrefix(oldCommitId, "0000000")
20 21
 	if isNew &&
21 22
 		strings.HasPrefix(newCommitId, "0000000") {
22
-		log.GitLogger.Fatal("old rev and new rev both 000000")
23
+		return fmt.Errorf("old rev and new rev both 000000")
23 24
 	}
24 25
 
25 26
 	f := RepoPath(repoUserName, repoName)
@@ -31,18 +32,17 @@ func Update(refName, oldCommitId, newCommitId, userName, repoUserName, repoName
31 32
 	isDel := strings.HasPrefix(newCommitId, "0000000")
32 33
 	if isDel {
33 34
 		log.GitLogger.Info("del rev", refName, "from", userName+"/"+repoName+".git", "by", userId)
34
-		return
35
+		return nil
35 36
 	}
36 37
 
37 38
 	repo, err := git.OpenRepository(f)
38 39
 	if err != nil {
39
-		log.GitLogger.Fatal("runUpdate.Open repoId: %v", err)
40
+		return fmt.Errorf("runUpdate.Open repoId: %v", err)
40 41
 	}
41 42
 
42 43
 	newCommit, err := repo.GetCommit(newCommitId)
43 44
 	if err != nil {
44
-		log.GitLogger.Fatal("runUpdate GetCommit of newCommitId: %v", err)
45
-		return
45
+		return fmt.Errorf("runUpdate GetCommit of newCommitId: %v", err)
46 46
 	}
47 47
 
48 48
 	var l *list.List
@@ -50,28 +50,27 @@ func Update(refName, oldCommitId, newCommitId, userName, repoUserName, repoName
50 50
 	if isNew {
51 51
 		l, err = newCommit.CommitsBefore()
52 52
 		if err != nil {
53
-			log.GitLogger.Fatal("Find CommitsBefore erro: %v", err)
53
+			return fmt.Errorf("Find CommitsBefore erro: %v", err)
54 54
 		}
55 55
 	} else {
56 56
 		l, err = newCommit.CommitsBeforeUntil(oldCommitId)
57 57
 		if err != nil {
58
-			log.GitLogger.Fatal("Find CommitsBeforeUntil erro: %v", err)
59
-			return
58
+			return fmt.Errorf("Find CommitsBeforeUntil erro: %v", err)
60 59
 		}
61 60
 	}
62 61
 
63 62
 	if err != nil {
64
-		log.GitLogger.Fatal("runUpdate.Commit repoId: %v", err)
63
+		return fmt.Errorf("runUpdate.Commit repoId: %v", err)
65 64
 	}
66 65
 
67 66
 	ru, err := GetUserByName(repoUserName)
68 67
 	if err != nil {
69
-		log.GitLogger.Fatal("runUpdate.GetUserByName: %v", err)
68
+		return fmt.Errorf("runUpdate.GetUserByName: %v", err)
70 69
 	}
71 70
 
72 71
 	repos, err := GetRepositoryByName(ru.Id, repoName)
73 72
 	if err != nil {
74
-		log.GitLogger.Fatal("runUpdate.GetRepositoryByName userId: %v", err)
73
+		return fmt.Errorf("runUpdate.GetRepositoryByName userId: %v", err)
75 74
 	}
76 75
 
77 76
 	commits := make([]*base.PushCommit, 0)
@@ -95,6 +94,7 @@ func Update(refName, oldCommitId, newCommitId, userName, repoUserName, repoName
95 94
 	//commits = append(commits, []string{lastCommit.Id().String(), lastCommit.Message()})
96 95
 	if err = CommitRepoAction(userId, ru.Id, userName, actEmail,
97 96
 		repos.Id, repoUserName, repoName, refName, &base.PushCommits{l.Len(), commits}); err != nil {
98
-		log.GitLogger.Fatal("runUpdate.models.CommitRepoAction: %s/%s:%v", repoUserName, repoName, err)
97
+		return fmt.Errorf("runUpdate.models.CommitRepoAction: %s/%s:%v", repoUserName, repoName, err)
99 98
 	}
99
+	return nil
100 100
 }

+ 4 - 1
routers/repo/http.go

@@ -141,7 +141,10 @@ func Http(ctx *middleware.Context, params martini.Params) {
141 141
 					newCommitId := fields[1]
142 142
 					refName := fields[2]
143 143
 
144
-					models.Update(refName, oldCommitId, newCommitId, authUsername, username, reponame, authUser.Id)
144
+					if err = models.Update(refName, oldCommitId, newCommitId, authUsername, username, reponame, authUser.Id); err != nil {
145
+						log.GitLogger.Error(err.Error())
146
+						return
147
+					}
145 148
 				}
146 149
 			}
147 150
 		}

+ 1 - 1
templates/VERSION

@@ -1 +1 @@
1
-0.4.5.0622 Alpha
1
+0.4.5.0623 Alpha