module.go 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2020 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 gitutil
  5. import (
  6. "github.com/gogs/git-module"
  7. )
  8. // ModuleStore is the interface for Git operations.
  9. //
  10. // NOTE: All methods are sorted in alphabetical order.
  11. type ModuleStore interface {
  12. // RemoteAdd adds a new remote to the repository in given path.
  13. RemoteAdd(repoPath, name, url string, opts ...git.RemoteAddOptions) error
  14. // DiffNameOnly returns a list of changed files between base and head revisions
  15. // of the repository in given path.
  16. DiffNameOnly(repoPath, base, head string, opts ...git.DiffNameOnlyOptions) ([]string, error)
  17. // Log returns a list of commits in the state of given revision of the
  18. // repository in given path. The returned list is in reverse chronological
  19. // order.
  20. Log(repoPath, rev string, opts ...git.LogOptions) ([]*git.Commit, error)
  21. // MergeBase returns merge base between base and head revisions of the
  22. // repository in given path.
  23. MergeBase(repoPath, base, head string, opts ...git.MergeBaseOptions) (string, error)
  24. // RemoteRemove removes a remote from the repository in given path.
  25. RemoteRemove(repoPath, name string, opts ...git.RemoteRemoveOptions) error
  26. // RepoTags returns a list of tags of the repository in given path.
  27. RepoTags(repoPath string, opts ...git.TagsOptions) ([]string, error)
  28. // PullRequestMeta gathers pull request metadata based on given head and base
  29. // information.
  30. PullRequestMeta(headPath, basePath, headBranch, baseBranch string) (*PullRequestMeta, error)
  31. // ListTagsAfter returns a list of tags "after" (exclusive) given tag.
  32. ListTagsAfter(repoPath, after string, limit int) (*TagsPage, error)
  33. }
  34. // module holds the real implementation.
  35. type module struct{}
  36. func (module) RemoteAdd(repoPath, name, url string, opts ...git.RemoteAddOptions) error {
  37. return git.RemoteAdd(repoPath, name, url, opts...)
  38. }
  39. func (module) DiffNameOnly(repoPath, base, head string, opts ...git.DiffNameOnlyOptions) ([]string, error) {
  40. return git.DiffNameOnly(repoPath, base, head, opts...)
  41. }
  42. func (module) Log(repoPath, rev string, opts ...git.LogOptions) ([]*git.Commit, error) {
  43. return git.Log(repoPath, rev, opts...)
  44. }
  45. func (module) MergeBase(repoPath, base, head string, opts ...git.MergeBaseOptions) (string, error) {
  46. return git.MergeBase(repoPath, base, head, opts...)
  47. }
  48. func (module) RemoteRemove(repoPath, name string, opts ...git.RemoteRemoveOptions) error {
  49. return git.RemoteRemove(repoPath, name, opts...)
  50. }
  51. func (module) RepoTags(repoPath string, opts ...git.TagsOptions) ([]string, error) {
  52. return git.RepoTags(repoPath, opts...)
  53. }
  54. // Module is a mockable interface for Git operations.
  55. var Module ModuleStore = module{}