mod: tidy and vendor
parent
f7d566b915
commit
f384e57917
@ -1 +0,0 @@
|
||||
*.test
|
@ -1,64 +0,0 @@
|
||||
## 0.1.2 (2015-03-28)
|
||||
|
||||
Add new functions
|
||||
|
||||
### Added
|
||||
|
||||
- `GithubUser()` extracts `github.user` ([**dstokes**](https://github.com/dstokes)), [#5](https://github.com/tcnksm/go-gitconfig/pull/5/commits)
|
||||
|
||||
### Deprecated
|
||||
|
||||
- Nothing
|
||||
|
||||
### Removed
|
||||
|
||||
- Nothing
|
||||
|
||||
### Fixed
|
||||
|
||||
- Nothing
|
||||
|
||||
|
||||
## 0.1.1 (2014-10-28)
|
||||
|
||||
Add new functions
|
||||
|
||||
### Added
|
||||
|
||||
- `GithubToken()` extracts `github.token` ([**@sona-tar**](https://github.com/sona-tar), [#3](https://github.com/tcnksm/go-gitconfig/pull/3))
|
||||
- `Entire()` try to extract value from entire git config. It's able to extract values from included config ([**@sona-tar**](https://github.com/sona-tar), [#3](https://github.com/tcnksm/go-gitconfig/pull/3))
|
||||
|
||||
### Deprecated
|
||||
|
||||
- Nothing
|
||||
|
||||
### Removed
|
||||
|
||||
- Nothing
|
||||
|
||||
### Fixed
|
||||
|
||||
- Nothing
|
||||
|
||||
|
||||
## 0.1.0 (2014-09-08)
|
||||
|
||||
Initial release
|
||||
|
||||
### Added
|
||||
|
||||
- Fundamental features
|
||||
|
||||
### Deprecated
|
||||
|
||||
- Nothing
|
||||
|
||||
### Removed
|
||||
|
||||
- Nothing
|
||||
|
||||
### Fixed
|
||||
|
||||
- Nothing
|
||||
|
||||
|
@ -1,22 +0,0 @@
|
||||
Copyright (c) 2014 tcnksm
|
||||
|
||||
MIT License
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@ -1,84 +0,0 @@
|
||||
go-gitconfig
|
||||
====
|
||||
|
||||
[![GitHub release](http://img.shields.io/github/release/tcnksm/go-gitconfig.svg?style=flat-square)][release]
|
||||
[![Wercker](http://img.shields.io/wercker/ci/544ee33aea87f6374f001483.svg?style=flat-square)][wercker]
|
||||
[![Coveralls](http://img.shields.io/coveralls/tcnksm/go-gitconfig.svg?style=flat-square)][coveralls]
|
||||
[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)][license]
|
||||
[![Go Documentation](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)][godocs]
|
||||
|
||||
[release]: https://github.com/tcnksm/go-gitconfig/releases
|
||||
[wercker]: https://app.wercker.com/project/bykey/89c5a6e50a0daceec971ff5ce210164a
|
||||
[coveralls]: https://coveralls.io/r/tcnksm/go-gitconfig
|
||||
[license]: https://github.com/tcnksm/go-gitconfig/blob/master/LICENSE
|
||||
[godocs]: http://godoc.org/github.com/tcnksm/go-gitconfig
|
||||
|
||||
|
||||
`go-gitconfig` is a pacakge to use `gitconfig` values in Golang.
|
||||
|
||||
Sometimes you want to extract username or its email address **implicitly** in your tool.
|
||||
Now most of developer use `git`, so we can use its configuration variables. `go-gitconfig` is for that.
|
||||
|
||||
`go-gitconfig` is very small, so it may not be included what you want to use.
|
||||
If you want to use more git specific variable, check [Other](##VS).
|
||||
|
||||
## Usage
|
||||
|
||||
If you want to use git user name defined in `~/.gitconfig`:
|
||||
|
||||
```go
|
||||
username, err := gitconfig.Username()
|
||||
```
|
||||
|
||||
Or git user email defined in `~/.gitconfig`:
|
||||
|
||||
```go
|
||||
email, err := gitconfig.Email()
|
||||
```
|
||||
|
||||
Or, if you want to extract origin url of current project (from `.git/config`):
|
||||
|
||||
```go
|
||||
url, err := gitconfig.OriginURL()
|
||||
```
|
||||
|
||||
You can also extract value by key:
|
||||
|
||||
```go
|
||||
editor, err := gitconfig.Global("core.editor")
|
||||
```
|
||||
|
||||
```go
|
||||
remote, err := gitconfig.Local("branch.master.remote")
|
||||
```
|
||||
|
||||
See more details in document at [https://godoc.org/github.com/tcnksm/go-gitconfig](https://godoc.org/github.com/tcnksm/go-gitconfig).
|
||||
|
||||
## Install
|
||||
|
||||
To install, use `go get`:
|
||||
|
||||
```bash
|
||||
$ go get -d github.com/tcnksm/go-gitconfig
|
||||
```
|
||||
|
||||
## VS.
|
||||
|
||||
- [speedata/gogit](https://github.com/speedata/gogit)
|
||||
- [libgit2/git2go](https://github.com/libgit2/git2go)
|
||||
|
||||
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](https://github.com/tcnksm/ghr).
|
||||
|
||||
## Contribution
|
||||
|
||||
1. Fork ([https://github.com/tcnksm/go-gitconfig/fork](https://github.com/tcnksm/go-gitconfig/fork))
|
||||
1. Create a feature branch
|
||||
1. Commit your changes
|
||||
1. Rebase your local changes against the master branch
|
||||
1. Run test suite with the `go test ./...` command and confirm that it passes
|
||||
1. Run `gofmt -s`
|
||||
1. Create new Pull Request
|
||||
|
||||
## Author
|
||||
|
||||
[tcnksm](https://github.com/tcnksm)
|
@ -1,113 +0,0 @@
|
||||
// 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)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
package gitconfig
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"strings"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// Entire extracts configuration value from `$HOME/.gitconfig` file ,
|
||||
// `$GIT_CONFIG`, /etc/gitconfig or include.path files.
|
||||
func Entire(key string) (string, error) {
|
||||
return execGitConfig(key)
|
||||
}
|
||||
|
||||
// Global extracts configuration value from `$HOME/.gitconfig` file or `$GIT_CONFIG`.
|
||||
func Global(key string) (string, error) {
|
||||
return execGitConfig("--global", key)
|
||||
}
|
||||
|
||||
// Local extracts configuration value from current project repository.
|
||||
func Local(key string) (string, error) {
|
||||
return execGitConfig("--local", key)
|
||||
}
|
||||
|
||||
// GithubUser extracts github.user name from `Entire gitconfig`
|
||||
// This is same as Entire("github.user")
|
||||
func GithubUser() (string, error) {
|
||||
return Entire("github.user")
|
||||
}
|
||||
|
||||
// Username extracts git user name from `Entire gitconfig`.
|
||||
// This is same as Entire("user.name")
|
||||
func Username() (string, error) {
|
||||
return Entire("user.name")
|
||||
}
|
||||
|
||||
// Email extracts git user email from `$HOME/.gitconfig` file or `$GIT_CONFIG`.
|
||||
// This is same as Global("user.email")
|
||||
func Email() (string, error) {
|
||||
return Entire("user.email")
|
||||
}
|
||||
|
||||
// OriginURL extract remote origin url from current project repository.
|
||||
// This is same as Local("remote.origin.url")
|
||||
func OriginURL() (string, error) {
|
||||
return Local("remote.origin.url")
|
||||
}
|
||||
|
||||
// Repository extract repository name of current project repository.
|
||||
func Repository() (string, error) {
|
||||
url, err := OriginURL()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
repo := retrieveRepoName(url)
|
||||
return repo, nil
|
||||
}
|
||||
|
||||
// Github extracts github token from `Entire gitconfig`.
|
||||
// This is same as Entire("github.token")
|
||||
func GithubToken() (string, error) {
|
||||
return Entire("github.token")
|
||||
}
|
||||
|
||||
func execGitConfig(args ...string) (string, error) {
|
||||
gitArgs := append([]string{"config", "--get", "--null"}, args...)
|
||||
var stdout bytes.Buffer
|
||||
cmd := exec.Command("git", gitArgs...)
|
||||
cmd.Stdout = &stdout
|
||||
cmd.Stderr = ioutil.Discard
|
||||
|
||||
err := cmd.Run()
|
||||
if exitError, ok := err.(*exec.ExitError); ok {
|
||||
if waitStatus, ok := exitError.Sys().(syscall.WaitStatus); ok {
|
||||
if waitStatus.ExitStatus() == 1 {
|
||||
return "", fmt.Errorf("the key `%s` is not found", args[len(args)-1])
|
||||
}
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
|
||||
return strings.TrimRight(stdout.String(), "\000"), nil
|
||||
}
|
||||
|
||||
var RepoNameRegexp = regexp.MustCompile(`.+/([^/]+)(\.git)?$`)
|
||||
|
||||
func retrieveRepoName(url string) string {
|
||||
matched := RepoNameRegexp.FindStringSubmatch(url)
|
||||
return strings.TrimSuffix(matched[1], ".git")
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
box: tcnksm/gox
|
||||
build:
|
||||
steps:
|
||||
- setup-go-workspace
|
||||
- script:
|
||||
name: install latest git
|
||||
code: |
|
||||
sudo add-apt-repository -y ppa:git-core/ppa
|
||||
sudo apt-get -y update
|
||||
sudo apt-get -y install git
|
||||
- script:
|
||||
name: git version
|
||||
code: |
|
||||
git version
|
||||
- script:
|
||||
name: go get
|
||||
code: |
|
||||
go get -t ./...
|
||||
- tcnksm/goveralls:
|
||||
token: $COVERALLS_REPO_TOKEN
|
Loading…
Reference in New Issue