summaryrefslogtreecommitdiffstats
path: root/update.go
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-03-16 02:28:28 -0400
committerUnknown <joe2010xtmf@163.com>2014-03-16 02:28:28 -0400
commit50df58a893b745abff74bdcbb9be3fc0d10d21f4 (patch)
tree7753f6095090e3f0f60a15223fdf3074f0dfb11f /update.go
parent828c89de996c328bb3759d90be8a8a35b4d9cdc0 (diff)
parent795dad786189aeba9c61452e395bb4ecf5fc2cb9 (diff)
downloadgitea-50df58a893b745abff74bdcbb9be3fc0d10d21f4.tar.gz
gitea-50df58a893b745abff74bdcbb9be3fc0d10d21f4.zip
Merge branch 'master' of github.com:gogits/gogs
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
+ }
+}