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

update.go 1.5 kB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. "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. // for command: ./gogs update
  22. func runUpdate(*cli.Context) {
  23. userName := os.Getenv("userName")
  24. userId := os.Getenv("userId")
  25. repoId := os.Getenv("repoId")
  26. repoName := os.Getenv("repoName")
  27. f := models.RepoPath(userName, repoName)
  28. repo, err := git.OpenRepository(f)
  29. if err != nil {
  30. return
  31. }
  32. ref, err := repo.LookupReference("HEAD")
  33. if err != nil {
  34. return
  35. }
  36. lastCommit, err := repo.LookupCommit(ref.Oid)
  37. if err != nil {
  38. return
  39. }
  40. sUserId, err := strconv.Atoi(userId)
  41. if err != nil {
  42. log.Error("runUpdate.Parse userId: %v", err)
  43. return
  44. }
  45. sRepoId, err := strconv.Atoi(repoId)
  46. if err != nil {
  47. log.Error("runUpdate.Parse repoId: %v", err)
  48. return
  49. }
  50. commits := make([][]string, 0)
  51. commits = append(commits, []string{lastCommit.Id().String(), lastCommit.Message()})
  52. if err = models.CommitRepoAction(int64(sUserId), userName,
  53. int64(sRepoId), repoName, commits); err != nil {
  54. log.Error("runUpdate.models.CommitRepoAction: %v", err)
  55. }
  56. }