Skip to content

fix(cli): ignore missing sections when removing configuration #1455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ getting started as a contributor to this project.
- [4.2 | Test the development shell](#42--test-the-development-shell)
- [Useful development commands](#useful-development-commands)
- [Submitting changes](#submitting-changes)
- [Commit messages are the source of truth](#commit-messages-are-the-source-of-truth)
- [Push early, push often](#push-early-push-often)
- [Pull requests are squashed](#pull-requests-are-squashed)
- [Draft vs Ready](#draft-vs-ready)
Expand Down Expand Up @@ -265,6 +266,15 @@ repository, and create a pull request.
If you are in the development shell, you have the `gh` command line tool
available for use with github.

### Commit messages are the source of truth<a name="commit-messages-are-the-source-of-truth"></a>

Commit subjects and messages are the source of truth for a variety of things,
including the public-facing changelog (\[`//:CHANGELOG.md`\]\[changelog\]) and
release descriptions. Writing thorough commit messages is beneficial to anyone
reviewing a commit, including future you!

Please be sure to read the [commit message guidelines][doc/contrib/commit].

### Push early, push often<a name="push-early-push-often"></a>

We encourage pushing small changes. There is no such thing as a contribution
Expand Down
1 change: 1 addition & 0 deletions commands/wipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func runWipe(env *execenv.Env) error {
_ = env.Backend.Close()
return err
}

err = env.Backend.LocalConfig().RemoveAll("git-bug")
if err != nil {
_ = env.Backend.Close()
Expand Down
7 changes: 0 additions & 7 deletions repository/config_mem.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package repository

import (
"fmt"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -82,18 +81,12 @@ func (mc *MemConfig) ReadTimestamp(key string) (time.Time, error) {
// RemoveAll remove all key/value pair matching the key prefix
func (mc *MemConfig) RemoveAll(keyPrefix string) error {
keyPrefix = normalizeKey(keyPrefix)
found := false
for key := range mc.config {
if strings.HasPrefix(key, keyPrefix) {
delete(mc.config, key)
found = true
}
}

if !found {
return fmt.Errorf("section not found")
}

return nil
}

Expand Down
9 changes: 3 additions & 6 deletions repository/config_testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func testConfig(t *testing.T, config Config) {
require.ErrorIs(t, err, ErrNoConfigEntry)

err = config.RemoveAll("section.nonexistingkey")
require.Error(t, err)
require.NoError(t, err)

err = config.RemoveAll("section.key")
require.NoError(t, err)
Expand All @@ -65,20 +65,17 @@ func testConfig(t *testing.T, config Config) {
require.ErrorIs(t, err, ErrNoConfigEntry)

err = config.RemoveAll("nonexistingsection")
require.Error(t, err)
require.NoError(t, err)

err = config.RemoveAll("section.time")
require.NoError(t, err)

err = config.RemoveAll("section")
require.Error(t, err)
require.NoError(t, err)

_, err = config.ReadString("section.key")
require.Error(t, err)

err = config.RemoveAll("section.key")
require.Error(t, err)

// section + subsections
require.NoError(t, config.StoreString("section.opt1", "foo"))
require.NoError(t, config.StoreString("section.opt2", "foo2"))
Expand Down
13 changes: 1 addition & 12 deletions repository/gogit_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,27 +212,16 @@ func (cw *goGitConfigWriter) RemoveAll(keyPrefix string) error {
case len(split) == 1:
if cfg.Raw.HasSection(split[0]) {
cfg.Raw.RemoveSection(split[0])
} else {
return fmt.Errorf("invalid key prefix")
}
default:
if !cfg.Raw.HasSection(split[0]) {
return fmt.Errorf("invalid key prefix")
}
case cfg.Raw.HasSection(split[0]):
section := cfg.Raw.Section(split[0])
rest := strings.Join(split[1:], ".")

ok := false
if section.HasSubsection(rest) {
section.RemoveSubsection(rest)
ok = true
}
if section.HasOption(rest) {
section.RemoveOption(rest)
ok = true
}
if !ok {
return fmt.Errorf("invalid key prefix")
}
}

Expand Down