diff options
author | Amine Hilaly <hilalyamine@gmail.com> | 2019-07-07 13:44:10 +0200 |
---|---|---|
committer | Amine Hilaly <hilalyamine@gmail.com> | 2019-07-07 13:57:15 +0200 |
commit | bb68b391a0fe5ff868b76725142cd351bee41b1c (patch) | |
tree | 8c9ecc4efc328a200c7511b1bc1c6d4918fdedbd /repository | |
parent | 08f9bafd09c8452a60ee603a744188c1a823cb3c (diff) | |
download | git-bug-bb68b391a0fe5ff868b76725142cd351bee41b1c.tar.gz |
Check git version before removing config section
update git config tests
Diffstat (limited to 'repository')
-rw-r--r-- | repository/git.go | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/repository/git.go b/repository/git.go index c8c45d6a..c115cb0b 100644 --- a/repository/git.go +++ b/repository/git.go @@ -13,6 +13,7 @@ import ( "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" @@ -264,13 +265,46 @@ func (repo *GitRepo) RmConfigs(keyPrefix string) error { // try to remove key/value pair by key _, err := repo.runGitCommand("config", "--unset-all", keyPrefix) if err != nil { - // try to remove section - _, err = repo.runGitCommand("config", "--remove-section", 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 + + var ok bool + ok, err = repo.gitVersionLT218() + 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 } +func (repo *GitRepo) gitVersionLT218() (bool, error) { + versionOut, err := repo.runGitCommand("version") + if err != nil { + return false, err + } + + versionString := strings.Fields(versionOut)[2] + version, err := semver.Make(versionString) + if err != nil { + return false, err + } + + version218string := "2.18.0" + gitVersion218, err := semver.Make(version218string) + if err != nil { + return false, err + } + + return version.LT(gitVersion218), nil +} + // FetchRefs fetch git refs from a remote func (repo *GitRepo) FetchRefs(remote, refSpec string) (string, error) { stdout, err := repo.runGitCommand("fetch", remote, refSpec) |