gitea源码

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package cmd
  4. import (
  5. "context"
  6. "strings"
  7. "code.gitea.io/gitea/modules/private"
  8. "code.gitea.io/gitea/modules/setting"
  9. "github.com/urfave/cli/v3"
  10. )
  11. // CmdRestoreRepository represents the available restore a repository sub-command.
  12. var CmdRestoreRepository = &cli.Command{
  13. Name: "restore-repo",
  14. Usage: "Restore the repository from disk",
  15. Description: "This is a command for restoring the repository data.",
  16. Action: runRestoreRepository,
  17. Flags: []cli.Flag{
  18. &cli.StringFlag{
  19. Name: "repo_dir",
  20. Aliases: []string{"r"},
  21. Value: "./data",
  22. Usage: "Repository dir path to restore from",
  23. },
  24. &cli.StringFlag{
  25. Name: "owner_name",
  26. Value: "",
  27. Usage: "Restore destination owner name",
  28. },
  29. &cli.StringFlag{
  30. Name: "repo_name",
  31. Value: "",
  32. Usage: "Restore destination repository name",
  33. },
  34. &cli.StringFlag{
  35. Name: "units",
  36. Value: "",
  37. Usage: `Which items will be restored, one or more units should be separated as comma.
  38. wiki, issues, labels, releases, release_assets, milestones, pull_requests, comments are allowed. Empty means all units.`,
  39. },
  40. &cli.BoolFlag{
  41. Name: "validation",
  42. Usage: "Sanity check the content of the files before trying to load them",
  43. },
  44. },
  45. }
  46. func runRestoreRepository(ctx context.Context, c *cli.Command) error {
  47. setting.MustInstalled()
  48. var units []string
  49. if s := c.String("units"); s != "" {
  50. units = strings.Split(s, ",")
  51. }
  52. extra := private.RestoreRepo(
  53. ctx,
  54. c.String("repo_dir"),
  55. c.String("owner_name"),
  56. c.String("repo_name"),
  57. units,
  58. c.Bool("validation"),
  59. )
  60. return handleCliResponseExtra(extra)
  61. }