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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 cmd
  5. import (
  6. "os"
  7. "github.com/urfave/cli"
  8. "code.gitea.io/gitea/models"
  9. "code.gitea.io/gitea/modules/log"
  10. "code.gitea.io/gitea/modules/setting"
  11. )
  12. // CmdUpdate represents the available update sub-command.
  13. var CmdUpdate = cli.Command{
  14. Name: "update",
  15. Usage: "This command should only be called by Git hook",
  16. Description: `Update get pushed info and insert into database`,
  17. Action: runUpdate,
  18. Flags: []cli.Flag{
  19. cli.StringFlag{
  20. Name: "config, c",
  21. Value: "custom/conf/app.ini",
  22. Usage: "Custom configuration file path",
  23. },
  24. },
  25. }
  26. func runUpdate(c *cli.Context) error {
  27. if c.IsSet("config") {
  28. setting.CustomConf = c.String("config")
  29. }
  30. setup("update.log")
  31. if len(os.Getenv("SSH_ORIGINAL_COMMAND")) == 0 {
  32. log.GitLogger.Trace("SSH_ORIGINAL_COMMAND is empty")
  33. return nil
  34. }
  35. args := c.Args()
  36. if len(args) != 3 {
  37. log.GitLogger.Fatal(2, "Arguments received are not equal to three")
  38. } else if len(args[0]) == 0 {
  39. log.GitLogger.Fatal(2, "First argument 'refName' is empty, shouldn't use")
  40. }
  41. task := models.UpdateTask{
  42. UUID: os.Getenv("uuid"),
  43. RefName: args[0],
  44. OldCommitID: args[1],
  45. NewCommitID: args[2],
  46. }
  47. if err := models.AddUpdateTask(&task); err != nil {
  48. log.GitLogger.Fatal(2, "AddUpdateTask: %v", err)
  49. }
  50. return nil
  51. }