aboutsummaryrefslogtreecommitdiffstats
path: root/repository
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-07-08 12:14:41 +0200
committerMichael Muré <batolettre@gmail.com>2019-07-08 12:14:41 +0200
commit76db2f42ebc356a0c347558133dc67ff6cb0d72d (patch)
treea5a9bad26e42a807869d24b4488a90c6e7104d9e /repository
parentbb68b391a0fe5ff868b76725142cd351bee41b1c (diff)
downloadgit-bug-76db2f42ebc356a0c347558133dc67ff6cb0d72d.tar.gz
repository: rework how RmConfigs works with git
Diffstat (limited to 'repository')
-rw-r--r--repository/git.go33
-rw-r--r--repository/git_test.go2
2 files changed, 19 insertions, 16 deletions
diff --git a/repository/git.go b/repository/git.go
index c115cb0b..fcf5e70c 100644
--- a/repository/git.go
+++ b/repository/git.go
@@ -3,7 +3,6 @@ package repository
import (
"bytes"
- "errors"
"fmt"
"io"
"os/exec"
@@ -11,9 +10,11 @@ import (
"strconv"
"strings"
+ "github.com/blang/semver"
+ "github.com/pkg/errors"
+
"github.com/MichaelMure/git-bug/util/git"
"github.com/MichaelMure/git-bug/util/lamport"
- "github.com/blang/semver"
)
const createClockFile = "/.git/git-bug/create-clock"
@@ -262,25 +263,27 @@ func (repo *GitRepo) ReadConfigString(key string) (string, error) {
// RmConfigs remove all key/value pair matching the key prefix
func (repo *GitRepo) RmConfigs(keyPrefix string) error {
- // try to remove key/value pair by key
- _, err := repo.runGitCommand("config", "--unset-all", keyPrefix)
+ // starting from git 2.18.0 sections are automatically deleted when the last existing
+ // key/value is removed. Before 2.18.0 we should remove the section
+ // see https://github.com/git/git/blob/master/Documentation/RelNotes/2.18.0.txt#L379
+ lt218, err := repo.gitVersionLT218()
if err != nil {
- // starting from git 2.18.0 sections are automatically deleted when the last existing
- // key/value is removed. Before 2.18.0 we should remove the section
- // see https://github.com/git/git/blob/master/Documentation/RelNotes/2.18.0.txt#L379
+ return errors.Wrap(err, "getting git version")
+ }
- var ok bool
- ok, err = repo.gitVersionLT218()
+ if lt218 {
+ // try to remove key/value pair by key
+ _, err := repo.runGitCommand("config", "--unset-all", keyPrefix)
if err != nil {
- return fmt.Errorf("getting git version: %v", err)
- }
-
- if ok {
// try to remove section
_, err = repo.runGitCommand("config", "--remove-section", keyPrefix)
}
+
+ return err
}
+ // try to remove key/value pair by key
+ _, err = repo.runGitCommand("config", "--unset-all", keyPrefix)
return err
}
@@ -462,7 +465,7 @@ func (repo *GitRepo) FindCommonAncestor(hash1 git.Hash, hash2 git.Hash) (git.Has
stdout, err := repo.runGitCommand("merge-base", string(hash1), string(hash2))
if err != nil {
- return "", nil
+ return "", err
}
return git.Hash(stdout), nil
@@ -473,7 +476,7 @@ func (repo *GitRepo) GetTreeHash(commit git.Hash) (git.Hash, error) {
stdout, err := repo.runGitCommand("rev-parse", string(commit)+"^{tree}")
if err != nil {
- return "", nil
+ return "", err
}
return git.Hash(stdout), nil
diff --git a/repository/git_test.go b/repository/git_test.go
index 8bd3aa8e..20bf6ec3 100644
--- a/repository/git_test.go
+++ b/repository/git_test.go
@@ -55,7 +55,7 @@ func TestConfig(t *testing.T) {
assert.Error(t, err)
err = repo.RmConfigs("section")
- assert.NoError(t, err)
+ assert.Error(t, err)
_, err = repo.ReadConfigString("section.key")
assert.Error(t, err)