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.

306 lines
9.7 KiB

Sign merges, CRUD, Wiki and Repository initialisation with gpg key (#7631) This PR fixes #7598 by providing a configurable way of signing commits across the Gitea instance. Per repository configurability and import/generation of trusted secure keys is not provided by this PR - from a security PoV that's probably impossible to do properly. Similarly web-signing, that is asking the user to sign something, is not implemented - this could be done at a later stage however. ## Features - [x] If commit.gpgsign is set in .gitconfig sign commits and files created through repofiles. (merges should already have been signed.) - [x] Verify commits signed with the default gpg as valid - [x] Signer, Committer and Author can all be different - [x] Allow signer to be arbitrarily different - We still require the key to have an activated email on Gitea. A more complete implementation would be to use a keyserver and mark external-or-unactivated with an "unknown" trust level icon. - [x] Add a signing-key.gpg endpoint to get the default gpg pub key if available - Rather than add a fake web-flow user I've added this as an endpoint on /api/v1/signing-key.gpg - [x] Try to match the default key with a user on gitea - this is done at verification time - [x] Make things configurable? - app.ini configuration done - [x] when checking commits are signed need to check if they're actually verifiable too - [x] Add documentation I have decided that adjusting the docker to create a default gpg key is not the correct thing to do and therefore have not implemented this.
4 years ago
Sign merges, CRUD, Wiki and Repository initialisation with gpg key (#7631) This PR fixes #7598 by providing a configurable way of signing commits across the Gitea instance. Per repository configurability and import/generation of trusted secure keys is not provided by this PR - from a security PoV that's probably impossible to do properly. Similarly web-signing, that is asking the user to sign something, is not implemented - this could be done at a later stage however. ## Features - [x] If commit.gpgsign is set in .gitconfig sign commits and files created through repofiles. (merges should already have been signed.) - [x] Verify commits signed with the default gpg as valid - [x] Signer, Committer and Author can all be different - [x] Allow signer to be arbitrarily different - We still require the key to have an activated email on Gitea. A more complete implementation would be to use a keyserver and mark external-or-unactivated with an "unknown" trust level icon. - [x] Add a signing-key.gpg endpoint to get the default gpg pub key if available - Rather than add a fake web-flow user I've added this as an endpoint on /api/v1/signing-key.gpg - [x] Try to match the default key with a user on gitea - this is done at verification time - [x] Make things configurable? - app.ini configuration done - [x] when checking commits are signed need to check if they're actually verifiable too - [x] Add documentation I have decided that adjusting the docker to create a default gpg key is not the correct thing to do and therefore have not implemented this.
4 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
  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. "path"
  7. "path/filepath"
  8. "strings"
  9. "code.gitea.io/gitea/modules/log"
  10. "github.com/unknwon/com"
  11. )
  12. // enumerates all the policy repository creating
  13. const (
  14. RepoCreatingLastUserVisibility = "last"
  15. RepoCreatingPrivate = "private"
  16. RepoCreatingPublic = "public"
  17. )
  18. // Repository settings
  19. var (
  20. Repository = struct {
  21. DetectedCharsetsOrder []string
  22. DetectedCharsetScore map[string]int `ini:"-"`
  23. AnsiCharset string
  24. ForcePrivate bool
  25. DefaultPrivate string
  26. MaxCreationLimit int
  27. MirrorQueueLength int
  28. PullRequestQueueLength int
  29. PreferredLicenses []string
  30. DisableHTTPGit bool
  31. AccessControlAllowOrigin string
  32. UseCompatSSHURI bool
  33. DefaultCloseIssuesViaCommitsInAnyBranch bool
  34. EnablePushCreateUser bool
  35. EnablePushCreateOrg bool
  36. DisabledRepoUnits []string
  37. DefaultRepoUnits []string
  38. PrefixArchiveFiles bool
  39. DisableMirrors bool
  40. DefaultBranch string
  41. // Repository editor settings
  42. Editor struct {
  43. LineWrapExtensions []string
  44. PreviewableFileModes []string
  45. } `ini:"-"`
  46. // Repository upload settings
  47. Upload struct {
  48. Enabled bool
  49. TempPath string
  50. AllowedTypes []string `delim:"|"`
  51. FileMaxSize int64
  52. MaxFiles int
  53. } `ini:"-"`
  54. // Repository local settings
  55. Local struct {
  56. LocalCopyPath string
  57. } `ini:"-"`
  58. // Pull request settings
  59. PullRequest struct {
  60. WorkInProgressPrefixes []string
  61. CloseKeywords []string
  62. ReopenKeywords []string
  63. DefaultMergeMessageCommitsLimit int
  64. DefaultMergeMessageSize int
  65. DefaultMergeMessageAllAuthors bool
  66. DefaultMergeMessageMaxApprovers int
  67. DefaultMergeMessageOfficialApproversOnly bool
  68. } `ini:"repository.pull-request"`
  69. // Issue Setting
  70. Issue struct {
  71. LockReasons []string
  72. } `ini:"repository.issue"`
  73. Signing struct {
  74. SigningKey string
  75. SigningName string
  76. SigningEmail string
  77. InitialCommit []string
  78. CRUDActions []string `ini:"CRUD_ACTIONS"`
  79. Merges []string
  80. Wiki []string
  81. } `ini:"repository.signing"`
  82. }{
  83. DetectedCharsetsOrder: []string{
  84. "UTF-8",
  85. "UTF-16BE",
  86. "UTF-16LE",
  87. "UTF-32BE",
  88. "UTF-32LE",
  89. "ISO-8859-1",
  90. "windows-1252",
  91. "ISO-8859-2",
  92. "windows-1250",
  93. "ISO-8859-5",
  94. "ISO-8859-6",
  95. "ISO-8859-7",
  96. "windows-1253",
  97. "ISO-8859-8-I",
  98. "windows-1255",
  99. "ISO-8859-8",
  100. "windows-1251",
  101. "windows-1256",
  102. "KOI8-R",
  103. "ISO-8859-9",
  104. "windows-1254",
  105. "Shift_JIS",
  106. "GB18030",
  107. "EUC-JP",
  108. "EUC-KR",
  109. "Big5",
  110. "ISO-2022-JP",
  111. "ISO-2022-KR",
  112. "ISO-2022-CN",
  113. "IBM424_rtl",
  114. "IBM424_ltr",
  115. "IBM420_rtl",
  116. "IBM420_ltr",
  117. },
  118. DetectedCharsetScore: map[string]int{},
  119. AnsiCharset: "",
  120. ForcePrivate: false,
  121. DefaultPrivate: RepoCreatingLastUserVisibility,
  122. MaxCreationLimit: -1,
  123. MirrorQueueLength: 1000,
  124. PullRequestQueueLength: 1000,
  125. PreferredLicenses: []string{"Apache License 2.0,MIT License"},
  126. DisableHTTPGit: false,
  127. AccessControlAllowOrigin: "",
  128. UseCompatSSHURI: false,
  129. DefaultCloseIssuesViaCommitsInAnyBranch: false,
  130. EnablePushCreateUser: false,
  131. EnablePushCreateOrg: false,
  132. DisabledRepoUnits: []string{},
  133. DefaultRepoUnits: []string{},
  134. PrefixArchiveFiles: true,
  135. DisableMirrors: false,
  136. // Repository editor settings
  137. Editor: struct {
  138. LineWrapExtensions []string
  139. PreviewableFileModes []string
  140. }{
  141. LineWrapExtensions: strings.Split(".txt,.md,.markdown,.mdown,.mkd,", ","),
  142. PreviewableFileModes: []string{"markdown"},
  143. },
  144. // Repository upload settings
  145. Upload: struct {
  146. Enabled bool
  147. TempPath string
  148. AllowedTypes []string `delim:"|"`
  149. FileMaxSize int64
  150. MaxFiles int
  151. }{
  152. Enabled: true,
  153. TempPath: "data/tmp/uploads",
  154. AllowedTypes: []string{},
  155. FileMaxSize: 3,
  156. MaxFiles: 5,
  157. },
  158. // Repository local settings
  159. Local: struct {
  160. LocalCopyPath string
  161. }{
  162. LocalCopyPath: "tmp/local-repo",
  163. },
  164. // Pull request settings
  165. PullRequest: struct {
  166. WorkInProgressPrefixes []string
  167. CloseKeywords []string
  168. ReopenKeywords []string
  169. DefaultMergeMessageCommitsLimit int
  170. DefaultMergeMessageSize int
  171. DefaultMergeMessageAllAuthors bool
  172. DefaultMergeMessageMaxApprovers int
  173. DefaultMergeMessageOfficialApproversOnly bool
  174. }{
  175. WorkInProgressPrefixes: []string{"WIP:", "[WIP]"},
  176. // Same as GitHub. See
  177. // https://help.github.com/articles/closing-issues-via-commit-messages
  178. CloseKeywords: strings.Split("close,closes,closed,fix,fixes,fixed,resolve,resolves,resolved", ","),
  179. ReopenKeywords: strings.Split("reopen,reopens,reopened", ","),
  180. DefaultMergeMessageCommitsLimit: 50,
  181. DefaultMergeMessageSize: 5 * 1024,
  182. DefaultMergeMessageAllAuthors: false,
  183. DefaultMergeMessageMaxApprovers: 10,
  184. DefaultMergeMessageOfficialApproversOnly: true,
  185. },
  186. // Issue settings
  187. Issue: struct {
  188. LockReasons []string
  189. }{
  190. LockReasons: strings.Split("Too heated,Off-topic,Spam,Resolved", ","),
  191. },
  192. // Signing settings
  193. Signing: struct {
  194. SigningKey string
  195. SigningName string
  196. SigningEmail string
  197. InitialCommit []string
  198. CRUDActions []string `ini:"CRUD_ACTIONS"`
  199. Merges []string
  200. Wiki []string
  201. }{
  202. SigningKey: "default",
  203. SigningName: "",
  204. SigningEmail: "",
  205. InitialCommit: []string{"always"},
  206. CRUDActions: []string{"pubkey", "twofa", "parentsigned"},
  207. Merges: []string{"pubkey", "twofa", "basesigned", "commitssigned"},
  208. Wiki: []string{"never"},
  209. },
  210. }
  211. RepoRootPath string
  212. ScriptType = "bash"
  213. )
  214. func newRepository() {
  215. homeDir, err := com.HomeDir()
  216. if err != nil {
  217. log.Fatal("Failed to get home directory: %v", err)
  218. }
  219. homeDir = strings.Replace(homeDir, "\\", "/", -1)
  220. // Determine and create root git repository path.
  221. sec := Cfg.Section("repository")
  222. Repository.DisableHTTPGit = sec.Key("DISABLE_HTTP_GIT").MustBool()
  223. Repository.UseCompatSSHURI = sec.Key("USE_COMPAT_SSH_URI").MustBool()
  224. Repository.MaxCreationLimit = sec.Key("MAX_CREATION_LIMIT").MustInt(-1)
  225. Repository.DefaultBranch = sec.Key("DEFAULT_BRANCH").MustString("master")
  226. RepoRootPath = sec.Key("ROOT").MustString(path.Join(homeDir, "gitea-repositories"))
  227. forcePathSeparator(RepoRootPath)
  228. if !filepath.IsAbs(RepoRootPath) {
  229. RepoRootPath = filepath.Join(AppWorkPath, RepoRootPath)
  230. } else {
  231. RepoRootPath = filepath.Clean(RepoRootPath)
  232. }
  233. defaultDetectedCharsetsOrder := make([]string, 0, len(Repository.DetectedCharsetsOrder))
  234. for _, charset := range Repository.DetectedCharsetsOrder {
  235. defaultDetectedCharsetsOrder = append(defaultDetectedCharsetsOrder, strings.ToLower(strings.TrimSpace(charset)))
  236. }
  237. ScriptType = sec.Key("SCRIPT_TYPE").MustString("bash")
  238. if err = Cfg.Section("repository").MapTo(&Repository); err != nil {
  239. log.Fatal("Failed to map Repository settings: %v", err)
  240. } else if err = Cfg.Section("repository.editor").MapTo(&Repository.Editor); err != nil {
  241. log.Fatal("Failed to map Repository.Editor settings: %v", err)
  242. } else if err = Cfg.Section("repository.upload").MapTo(&Repository.Upload); err != nil {
  243. log.Fatal("Failed to map Repository.Upload settings: %v", err)
  244. } else if err = Cfg.Section("repository.local").MapTo(&Repository.Local); err != nil {
  245. log.Fatal("Failed to map Repository.Local settings: %v", err)
  246. } else if err = Cfg.Section("repository.pull-request").MapTo(&Repository.PullRequest); err != nil {
  247. log.Fatal("Failed to map Repository.PullRequest settings: %v", err)
  248. }
  249. preferred := make([]string, 0, len(Repository.DetectedCharsetsOrder))
  250. for _, charset := range Repository.DetectedCharsetsOrder {
  251. canonicalCharset := strings.ToLower(strings.TrimSpace(charset))
  252. preferred = append(preferred, canonicalCharset)
  253. // remove it from the defaults
  254. for i, charset := range defaultDetectedCharsetsOrder {
  255. if charset == canonicalCharset {
  256. defaultDetectedCharsetsOrder = append(defaultDetectedCharsetsOrder[:i], defaultDetectedCharsetsOrder[i+1:]...)
  257. break
  258. }
  259. }
  260. }
  261. i := 0
  262. for _, charset := range preferred {
  263. // Add the defaults
  264. if charset == "defaults" {
  265. for _, charset := range defaultDetectedCharsetsOrder {
  266. canonicalCharset := strings.ToLower(strings.TrimSpace(charset))
  267. if _, has := Repository.DetectedCharsetScore[canonicalCharset]; !has {
  268. Repository.DetectedCharsetScore[canonicalCharset] = i
  269. i++
  270. }
  271. }
  272. continue
  273. }
  274. if _, has := Repository.DetectedCharsetScore[charset]; !has {
  275. Repository.DetectedCharsetScore[charset] = i
  276. i++
  277. }
  278. }
  279. if !filepath.IsAbs(Repository.Upload.TempPath) {
  280. Repository.Upload.TempPath = path.Join(AppWorkPath, Repository.Upload.TempPath)
  281. }
  282. }