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-09-21 10:27:31 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2021-09-22 08:58:47 +0300
commit4a0061039867b4e8747828aa27a0ca7f3ed0daa2 (patch)
tree25e1b699233ff37c9f54d5ec4b2840f6bd61ba28 /internal
parent76140fa589028f49501530c97d9b94235723f4c6 (diff)
localrepo: Drop unused `Config.Set()` function
The `Set()` function sets config entries in the gitconfig, but without proper atomic guarantees. Given that it has since been replaced with the `localrepo.SetConfig()` function, which does provide those guarantees, the old function shouldn't be used anymore. Remove it and remaining callers in tests.
Diffstat (limited to 'internal')
-rw-r--r--internal/git/housekeeping/housekeeping_test.go6
-rw-r--r--internal/git/localrepo/config.go31
-rw-r--r--internal/git/localrepo/config_test.go60
-rw-r--r--internal/git/localrepo/remote_extra_test.go2
4 files changed, 4 insertions, 95 deletions
diff --git a/internal/git/housekeeping/housekeeping_test.go b/internal/git/housekeeping/housekeeping_test.go
index 09b46599d..e62c5de6f 100644
--- a/internal/git/housekeeping/housekeeping_test.go
+++ b/internal/git/housekeeping/housekeeping_test.go
@@ -666,7 +666,7 @@ func TestPerformRepoDoesNotExist(t *testing.T) {
}
func TestPerform_UnsetConfiguration(t *testing.T) {
- cfg, repoProto, _ := testcfg.BuildWithRepo(t)
+ cfg, repoProto, repoPath := testcfg.BuildWithRepo(t)
repo := localrepo.NewTestRepo(t, cfg, repoProto)
ctx, cancel := testhelper.Context()
@@ -679,7 +679,7 @@ func TestPerform_UnsetConfiguration(t *testing.T) {
"http.something.else": "untouched",
"totally.unrelated": "untouched",
} {
- require.NoError(t, repo.Config().Set(ctx, key, value))
+ gittest.Exec(t, cfg, "-C", repoPath, "config", key, value)
}
opts, err := repo.Config().GetRegexp(ctx, ".*", git.ConfigGetRegexpOpts{})
@@ -711,7 +711,7 @@ func testPerformUnsetConfigurationTransactional(t *testing.T, ctx context.Contex
repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
repo := localrepo.NewTestRepo(t, cfg, repoProto)
- require.NoError(t, repo.Config().Set(ctx, "http.some.extraHeader", "value"))
+ gittest.Exec(t, cfg, "-C", repoPath, "config", "http.some.extraHeader", "value")
votes := 0
txManager := &transaction.MockManager{
diff --git a/internal/git/localrepo/config.go b/internal/git/localrepo/config.go
index 97f4de2e4..49faa6cda 100644
--- a/internal/git/localrepo/config.go
+++ b/internal/git/localrepo/config.go
@@ -21,37 +21,6 @@ type Config struct {
repo *Repo
}
-// Set will set a configuration value. Any preexisting values will be overwritten with the new
-// value.
-func (cfg Config) Set(ctx context.Context, name, value string) error {
- if err := validateNotBlank(name, "name"); err != nil {
- return err
- }
-
- if err := cfg.repo.ExecAndWait(ctx, git.SubCmd{
- Name: "config",
- Flags: []git.Option{
- git.Flag{Name: "--replace-all"},
- },
- 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
-}
-
// 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 f09e525a5..15c440524 100644
--- a/internal/git/localrepo/config_test.go
+++ b/internal/git/localrepo/config_test.go
@@ -36,66 +36,6 @@ func setupRepoConfig(t *testing.T) (Config, string) {
return repo.Config(), repoPath
}
-func TestConfig_Set(t *testing.T) {
- ctx, cancel := testhelper.Context()
- defer cancel()
-
- repoConfig, repoPath := setupRepoConfig(t)
-
- t.Run("setting a new value", func(t *testing.T) {
- require.NoError(t, repoConfig.Set(ctx, "key.one", "1"))
-
- actual := text.ChompBytes(gittest.Exec(t, repoConfig.repo.cfg, "-C", repoPath, "config", "key.one"))
- require.Equal(t, "1", actual)
- })
-
- t.Run("overwriting an old value", func(t *testing.T) {
- require.NoError(t, repoConfig.Set(ctx, "key.two", "2"))
- require.NoError(t, repoConfig.Set(ctx, "key.two", "3"))
-
- actual := text.ChompBytes(gittest.Exec(t, repoConfig.repo.cfg, "-C", repoPath, "config", "--get-all", "key.two"))
- 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.Set(ctx, tc.name, "some")
- 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
diff --git a/internal/git/localrepo/remote_extra_test.go b/internal/git/localrepo/remote_extra_test.go
index f80be863b..8dc1a3cc5 100644
--- a/internal/git/localrepo/remote_extra_test.go
+++ b/internal/git/localrepo/remote_extra_test.go
@@ -60,7 +60,7 @@ func TestRepo_FetchInternal(t *testing.T) {
repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
repo := localrepo.NewTestRepo(t, cfg, repoProto)
- require.NoError(t, repo.Config().Set(ctx, "fetch.writeCommitGraph", "true"))
+ gittest.Exec(t, cfg, "-C", repoPath, "config", "fetch.writeCommitGraph", "true")
require.NoError(t, repo.FetchInternal(
ctx, remoteRepoProto, []string{"refs/heads/master:refs/heads/master"},