GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - git-bug/gitconfig: Read and edit any git config, correctly.

BranchesTags
Open more actions menu

Latest commit

 

History

35 Commits
35 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
docs
docs
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
config.go
config.go
 
 
config_test.go
config_test.go
 
 
discover.go
discover.go
 
 
doc.go
doc.go
 
 
edit.go
edit.go
 
 
env.go
env.go
 
 
env_test.go
env_test.go
 
 
errors.go
errors.go
 
 
errors_test.go
errors_test.go
 
 
example_test.go
example_test.go
 
 
file.go
file.go
 
 
file_test.go
file_test.go
 
 
glob.go
glob.go
 
 
go.mod
go.mod
 
 
go.sum
go.sum
 
 
interop_test.go
interop_test.go
 
 
key.go
key.go
 
 
load.go
load.go
 
 
parse.go
parse.go
 
 
platform.go
platform.go
 
 
platform_windows.go
platform_windows.go
 
 
safedir_test.go
safedir_test.go
 
 
update.go
update.go
 
 
value.go
value.go
 
 

Repository files navigation

gitconfig

Build Status Go Reference MIT License

Documentation - Issues - Compatibility

gitconfig is a Go library to read and edit git configuration the way git does.

  • same result as git: same parsing, same value types (bool, int, path), tested against the git binary.
  • every source: system, global, local and worktree files, GIT_CONFIG_* variables, include and includeIf. Each value says which file and line it came from.
  • lossless edits: an edit changes only the lines it touches; comments and layout are kept.
  • safe alongside git: writes take git's lock, so a concurrent git config and this library never overwrite each other.
  • safe on hostile repositories: untrusted repositories are refused, as git refuses them (safe.directory).

Where this library deliberately differs from git, and why, is listed in COMPATIBILITY.md.

Installation

go get github.com/git-bug/gitconfig

Example

package main

import (
	"fmt"
	"log"

	"github.com/git-bug/gitconfig"
)

func main() {
	// Find the repository and where git reads its configuration from.
	env, err := gitconfig.Discover(".")
	if err != nil {
		log.Fatal(err) // ErrNotRepository, or ErrUntrusted as git refuses it
	}

	// Read the effective configuration: system, global, local, worktree
	// and command scopes, with includes, as git would use it.
	cfg, err := env.Load()
	if err != nil {
		log.Fatal(err)
	}
	if e, ok := cfg.Get("user.name"); ok {
		fmt.Printf("user.name = %s (%s)\n", e.Value, e.Origin.File)
	}

	// Edit the repository's config. Comments and layout are kept, and the
	// file is not touched if the value is already set.
	err = env.UpdateScope(gitconfig.ScopeLocal, func(f *gitconfig.File) error {
		return f.Set("core.editor", "vim")
	})
	if err != nil {
		log.Fatal(err)
	}
}

License

MIT, see LICENSE. This is a clean room implementation: no code is derived from git, see CLEAN-ROOM.md. It is meant to interoperate with git.

About

Read and edit any git config, correctly.

Resources

Readme
MIT license
Activity
Custom properties

Stars

2 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.