Skip to content
.gitconfig syntax parser
Branch: master
Clone or download
Pull request Compare This branch is 21 commits ahead of muja:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
cmd/goconfig
configs
.gitignore
.travis.yml
LICENSE
Makefile
README.md
cache.go
errors.go
git-config.go
git-config_test.go
go.mod
go.sum
goconfig.go
goconfig_test.go
load.go
load_test.go
path.go
path_test.go

README.md

goconfig

Travis Build Status

Table of contents

  1. Introduction
  2. Usage
  3. Contributing
  4. Reporting bugs

1. Introduction

This project parses config files that have the same syntax as gitconfig files. It understands multiple values configuration, and can parse included configs by include.path directions (includeIf.*.path configuration is not supported yet).

It has no knowledge of git-specific keys and as such, does not provide any convenience methods like config.GetUserName(). For these, look into go-gitconfig

Most of the code was copied and translated to Go from git/config.c

2. Usage

To load specific git config file and inherit global and system git config, using:

package main

import (
	"fmt"
	"log"

	"github.com/jiangxin/goconfig"
)

func main() {
	cfg, err := goconfig.LoadAll("")
	if err != nil {
		log.Fatal(err)
	}
	if cfg == nil {
		log.Fatal("cfg is nil")
	}

	fmt.Printf(cfg.Get("user.name"))
}

As an example, there is a full functional git config to read/write git config file implemented by goconfig, see:

cmd/goconfig/main.go

3. Contributing

Contributions are welcome! Fork -> Push -> Pull request.

4. Bug report / suggestions

Just create an issue! I will try to reply as soon as possible.

You can’t perform that action at this time.