gitconfig

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2014 License: MIT Imports: 7 Imported by: 0

README

go-gitconfig GoDoc wercker status Coverage Status

Use gitconfig values in Golang.

Usage

If you want to use git user name defined in ~/.gitconfig:

username, err := gitconfig.Username()

Or git user email defined in ~/.gitconfig:

email, err := gitconfig.Email()

Or, if you want to extract origin url of current project (from .git/config):

url, err := gitconfig.OriginURL()

You can also extract value by key:

editor, err := gitconfig.Global("core.editor")
remote, err := gitconfig.Local("branch.master.remote")

See more details in document at https://godoc.org/github.com/tcnksm/go-gitconfig.

Install

To install, use go get:

$ go get -d github.com/tcnksm/go-gitconfig

VS.

These packages have many features to use git from golang. go-gitconfig is very simple alternative and focus to extract information from gitconfig. go-gitconfig is used in tcnksm/ghr.

Contribution

  1. Fork (https://github.com/tcnksm/go-gitconfig/fork)
  2. Create a feature branch
  3. Commit your changes
  4. Rebase your local changes against the master branch
  5. Run test suite with the go test ./... command and confirm that it passes
  6. Run gofmt -s
  7. Create new Pull Request

LICENCE

MIT License

Author

tcnksm

Documentation

Overview

Package gitconfig enables you to use `~/.gitconfig` values in Golang.

For a full guide visit http://github.com/tcnksm/go-gitconfig

package main

import (
  "github.com/tcnksm/go-gitconfig"
  "fmt"
)

func main() {
  user, err := gitconfig.Global("user.name")
  if err == nil {
    fmt.Println(user)
  }
}

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("the key was not found")
View Source
var RepoNameRegexp = regexp.MustCompile(`.+/([^/]+)(\.git)?$`)

Functions

func Email

func Email() (string, error)

Email extracts git user email from `$HOME/.gitconfig` file or `$GIT_CONFIG`. This is same as Global("user.email")

func Entire

func Entire(key string) (string, error)

Entire extracts configuration value from `$HOME/.gitconfig` file , `$GIT_CONFIG`, /etc/gitconfig or include.path files.

func GithubToken

func GithubToken() (string, error)

Github extracts github token from `Entire gitconfig`. This is same as Entire("github.token")

func Global

func Global(key string) (string, error)

Global extracts configuration value from `$HOME/.gitconfig` file or `$GIT_CONFIG`.

func Local

func Local(key string) (string, error)

Local extracts configuration value from current project repository.

func OriginURL

func OriginURL() (string, error)

OriginURL extract remote origin url from current project repository. This is same as Local("remote.origin.url")

func Repository

func Repository() (string, error)

Repository extract repository name of current project repository.

func Username

func Username() (string, error)

Username extracts git user name from `Entire gitconfig`. This is same as Entire("user.name")

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL