summaryrefslogtreecommitdiffstats
path: root/update.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2014-03-16 12:18:34 +0800
committerLunny Xiao <xiaolunwen@gmail.com>2014-03-16 12:18:34 +0800
commit3035a38caab5308ef30720760c99594fd9434176 (patch)
tree5582169bbb32538651e1a5c71546cd002f002888 /update.go
parentf047df6e2b69ecb41c3fe4bef746145916aa4063 (diff)
downloadgitea-3035a38caab5308ef30720760c99594fd9434176.tar.gz
gitea-3035a38caab5308ef30720760c99594fd9434176.zip
add update
Diffstat (limited to 'update.go')
-rw-r--r--update.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/update.go b/update.go
new file mode 100644
index 0000000000..339b3ab94f
--- /dev/null
+++ b/update.go
@@ -0,0 +1,51 @@
+package main
+
+import (
+ "os"
+ "strconv"
+
+ "github.com/gogits/gogs/models"
+
+ "github.com/codegangsta/cli"
+ git "github.com/gogits/git"
+)
+
+var CmdUpdate = cli.Command{
+ Name: "update",
+ Usage: "This command just should be called by ssh shell",
+ Description: `
+gogs serv provide access auth for repositories`,
+ Action: runUpdate,
+ Flags: []cli.Flag{},
+}
+
+func runUpdate(*cli.Context) {
+ userName := os.Getenv("userName")
+ userId := os.Getenv("userId")
+ repoId := os.Getenv("repoId")
+ repoName := os.Getenv("repoName")
+
+ f := models.RepoPath(userName, repoName)
+
+ repo, err := git.OpenRepository(f)
+ if err != nil {
+ return
+ }
+
+ ref, err := repo.LookupReference("HEAD")
+ if err != nil {
+ return
+ }
+
+ lastCommit, err := repo.LookupCommit(ref.Oid)
+ if err != nil {
+ return
+ }
+ sUserId, _ := strconv.Atoi(userId)
+ sRepoId, _ := strconv.Atoi(repoId)
+ err = models.CommitRepoAction(int64(sUserId), userName,
+ int64(sRepoId), repoName, lastCommit.Message())
+ if err != nil {
+ //TODO: log
+ }
+}