Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2021-10-18 09:35:24 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2021-10-25 13:38:52 +0300
commit9ce1e9ebe58a4646c393236f6183a78456b1a6ef (patch)
tree5f205834006d2cff538b3480ea427e6c3ff9c63f
parent6ad960b2f7c75e20836fa6b5ce2abaaa4d4076b5 (diff)
git: Drop Remote interface
The only implementation of the Remote interface, which is part of the localrepo interface, isn't used by anything anymore, and in fact we don't want to gain any new users either: on-disk remotes are not used in Gitaly anymore. Remove both the implementation and its interface.
-rw-r--r--internal/git/localrepo/remote.go164
-rw-r--r--internal/git/localrepo/remote_test.go308
-rw-r--r--internal/git/localrepo/repo.go5
-rw-r--r--internal/git/remote.go79
4 files changed, 17 insertions, 539 deletions
diff --git a/internal/git/localrepo/remote.go b/internal/git/localrepo/remote.go
index a490473a9..97c02e222 100644
--- a/internal/git/localrepo/remote.go
+++ b/internal/git/localrepo/remote.go
@@ -1,7 +1,6 @@
package localrepo
import (
- "bufio"
"bytes"
"context"
"errors"
@@ -14,169 +13,6 @@ import (
"gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
)
-// Remote provides functionality of the 'remote' git sub-command.
-type Remote struct {
- repo *Repo
-}
-
-// Add adds a new remote to the repository.
-func (remote Remote) Add(ctx context.Context, name, url string, opts git.RemoteAddOpts) error {
- if err := validateNotBlank(name, "name"); err != nil {
- return err
- }
-
- if err := validateNotBlank(url, "url"); err != nil {
- return err
- }
-
- var stderr bytes.Buffer
- if err := remote.repo.ExecAndWait(ctx,
- git.SubSubCmd{
- Name: "remote",
- Action: "add",
- Flags: buildRemoteAddOptsFlags(opts),
- Args: []string{name, url},
- },
- git.WithStderr(&stderr),
- git.WithRefTxHook(ctx, remote.repo, remote.repo.cfg),
- ); err != nil {
- switch {
- case isExitWithCode(err, 3):
- // In Git v2.30.0 and newer (https://gitlab.com/git-vcs/git/commit/9144ba4cf52)
- return git.ErrAlreadyExists
- case isExitWithCode(err, 128) && bytes.HasPrefix(stderr.Bytes(), []byte("fatal: remote "+name+" already exists")):
- // ..in older versions we parse stderr
- return git.ErrAlreadyExists
- }
-
- return err
- }
-
- return nil
-}
-
-func buildRemoteAddOptsFlags(opts git.RemoteAddOpts) []git.Option {
- var flags []git.Option
- for _, b := range opts.RemoteTrackingBranches {
- flags = append(flags, git.ValueFlag{Name: "-t", Value: b})
- }
-
- if opts.DefaultBranch != "" {
- flags = append(flags, git.ValueFlag{Name: "-m", Value: opts.DefaultBranch})
- }
-
- if opts.Fetch {
- flags = append(flags, git.Flag{Name: "-f"})
- }
-
- if opts.Tags != git.RemoteAddOptsTagsDefault {
- flags = append(flags, git.Flag{Name: opts.Tags.String()})
- }
-
- if opts.Mirror != git.RemoteAddOptsMirrorDefault {
- flags = append(flags, git.ValueFlag{Name: "--mirror", Value: opts.Mirror.String()})
- }
-
- return flags
-}
-
-// Remove removes a named remote from the repository configuration.
-func (remote Remote) Remove(ctx context.Context, name string) error {
- if err := validateNotBlank(name, "name"); err != nil {
- return err
- }
-
- var stderr bytes.Buffer
- if err := remote.repo.ExecAndWait(ctx,
- git.SubSubCmd{
- Name: "remote",
- Action: "remove",
- Args: []string{name},
- },
- git.WithStderr(&stderr),
- git.WithRefTxHook(ctx, remote.repo, remote.repo.cfg),
- ); err != nil {
- switch {
- case isExitWithCode(err, 2):
- // In Git v2.30.0 and newer (https://gitlab.com/git-vcs/git/commit/9144ba4cf52)
- return git.ErrNotFound
- case isExitWithCode(err, 128) && strings.HasPrefix(stderr.String(), "fatal: No such remote"):
- // ..in older versions we parse stderr
- return git.ErrNotFound
- }
-
- return err
- }
-
- return nil
-}
-
-// SetURL sets the URL for a given remote.
-func (remote Remote) SetURL(ctx context.Context, name, url string, opts git.SetURLOpts) error {
- if err := validateNotBlank(name, "name"); err != nil {
- return err
- }
-
- if err := validateNotBlank(url, "url"); err != nil {
- return err
- }
-
- var stderr bytes.Buffer
- if err := remote.repo.ExecAndWait(ctx,
- git.SubSubCmd{
- Name: "remote",
- Action: "set-url",
- Flags: buildSetURLOptsFlags(opts),
- Args: []string{name, url},
- },
- git.WithStderr(&stderr),
- git.WithRefTxHook(ctx, remote.repo, remote.repo.cfg),
- ); err != nil {
- switch {
- case isExitWithCode(err, 2):
- // In Git v2.30.0 and newer (https://gitlab.com/git-vcs/git/commit/9144ba4cf52)
- return git.ErrNotFound
- case isExitWithCode(err, 128) && strings.HasPrefix(stderr.String(), "fatal: No such remote"):
- // ..in older versions we parse stderr
- return git.ErrNotFound
- }
-
- return err
- }
-
- return nil
-}
-
-// Exists determines whether a given named remote exists.
-func (remote Remote) Exists(ctx context.Context, name string) (bool, error) {
- cmd, err := remote.repo.Exec(ctx,
- git.SubCmd{Name: "remote"},
- git.WithRefTxHook(ctx, remote.repo, remote.repo.cfg),
- )
- if err != nil {
- return false, err
- }
-
- found := false
- scanner := bufio.NewScanner(cmd)
- for scanner.Scan() {
- if scanner.Text() == name {
- found = true
- break
- }
- }
-
- return found, cmd.Wait()
-}
-
-func buildSetURLOptsFlags(opts git.SetURLOpts) []git.Option {
- if opts.Push {
- return []git.Option{git.Flag{Name: "--push"}}
- }
-
- return nil
-}
-
// FetchOptsTags controls what tags needs to be imported on fetch.
type FetchOptsTags string
diff --git a/internal/git/localrepo/remote_test.go b/internal/git/localrepo/remote_test.go
index 547f0cf90..d41157bc6 100644
--- a/internal/git/localrepo/remote_test.go
+++ b/internal/git/localrepo/remote_test.go
@@ -9,319 +9,43 @@ import (
"path/filepath"
"testing"
- "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/v14/internal/git"
"gitlab.com/gitlab-org/gitaly/v14/internal/git/catfile"
"gitlab.com/gitlab-org/gitaly/v14/internal/git/gittest"
- "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/config"
- "gitlab.com/gitlab-org/gitaly/v14/internal/helper/text"
"gitlab.com/gitlab-org/gitaly/v14/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testcfg"
- "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
)
-func setupRepoRemote(t *testing.T, bare bool) (Remote, string) {
- t.Helper()
+func TestRepo_FetchRemote(t *testing.T) {
+ ctx, cancel := testhelper.Context()
+ defer cancel()
cfg := testcfg.Build(t)
-
cfg.Ruby.Dir = "/var/empty"
- var repoProto *gitalypb.Repository
- var repoPath string
- if bare {
- repoProto, repoPath = gittest.InitRepo(t, cfg, cfg.Storages[0])
- } else {
- repoProto, repoPath = gittest.CloneRepo(t, cfg, cfg.Storages[0])
- }
-
gitCmdFactory := git.NewExecCommandFactory(cfg)
catfileCache := catfile.NewCache(cfg)
- t.Cleanup(catfileCache.Stop)
-
- return New(gitCmdFactory, catfileCache, repoProto, cfg).Remote(), repoPath
-}
-
-func TestRepo_Remote(t *testing.T) {
- repository := &gitalypb.Repository{StorageName: "stub", RelativePath: "/stub"}
-
- repo := New(nil, nil, repository, config.Cfg{})
- require.Equal(t, Remote{repo: repo}, repo.Remote())
-}
-
-func TestBuildRemoteAddOptsFlags(t *testing.T) {
- for _, tc := range []struct {
- desc string
- opts git.RemoteAddOpts
- exp []git.Option
- }{
- {
- desc: "none",
- exp: nil,
- },
- {
- desc: "all set",
- opts: git.RemoteAddOpts{
- Tags: git.RemoteAddOptsTagsNone,
- Fetch: true,
- RemoteTrackingBranches: []string{"branch-1", "branch-2"},
- DefaultBranch: "develop",
- Mirror: git.RemoteAddOptsMirrorPush,
- },
- exp: []git.Option{
- git.ValueFlag{Name: "-t", Value: "branch-1"},
- git.ValueFlag{Name: "-t", Value: "branch-2"},
- git.ValueFlag{Name: "-m", Value: "develop"},
- git.Flag{Name: "-f"},
- git.Flag{Name: "--no-tags"},
- git.ValueFlag{Name: "--mirror", Value: "push"},
- },
- },
- {
- desc: "with tags",
- opts: git.RemoteAddOpts{Tags: git.RemoteAddOptsTagsAll},
- exp: []git.Option{git.Flag{Name: "--tags"}},
- },
- } {
- t.Run(tc.desc, func(t *testing.T) {
- require.Equal(t, tc.exp, buildRemoteAddOptsFlags(tc.opts))
- })
- }
-}
-
-func TestRemote_Add(t *testing.T) {
- ctx, cancel := testhelper.Context()
- defer cancel()
-
- remote, repoPath := setupRepoRemote(t, false)
-
- gittest.Exec(t, remote.repo.cfg, "-C", repoPath, "remote", "remove", "origin")
-
- _, remoteRepoPath := gittest.CloneRepo(t, remote.repo.cfg, remote.repo.cfg.Storages[0])
-
- t.Run("invalid argument", func(t *testing.T) {
- for _, tc := range []struct {
- desc string
- name, url string
- errMsg string
- }{
- {
- desc: "name",
- name: " ",
- url: "http://some.com.git",
- errMsg: `"name" is blank or empty`,
- },
- {
- desc: "url",
- name: "name",
- url: "",
- errMsg: `"url" is blank or empty`,
- },
- } {
- t.Run(tc.desc, func(t *testing.T) {
- err := remote.Add(ctx, tc.name, tc.url, git.RemoteAddOpts{})
- require.Error(t, err)
- assert.True(t, errors.Is(err, git.ErrInvalidArg))
- assert.Contains(t, err.Error(), tc.errMsg)
- })
- }
- })
-
- t.Run("fetch", func(t *testing.T) {
- require.NoError(t, remote.Add(ctx, "first", remoteRepoPath, git.RemoteAddOpts{Fetch: true}))
-
- remotes := text.ChompBytes(gittest.Exec(t, remote.repo.cfg, "-C", repoPath, "remote", "--verbose"))
- require.Equal(t,
- "first "+remoteRepoPath+" (fetch)\n"+
- "first "+remoteRepoPath+" (push)",
- remotes,
- )
- latestSHA := text.ChompBytes(gittest.Exec(t, remote.repo.cfg, "-C", repoPath, "rev-parse", "refs/remotes/first/master"))
- require.Equal(t, "1e292f8fedd741b75372e19097c76d327140c312", latestSHA)
- })
-
- t.Run("default branch", func(t *testing.T) {
- require.NoError(t, remote.Add(ctx, "second", "http://some.com.git", git.RemoteAddOpts{DefaultBranch: "wip"}))
-
- defaultRemote := text.ChompBytes(gittest.Exec(t, remote.repo.cfg, "-C", repoPath, "symbolic-ref", "refs/remotes/second/HEAD"))
- require.Equal(t, "refs/remotes/second/wip", defaultRemote)
- })
-
- t.Run("remote tracking branches", func(t *testing.T) {
- require.NoError(t, remote.Add(ctx, "third", "http://some.com.git", git.RemoteAddOpts{RemoteTrackingBranches: []string{"a", "b"}}))
-
- defaultRemote := text.ChompBytes(gittest.Exec(t, remote.repo.cfg, "-C", repoPath, "config", "--get-all", "remote.third.fetch"))
- require.Equal(t, "+refs/heads/a:refs/remotes/third/a\n+refs/heads/b:refs/remotes/third/b", defaultRemote)
- })
-
- t.Run("already exists", func(t *testing.T) {
- require.NoError(t, remote.Add(ctx, "fourth", "http://some.com.git", git.RemoteAddOpts{}))
-
- err := remote.Add(ctx, "fourth", "http://some.com.git", git.RemoteAddOpts{})
- require.Equal(t, git.ErrAlreadyExists, err)
- })
-}
-
-func TestRemote_Remove(t *testing.T) {
- ctx, cancel := testhelper.Context()
- defer cancel()
-
- remote, repoPath := setupRepoRemote(t, true)
-
- t.Run("ok", func(t *testing.T) {
- gittest.Exec(t, remote.repo.cfg, "-C", repoPath, "remote", "add", "first", "http://some.com.git")
-
- require.NoError(t, remote.Remove(ctx, "first"))
-
- remotes := text.ChompBytes(gittest.Exec(t, remote.repo.cfg, "-C", repoPath, "remote", "--verbose"))
- require.Empty(t, remotes)
- })
-
- t.Run("not found", func(t *testing.T) {
- err := remote.Remove(ctx, "second")
- require.Equal(t, git.ErrNotFound, err)
- })
-
- t.Run("invalid argument: name", func(t *testing.T) {
- err := remote.Remove(ctx, " ")
- require.Error(t, err)
- assert.True(t, errors.Is(err, git.ErrInvalidArg))
- assert.Contains(t, err.Error(), `"name" is blank or empty`)
- })
-
- t.Run("don't remove local branches", func(t *testing.T) {
- remote, repoPath := setupRepoRemote(t, false)
-
- // configure remote as fetch mirror
- gittest.Exec(t, remote.repo.cfg, "-C", repoPath, "config", "remote.origin.fetch", "+refs/*:refs/*")
- gittest.Exec(t, remote.repo.cfg, "-C", repoPath, "fetch")
-
- masterBeforeRemove := gittest.Exec(t, remote.repo.cfg, "-C", repoPath, "show-ref", "refs/heads/master")
-
- require.NoError(t, remote.Remove(ctx, "origin"))
-
- out := gittest.Exec(t, remote.repo.cfg, "-C", repoPath, "remote")
- require.Len(t, out, 0)
-
- out = gittest.Exec(t, remote.repo.cfg, "-C", repoPath, "show-ref", "refs/heads/master")
- require.Equal(t, masterBeforeRemove, out)
- })
-}
-
-func TestRemote_Exists(t *testing.T) {
- ctx, cancel := testhelper.Context()
- defer cancel()
-
- remote, _ := setupRepoRemote(t, false)
-
- found, err := remote.Exists(ctx, "origin")
- require.NoError(t, err)
- require.True(t, found)
-
- found, err = remote.Exists(ctx, "can-not-be-found")
- require.NoError(t, err)
- require.False(t, found)
-}
-
-func TestBuildSetURLOptsFlags(t *testing.T) {
- for _, tc := range []struct {
- desc string
- opts git.SetURLOpts
- exp []git.Option
- }{
- {
- desc: "none",
- exp: nil,
- },
- {
- desc: "all set",
- opts: git.SetURLOpts{Push: true},
- exp: []git.Option{git.Flag{Name: "--push"}},
- },
- } {
- t.Run(tc.desc, func(t *testing.T) {
- require.Equal(t, tc.exp, buildSetURLOptsFlags(tc.opts))
- })
- }
-}
-
-func TestRemote_SetURL(t *testing.T) {
- ctx, cancel := testhelper.Context()
- defer cancel()
-
- remote, repoPath := setupRepoRemote(t, true)
-
- t.Run("invalid argument", func(t *testing.T) {
- for _, tc := range []struct {
- desc string
- name, url string
- errMsg string
- }{
- {
- desc: "name",
- name: " ",
- url: "http://some.com.git",
- errMsg: `"name" is blank or empty`,
- },
- {
- desc: "url",
- name: "name",
- url: "",
- errMsg: `"url" is blank or empty`,
- },
- } {
- t.Run(tc.desc, func(t *testing.T) {
- err := remote.SetURL(ctx, tc.name, tc.url, git.SetURLOpts{})
- require.Error(t, err)
- assert.True(t, errors.Is(err, git.ErrInvalidArg))
- assert.Contains(t, err.Error(), tc.errMsg)
- })
- }
- })
-
- t.Run("ok", func(t *testing.T) {
- gittest.Exec(t, remote.repo.cfg, "-C", repoPath, "remote", "add", "first", "file:/"+repoPath)
-
- require.NoError(t, remote.SetURL(ctx, "first", "http://some.com.git", git.SetURLOpts{Push: true}))
-
- remotes := text.ChompBytes(gittest.Exec(t, remote.repo.cfg, "-C", repoPath, "remote", "--verbose"))
- require.Equal(t,
- "first file:/"+repoPath+" (fetch)\n"+
- "first http://some.com.git (push)",
- remotes,
- )
- })
-
- t.Run("doesnt exist", func(t *testing.T) {
- err := remote.SetURL(ctx, "second", "http://some.com.git", git.SetURLOpts{})
- require.True(t, errors.Is(err, git.ErrNotFound), err)
- })
-}
-
-func TestRepo_FetchRemote(t *testing.T) {
- ctx, cancel := testhelper.Context()
- defer cancel()
-
- remoteCmd, remoteRepoPath := setupRepoRemote(t, false)
- cfg := remoteCmd.repo.cfg
+ defer catfileCache.Stop()
initBareWithRemote := func(t *testing.T, remote string) (*Repo, string) {
t.Helper()
- testRepo, testRepoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
+ _, remoteRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+
+ clientRepo, clientRepoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
- cmd := exec.Command(cfg.Git.BinPath, "-C", testRepoPath, "remote", "add", remote, remoteRepoPath)
+ cmd := exec.Command(cfg.Git.BinPath, "-C", clientRepoPath, "remote", "add", remote, remoteRepoPath)
err := cmd.Run()
if err != nil {
require.NoError(t, err)
}
- return New(remoteCmd.repo.gitCmdFactory, remoteCmd.repo.catfileCache, testRepo, cfg), testRepoPath
+ return New(gitCmdFactory, catfileCache, clientRepo, cfg), clientRepoPath
}
t.Run("invalid name", func(t *testing.T) {
- repo := New(remoteCmd.repo.gitCmdFactory, remoteCmd.repo.catfileCache, nil, cfg)
+ repo := New(gitCmdFactory, catfileCache, nil, cfg)
err := repo.FetchRemote(ctx, " ", FetchOpts{})
require.True(t, errors.Is(err, git.ErrInvalidArg))
@@ -329,7 +53,9 @@ func TestRepo_FetchRemote(t *testing.T) {
})
t.Run("unknown remote", func(t *testing.T) {
- repo := New(remoteCmd.repo.gitCmdFactory, remoteCmd.repo.catfileCache, remoteCmd.repo, cfg)
+ repoProto, _ := gittest.InitRepo(t, cfg, cfg.Storages[0])
+
+ repo := New(gitCmdFactory, catfileCache, repoProto, cfg)
var stderr bytes.Buffer
err := repo.FetchRemote(ctx, "stub", FetchOpts{Stderr: &stderr})
require.Error(t, err)
@@ -359,7 +85,7 @@ func TestRepo_FetchRemote(t *testing.T) {
_, sourceRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
testRepo, testRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
- repo := New(remoteCmd.repo.gitCmdFactory, remoteCmd.repo.catfileCache, testRepo, cfg)
+ repo := New(gitCmdFactory, catfileCache, testRepo, cfg)
gittest.Exec(t, cfg, "-C", testRepoPath, "remote", "add", "source", sourceRepoPath)
var stderr bytes.Buffer
@@ -371,7 +97,7 @@ func TestRepo_FetchRemote(t *testing.T) {
_, sourceRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
testRepo, testRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
- repo := New(remoteCmd.repo.gitCmdFactory, remoteCmd.repo.catfileCache, testRepo, cfg)
+ repo := New(gitCmdFactory, catfileCache, testRepo, cfg)
gittest.Exec(t, cfg, "-C", testRepoPath, "remote", "add", "source", sourceRepoPath)
var stderr bytes.Buffer
@@ -387,7 +113,7 @@ func TestRepo_FetchRemote(t *testing.T) {
_, sourceRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
testRepo, testRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
- repo := New(remoteCmd.repo.gitCmdFactory, remoteCmd.repo.catfileCache, testRepo, cfg)
+ repo := New(gitCmdFactory, catfileCache, testRepo, cfg)
gittest.Exec(t, cfg, "-C", testRepoPath, "remote", "add", "source", sourceRepoPath)
require.NoError(t, repo.FetchRemote(ctx, "source", FetchOpts{}))
@@ -414,7 +140,7 @@ func TestRepo_FetchRemote(t *testing.T) {
_, sourceRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
testRepo, testRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
- repo := New(remoteCmd.repo.gitCmdFactory, remoteCmd.repo.catfileCache, testRepo, cfg)
+ repo := New(gitCmdFactory, catfileCache, testRepo, cfg)
gittest.Exec(t, cfg, "-C", testRepoPath, "remote", "add", "source", sourceRepoPath)
require.NoError(t, repo.FetchRemote(ctx, "source", FetchOpts{}))
diff --git a/internal/git/localrepo/repo.go b/internal/git/localrepo/repo.go
index 0fc34f071..3d51f11df 100644
--- a/internal/git/localrepo/repo.go
+++ b/internal/git/localrepo/repo.go
@@ -64,11 +64,6 @@ func (repo *Repo) ExecAndWait(ctx context.Context, cmd git.Cmd, opts ...git.CmdO
return command.Wait()
}
-// Remote returns executor of the 'remote' sub-command.
-func (repo *Repo) Remote() Remote {
- return Remote{repo: repo}
-}
-
func errorWithStderr(err error, stderr []byte) error {
if len(stderr) == 0 {
return err
diff --git a/internal/git/remote.go b/internal/git/remote.go
deleted file mode 100644
index 9eafb3994..000000000
--- a/internal/git/remote.go
+++ /dev/null
@@ -1,79 +0,0 @@
-package git
-
-import (
- "context"
-)
-
-// Remote represents 'remote' sub-command.
-// https://git-scm.com/docs/git-remote
-type Remote interface {
- // Add creates a new remote repository if it doesn't exist.
- // If such a remote already exists it returns an ErrAlreadyExists error.
- // https://git-scm.com/docs/git-remote#Documentation/git-remote.txt-emaddem
- Add(ctx context.Context, name, url string, opts RemoteAddOpts) error
- // Remove removes the remote configured for the local repository and all configurations associated with it.
- // https://git-scm.com/docs/git-remote#Documentation/git-remote.txt-emremoveem
- Remove(ctx context.Context, name string) error
- // SetURL sets a new url value for an existing remote.
- // If remote doesn't exist it returns an ErrNotFound error.
- // https://git-scm.com/docs/git-remote#Documentation/git-remote.txt-emset-urlem
- SetURL(ctx context.Context, name, url string, opts SetURLOpts) error
-}
-
-// RemoteAddOptsMirror represents possible values for the '--mirror' flag value
-type RemoteAddOptsMirror string
-
-func (m RemoteAddOptsMirror) String() string {
- return string(m)
-}
-
-var (
- // RemoteAddOptsMirrorDefault allows to use a default behaviour.
- RemoteAddOptsMirrorDefault = RemoteAddOptsMirror("")
- // RemoteAddOptsMirrorFetch configures everything in refs/ on the remote to be
- // directly mirrored into refs/ in the local repository.
- RemoteAddOptsMirrorFetch = RemoteAddOptsMirror("fetch")
- // RemoteAddOptsMirrorPush configures 'git push' to always behave as if --mirror was passed.
- RemoteAddOptsMirrorPush = RemoteAddOptsMirror("push")
-)
-
-// RemoteAddOptsTags controls whether tags will be fetched.
-type RemoteAddOptsTags string
-
-func (t RemoteAddOptsTags) String() string {
- return string(t)
-}
-
-var (
- // RemoteAddOptsTagsDefault enables importing of tags only on fetched branches.
- RemoteAddOptsTagsDefault = RemoteAddOptsTags("")
- // RemoteAddOptsTagsAll enables importing of every tag from the remote repository.
- RemoteAddOptsTagsAll = RemoteAddOptsTags("--tags")
- // RemoteAddOptsTagsNone disables importing of tags from the remote repository.
- RemoteAddOptsTagsNone = RemoteAddOptsTags("--no-tags")
-)
-
-// RemoteAddOpts is used to configure invocation of the 'git remote add' command.
-// https://git-scm.com/docs/git-remote#Documentation/git-remote.txt-emaddem
-type RemoteAddOpts struct {
- // RemoteTrackingBranches controls what branches should be tracked instead of
- // all branches which is a default refs/remotes/<name>.
- // For each entry the refspec '+refs/heads/<branch>:refs/remotes/<remote>/<branch>' would be created and added to the configuration.
- RemoteTrackingBranches []string
- // DefaultBranch sets the default branch (i.e. the target of the symbolic-ref refs/remotes/<name>/HEAD)
- // for the named remote.
- // If set to 'develop' then: 'git symbolic-ref refs/remotes/<remote>/HEAD' call will result to 'refs/remotes/<remote>/develop'.
- DefaultBranch string
- // Fetch controls if 'git fetch <name>' is run immediately after the remote information is set up.
- Fetch bool
- // Tags controls whether tags will be fetched as part of the remote or not.
- Tags RemoteAddOptsTags
- // Mirror controls value used for '--mirror' flag.
- Mirror RemoteAddOptsMirror
-}
-
-// SetURLOpts are the options for SetURL.
-type SetURLOpts struct {
- // Push URLs are manipulated instead of fetch URLs.
- Push bool
-}