Skip to content

Commit

Permalink
New UI merge in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
unknwon committed Jul 26, 2014
1 parent 0a739cf commit 8dd07c0
Show file tree
Hide file tree
Showing 199 changed files with 15,143 additions and 9,438 deletions.
17 changes: 17 additions & 0 deletions .bra.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[run]
init_cmds = [["./gogs", "web"]]
watch_all = true
watch_dirs = [
"$WORKDIR/conf/locale",
"$WORKDIR/cmd",
"$WORKDIR/models",
"$WORKDIR/modules",
"$WORKDIR/routers"
]
watch_exts = [".go", ".ini"]
build_delay = 1500
cmds = [
["go", "install"],
["go", "build"],
["./gogs", "web"]
]
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ gogs
__pycache__
*.pem
output*
config.codekit
23 changes: 0 additions & 23 deletions bee.json

This file was deleted.

47 changes: 23 additions & 24 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import (
"os/exec"
"path"
"path/filepath"
"strconv"
"strings"

"github.com/codegangsta/cli"

"github.com/Unknwon/com"

"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/setting"
Expand Down Expand Up @@ -81,22 +82,22 @@ func runServ(k *cli.Context) {
keys := strings.Split(os.Args[2], "-")
if len(keys) != 2 {
println("Gogs: auth file format error")
log.GitLogger.Fatal("Invalid auth file format: %s", os.Args[2])
log.GitLogger.Fatal(2, "Invalid auth file format: %s", os.Args[2])
}

keyId, err := strconv.ParseInt(keys[1], 10, 64)
keyId, err := com.StrTo(keys[1]).Int64()
if err != nil {
println("Gogs: auth file format error")
log.GitLogger.Fatal("Invalid auth file format: %v", err)
log.GitLogger.Fatal(2, "Invalid auth file format: %v", err)
}
user, err := models.GetUserByKeyId(keyId)
if err != nil {
if err == models.ErrUserNotKeyOwner {
println("Gogs: you are not the owner of SSH key")
log.GitLogger.Fatal("Invalid owner of SSH key: %d", keyId)
log.GitLogger.Fatal(2, "Invalid owner of SSH key: %d", keyId)
}
println("Gogs: internal error:", err)
log.GitLogger.Fatal("Fail to get user by key ID(%d): %v", keyId, err)
log.GitLogger.Fatal(2, "Fail to get user by key ID(%d): %v", keyId, err)
}

cmd := os.Getenv("SSH_ORIGINAL_COMMAND")
Expand All @@ -110,7 +111,7 @@ func runServ(k *cli.Context) {
rr := strings.SplitN(repoPath, "/", 2)
if len(rr) != 2 {
println("Gogs: unavailable repository", args)
log.GitLogger.Fatal("Unavailable repository: %v", args)
log.GitLogger.Fatal(2, "Unavailable repository: %v", args)
}
repoUserName := rr[0]
repoName := strings.TrimSuffix(rr[1], ".git")
Expand All @@ -122,10 +123,10 @@ func runServ(k *cli.Context) {
if err != nil {
if err == models.ErrUserNotExist {
println("Gogs: given repository owner are not registered")
log.GitLogger.Fatal("Unregistered owner: %s", repoUserName)
log.GitLogger.Fatal(2, "Unregistered owner: %s", repoUserName)
}
println("Gogs: internal error:", err)
log.GitLogger.Fatal("Fail to get repository owner(%s): %v", repoUserName, err)
log.GitLogger.Fatal(2, "Fail to get repository owner(%s): %v", repoUserName, err)
}

// Access check.
Expand All @@ -134,20 +135,20 @@ func runServ(k *cli.Context) {
has, err := models.HasAccess(user.Name, path.Join(repoUserName, repoName), models.WRITABLE)
if err != nil {
println("Gogs: internal error:", err)
log.GitLogger.Fatal("Fail to check write access:", err)
log.GitLogger.Fatal(2, "Fail to check write access:", err)
} else if !has {
println("You have no right to write this repository")
log.GitLogger.Fatal("User %s has no right to write repository %s", user.Name, repoPath)
log.GitLogger.Fatal(2, "User %s has no right to write repository %s", user.Name, repoPath)
}
case isRead:
repo, err := models.GetRepositoryByName(repoUser.Id, repoName)
if err != nil {
if err == models.ErrRepoNotExist {
println("Gogs: given repository does not exist")
log.GitLogger.Fatal("Repository does not exist: %s/%s", repoUser.Name, repoName)
log.GitLogger.Fatal(2, "Repository does not exist: %s/%s", repoUser.Name, repoName)
}
println("Gogs: internal error:", err)
log.GitLogger.Fatal("Fail to get repository: %v", err)
log.GitLogger.Fatal(2, "Fail to get repository: %v", err)
}

if !repo.IsPrivate {
Expand All @@ -157,10 +158,10 @@ func runServ(k *cli.Context) {
has, err := models.HasAccess(user.Name, path.Join(repoUserName, repoName), models.READABLE)
if err != nil {
println("Gogs: internal error:", err)
log.GitLogger.Fatal("Fail to check read access:", err)
log.GitLogger.Fatal(2, "Fail to check read access:", err)
} else if !has {
println("You have no right to access this repository")
log.GitLogger.Fatal("User %s has no right to read repository %s", user.Name, repoPath)
log.GitLogger.Fatal(2, "User %s has no right to read repository %s", user.Name, repoPath)
}
default:
println("Unknown command")
Expand All @@ -175,29 +176,27 @@ func runServ(k *cli.Context) {
gitcmd.Stdout = os.Stdout
gitcmd.Stdin = os.Stdin
gitcmd.Stderr = os.Stderr
err = gitcmd.Run()
if err != nil {
println("Gogs: internal error:", err)
log.GitLogger.Fatal("Fail to execute git command: %v", err)
if err = gitcmd.Run(); err != nil {
println("Gogs: internal error:", err.Error())
log.GitLogger.Fatal(2, "Fail to execute git command: %v", err)
}

if isWrite {
tasks, err := models.GetUpdateTasksByUuid(uuid)
if err != nil {
log.GitLogger.Fatal("Fail to get update task: %v", err)
log.GitLogger.Fatal(2, "Fail to get update task: %v", err)
}

for _, task := range tasks {
err = models.Update(task.RefName, task.OldCommitId, task.NewCommitId,
user.Name, repoUserName, repoName, user.Id)
if err != nil {
log.GitLogger.Fatal("Fail to update: %v", err)
log.GitLogger.Fatal(2, "Fail to update: %v", err)
}
}

err = models.DelUpdateTasksByUuid(uuid)
if err != nil {
log.GitLogger.Fatal("Fail to del update task: %v", err)
if err = models.DelUpdateTasksByUuid(uuid); err != nil {
log.GitLogger.Fatal(2, "Fail to del update task: %v", err)
}
}
}
7 changes: 4 additions & 3 deletions cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"

"github.com/codegangsta/cli"

"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/log"
)
Expand All @@ -30,9 +31,9 @@ func runUpdate(c *cli.Context) {

args := c.Args()
if len(args) != 3 {
log.GitLogger.Fatal("received less 3 parameters")
log.GitLogger.Fatal(2, "received less 3 parameters")
} else if args[0] == "" {
log.GitLogger.Fatal("refName is empty, shouldn't use")
log.GitLogger.Fatal(2, "refName is empty, shouldn't use")
}

uuid := os.Getenv("uuid")
Expand All @@ -45,6 +46,6 @@ func runUpdate(c *cli.Context) {
}

if err := models.AddUpdateTask(&task); err != nil {
log.GitLogger.Fatal(err.Error())
log.GitLogger.Fatal(2, err.Error())
}
}
Loading

0 comments on commit 8dd07c0

Please sign in to comment.