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-07-28 13:10:27 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2021-07-28 13:10:27 +0300
commit96ff28e18c2b93c77e5f49f87b72887095ad5476 (patch)
treeb9c9837abc0d0e5af9d4c4d6807f910cdd225859
parent0622b256ea3bdef6a0a52cf66ce9d3ecca08b338 (diff)
git: Remove unused `config.Add()` function
The `config.Add()` function is not used anywhere in our codebase, and most callers would actually want to use `config.Set()` because the former one will add multi-value config entries. Remove `config.Add()` and its localrepo implementation.
-rw-r--r--internal/git/config.go11
-rw-r--r--internal/git/housekeeping/housekeeping_test.go2
-rw-r--r--internal/git/localrepo/config.go37
-rw-r--r--internal/git/localrepo/config_test.go90
4 files changed, 1 insertions, 139 deletions
diff --git a/internal/git/config.go b/internal/git/config.go
index 899da1d0a..7e0226966 100644
--- a/internal/git/config.go
+++ b/internal/git/config.go
@@ -11,11 +11,6 @@ type Config interface {
// new value.
Set(ctx context.Context, name, value string) error
- // Add adds a new configuration value.
- // WARNING: you can't ever use it for anything that contains secrets.
- // https://git-scm.com/docs/git-config#Documentation/git-config.txt---add
- Add(ctx context.Context, name, value string, opts ConfigAddOpts) error
-
// GetRegexp returns configurations matched to nameRegexp regular expression.
// https://git-scm.com/docs/git-config#Documentation/git-config.txt---get-regexp
GetRegexp(ctx context.Context, nameRegexp string, opts ConfigGetRegexpOpts) ([]ConfigPair, error)
@@ -51,12 +46,6 @@ var (
ConfigTypePath = ConfigType("--path")
)
-// ConfigAddOpts is used to configure invocation of the 'git config --add' command.
-type ConfigAddOpts struct {
- // Type controls rules used to check the value.
- Type ConfigType
-}
-
// ConfigGetRegexpOpts is used to configure invocation of the 'git config --get-regexp' command.
type ConfigGetRegexpOpts struct {
// Type allows to specify an expected type for the configuration.
diff --git a/internal/git/housekeeping/housekeeping_test.go b/internal/git/housekeeping/housekeeping_test.go
index 5cb10d7b9..4f85aee6b 100644
--- a/internal/git/housekeeping/housekeeping_test.go
+++ b/internal/git/housekeeping/housekeeping_test.go
@@ -672,7 +672,7 @@ func TestPerform_UnsetConfiguration(t *testing.T) {
"http.something.else": "untouched",
"totally.unrelated": "untouched",
} {
- require.NoError(t, repo.Config().Add(ctx, key, value, git.ConfigAddOpts{}))
+ require.NoError(t, repo.Config().Set(ctx, key, value))
}
opts, err := repo.Config().GetRegexp(ctx, ".*", git.ConfigGetRegexpOpts{})
diff --git a/internal/git/localrepo/config.go b/internal/git/localrepo/config.go
index d9c7c40a4..607f7dbdd 100644
--- a/internal/git/localrepo/config.go
+++ b/internal/git/localrepo/config.go
@@ -48,43 +48,6 @@ func (cfg Config) Set(ctx context.Context, name, value string) error {
return nil
}
-// Add adds a new entry to the repository's configuration.
-func (cfg Config) Add(ctx context.Context, name, value string, opts git.ConfigAddOpts) error {
- if err := validateNotBlank(name, "name"); err != nil {
- return err
- }
-
- if err := cfg.repo.ExecAndWait(ctx, git.SubCmd{
- Name: "config",
- Flags: append(buildConfigAddOptsFlags(opts), git.Flag{Name: "--add"}),
- Args: []string{name, value},
- }); err != nil {
- // Please refer to https://git-scm.com/docs/git-config#_description
- // on return codes.
- switch {
- case isExitWithCode(err, 1):
- // section or key is invalid
- return fmt.Errorf("%w: bad section or name", git.ErrInvalidArg)
- case isExitWithCode(err, 2):
- // no section or name was provided
- return fmt.Errorf("%w: missing section or name", git.ErrInvalidArg)
- }
-
- return err
- }
-
- return nil
-}
-
-func buildConfigAddOptsFlags(opts git.ConfigAddOpts) []git.Option {
- var flags []git.Option
- if opts.Type != git.ConfigTypeDefault {
- flags = append(flags, git.Flag{Name: opts.Type.String()})
- }
-
- return flags
-}
-
// GetRegexp gets all config entries which whose keys match the given regexp.
func (cfg Config) GetRegexp(ctx context.Context, nameRegexp string, opts git.ConfigGetRegexpOpts) ([]git.ConfigPair, error) {
if err := validateNotBlank(nameRegexp, "nameRegexp"); err != nil {
diff --git a/internal/git/localrepo/config_test.go b/internal/git/localrepo/config_test.go
index f0a5c371d..2ef7caac9 100644
--- a/internal/git/localrepo/config_test.go
+++ b/internal/git/localrepo/config_test.go
@@ -89,96 +89,6 @@ func TestConfig_Set(t *testing.T) {
})
}
-func TestBuildConfigAddOptsFlags(t *testing.T) {
- for _, tc := range []struct {
- desc string
- opts git.ConfigAddOpts
- exp []git.Option
- }{
- {
- desc: "none",
- opts: git.ConfigAddOpts{},
- exp: nil,
- },
- {
- desc: "all set",
- opts: git.ConfigAddOpts{Type: git.ConfigTypeBoolOrInt},
- exp: []git.Option{git.Flag{Name: "--bool-or-int"}},
- },
- } {
- t.Run(tc.desc, func(t *testing.T) {
- require.Equal(t, tc.exp, buildConfigAddOptsFlags(tc.opts))
- })
- }
-}
-
-func TestConfig_Add(t *testing.T) {
- ctx, cancel := testhelper.Context()
- defer cancel()
-
- repoConfig, repoPath := setupRepoConfig(t)
-
- t.Run("ok", func(t *testing.T) {
- require.NoError(t, repoConfig.Add(ctx, "key.one", "1", git.ConfigAddOpts{}))
-
- actual := text.ChompBytes(gittest.Exec(t, repoConfig.repo.cfg, "-C", repoPath, "config", "key.one"))
- require.Equal(t, "1", actual)
- })
-
- t.Run("appends to an old value", func(t *testing.T) {
- require.NoError(t, repoConfig.Add(ctx, "key.two", "2", git.ConfigAddOpts{}))
- require.NoError(t, repoConfig.Add(ctx, "key.two", "3", git.ConfigAddOpts{}))
-
- actual := text.ChompBytes(gittest.Exec(t, repoConfig.repo.cfg, "-C", repoPath, "config", "--get-all", "key.two"))
- require.Equal(t, "2\n3", actual)
- })
-
- t.Run("options are passed", func(t *testing.T) {
- require.NoError(t, repoConfig.Add(ctx, "key.three", "3", git.ConfigAddOpts{Type: git.ConfigTypeInt}))
-
- actual := text.ChompBytes(gittest.Exec(t, repoConfig.repo.cfg, "-C", repoPath, "config", "--int", "key.three"))
- require.Equal(t, "3", actual)
- })
-
- t.Run("invalid argument", func(t *testing.T) {
- for _, tc := range []struct {
- desc string
- name string
- expErr error
- expMsg string
- }{
- {
- desc: "empty name",
- name: "",
- expErr: git.ErrInvalidArg,
- expMsg: `"name" is blank or empty`,
- },
- {
- desc: "invalid name",
- name: "`.\n",
- expErr: git.ErrInvalidArg,
- expMsg: "bad section or name",
- },
- {
- desc: "no section or name",
- name: "missing",
- expErr: git.ErrInvalidArg,
- expMsg: "missing section or name",
- },
- } {
- t.Run(tc.desc, func(t *testing.T) {
- ctx, cancel := testhelper.Context()
- defer cancel()
-
- err := repoConfig.Add(ctx, tc.name, "some", git.ConfigAddOpts{})
- require.Error(t, err)
- require.True(t, errors.Is(err, tc.expErr), err.Error())
- require.Contains(t, err.Error(), tc.expMsg)
- })
- }
- })
-}
-
func TestBuildConfigGetRegexpOptsFlags(t *testing.T) {
for _, tc := range []struct {
desc string