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.

git.go 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2019 The Gitea 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 setting
  5. import (
  6. "time"
  7. "code.gitea.io/gitea/modules/git"
  8. "code.gitea.io/gitea/modules/log"
  9. version "github.com/mcuadros/go-version"
  10. )
  11. var (
  12. // Git settings
  13. Git = struct {
  14. DisableDiffHighlight bool
  15. MaxGitDiffLines int
  16. MaxGitDiffLineCharacters int
  17. MaxGitDiffFiles int
  18. GCArgs []string `delim:" "`
  19. Timeout struct {
  20. Default int
  21. Migrate int
  22. Mirror int
  23. Clone int
  24. Pull int
  25. GC int `ini:"GC"`
  26. } `ini:"git.timeout"`
  27. }{
  28. DisableDiffHighlight: false,
  29. MaxGitDiffLines: 1000,
  30. MaxGitDiffLineCharacters: 5000,
  31. MaxGitDiffFiles: 100,
  32. GCArgs: []string{},
  33. Timeout: struct {
  34. Default int
  35. Migrate int
  36. Mirror int
  37. Clone int
  38. Pull int
  39. GC int `ini:"GC"`
  40. }{
  41. Default: int(git.DefaultCommandExecutionTimeout / time.Second),
  42. Migrate: 600,
  43. Mirror: 300,
  44. Clone: 300,
  45. Pull: 300,
  46. GC: 60,
  47. },
  48. }
  49. )
  50. func newGit() {
  51. if err := Cfg.Section("git").MapTo(&Git); err != nil {
  52. log.Fatal("Failed to map Git settings: %v", err)
  53. }
  54. git.DefaultCommandExecutionTimeout = time.Duration(Git.Timeout.Default) * time.Second
  55. binVersion, err := git.BinVersion()
  56. if err != nil {
  57. log.Fatal("Error retrieving git version: %v", err)
  58. }
  59. log.Info("Git Version: %s", binVersion)
  60. if version.Compare(binVersion, "2.9", ">=") {
  61. // Explicitly disable credential helper, otherwise Git credentials might leak
  62. git.GlobalCommandArgs = append(git.GlobalCommandArgs, "-c", "credential.helper=")
  63. }
  64. }