mirror of
https://github.com/grdl/git-get.git
synced 2026-02-04 19:09:45 +00:00
* Fix typo in readme * Reimplement all git methods without go-git * Rename repo pkg to git, add gitconfig methods * Improve tests for configuration reading * Rename package file to io and move RepoFinder there * Refactor printers - Remove smart printer - Decouple printers from git repos with interfaces - Update printer functions - Remove unnecessary flags - Add better remote URL detection * Update readme and go.mod * Add author to git commit in tests Otherwise tests will fail in CI. * Install git before running tests and don't use cgo * Add better error message, revert installing git * Ensure commit message is in quotes * Set up git config before running tests
21 lines
497 B
Go
21 lines
497 B
Go
package git
|
|
|
|
import "os/exec"
|
|
|
|
// ConfigGlobal represents a global gitconfig file.
|
|
type ConfigGlobal struct{}
|
|
|
|
// Get reads a value from global gitconfig file. Returns empty string when key is missing.
|
|
func (c *ConfigGlobal) Get(key string) string {
|
|
cmd := exec.Command("git", "config", "--global", key)
|
|
out, err := cmd.Output()
|
|
|
|
// In case of error return an empty string, the missing value will fall back to a default.
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
|
|
lines := lines(out)
|
|
return lines[0]
|
|
}
|