module.go 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. // AddRemote adds a new remote to the repository in given path.
  13. RepoAddRemote(repoPath, name, url string, opts ...git.AddRemoteOptions) error
  14. // RepoDiffNameOnly returns a list of changed files between base and head revisions
  15. // of the repository in given path.
  16. RepoDiffNameOnly(repoPath, base, head string, opts ...git.DiffNameOnlyOptions) ([]string, error)
  17. // RepoLog returns a list of commits in the state of given revision of the repository
  18. // in given path. The returned list is in reverse chronological order.
  19. RepoLog(repoPath, rev string, opts ...git.LogOptions) ([]*git.Commit, error)
  20. // RepoMergeBase returns merge base between base and head revisions of the repository
  21. // in given path.
  22. RepoMergeBase(repoPath, base, head string, opts ...git.MergeBaseOptions) (string, error)
  23. // RepoRemoveRemote removes a remote from the repository in given path.
  24. RepoRemoveRemote(repoPath, name string, opts ...git.RemoveRemoteOptions) error
  25. // RepoTags returns a list of tags of the repository in given path.
  26. RepoTags(repoPath string, opts ...git.TagsOptions) ([]string, error)
  27. // GetPullRequestMeta gathers pull request metadata based on given head and base information.
  28. PullRequestMeta(headPath, basePath, headBranch, baseBranch string) (*PullRequestMeta, error)
  29. // ListTagsAfter returns a list of tags "after" (exclusive) given tag.
  30. ListTagsAfter(repoPath, after string, limit int) (*TagsPage, error)
  31. }
  32. // module holds the real implementation.
  33. type module struct{}
  34. func (module) RepoAddRemote(repoPath, name, url string, opts ...git.AddRemoteOptions) error {
  35. return git.RepoAddRemote(repoPath, name, url, opts...)
  36. }
  37. func (module) RepoDiffNameOnly(repoPath, base, head string, opts ...git.DiffNameOnlyOptions) ([]string, error) {
  38. return git.RepoDiffNameOnly(repoPath, base, head, opts...)
  39. }
  40. func (module) RepoLog(repoPath, rev string, opts ...git.LogOptions) ([]*git.Commit, error) {
  41. return git.RepoLog(repoPath, rev, opts...)
  42. }
  43. func (module) RepoMergeBase(repoPath, base, head string, opts ...git.MergeBaseOptions) (string, error) {
  44. return git.RepoMergeBase(repoPath, base, head, opts...)
  45. }
  46. func (module) RepoRemoveRemote(repoPath, name string, opts ...git.RemoveRemoteOptions) error {
  47. return git.RepoRemoveRemote(repoPath, name, opts...)
  48. }
  49. func (module) RepoTags(repoPath string, opts ...git.TagsOptions) ([]string, error) {
  50. return git.RepoTags(repoPath, opts...)
  51. }
  52. // Module is a mockable interface for Git operations.
  53. var Module ModuleStore = module{}