You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.4 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package main
  5. import (
  6. "os"
  7. "strconv"
  8. "github.com/codegangsta/cli"
  9. git "github.com/gogits/git"
  10. "github.com/gogits/gogs/models"
  11. "github.com/gogits/gogs/modules/log"
  12. )
  13. var CmdUpdate = cli.Command{
  14. Name: "update",
  15. Usage: "This command just should be called by ssh shell",
  16. Description: `
  17. gogs serv provide access auth for repositories`,
  18. Action: runUpdate,
  19. Flags: []cli.Flag{},
  20. }
  21. func runUpdate(*cli.Context) {
  22. userName := os.Getenv("userName")
  23. userId := os.Getenv("userId")
  24. repoId := os.Getenv("repoId")
  25. repoName := os.Getenv("repoName")
  26. f := models.RepoPath(userName, repoName)
  27. repo, err := git.OpenRepository(f)
  28. if err != nil {
  29. return
  30. }
  31. ref, err := repo.LookupReference("HEAD")
  32. if err != nil {
  33. return
  34. }
  35. lastCommit, err := repo.LookupCommit(ref.Oid)
  36. if err != nil {
  37. return
  38. }
  39. sUserId, err := strconv.Atoi(userId)
  40. if err != nil {
  41. log.Error("runUpdate.Parse userId: %v", err)
  42. return
  43. }
  44. sRepoId, err := strconv.Atoi(repoId)
  45. if err != nil {
  46. log.Error("runUpdate.Parse repoId: %v", err)
  47. return
  48. }
  49. if err = models.CommitRepoAction(int64(sUserId), userName,
  50. int64(sRepoId), repoName, lastCommit.Message()); err != nil {
  51. log.Error("runUpdate.models.CommitRepoAction: %v", err)
  52. }
  53. }