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
9 years ago
11 years ago
11 years ago
11 years ago
11 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. "github.com/go-gitea/gitea/models"
  9. "github.com/go-gitea/gitea/modules/log"
  10. "github.com/go-gitea/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. stringFlag("config, c", "custom/conf/app.ini", "Custom configuration file path"),
  20. },
  21. }
  22. func runUpdate(c *cli.Context) error {
  23. if c.IsSet("config") {
  24. setting.CustomConf = c.String("config")
  25. }
  26. setup("update.log")
  27. if len(os.Getenv("SSH_ORIGINAL_COMMAND")) == 0 {
  28. log.GitLogger.Trace("SSH_ORIGINAL_COMMAND is empty")
  29. return nil
  30. }
  31. args := c.Args()
  32. if len(args) != 3 {
  33. log.GitLogger.Fatal(2, "Arguments received are not equal to three")
  34. } else if len(args[0]) == 0 {
  35. log.GitLogger.Fatal(2, "First argument 'refName' is empty, shouldn't use")
  36. }
  37. task := models.UpdateTask{
  38. UUID: os.Getenv("uuid"),
  39. RefName: args[0],
  40. OldCommitID: args[1],
  41. NewCommitID: args[2],
  42. }
  43. if err := models.AddUpdateTask(&task); err != nil {
  44. log.GitLogger.Fatal(2, "AddUpdateTask: %v", err)
  45. }
  46. return nil
  47. }