# README
for what
- this project used to management git local project with golang
depends
in go mod project
# warning use private git host must set
# global set for once
# add private git host like github.com to evn GOPRIVATE
$ go env -w GOPRIVATE='github.com'
# use ssh proxy
# set ssh-key to use ssh as http
$ git config --global url."[email protected]:".insteadOf "https://github.com/"
# or use PRIVATE-TOKEN
# set PRIVATE-TOKEN as gitlab or gitea
$ git config --global http.extraheader "PRIVATE-TOKEN: {PRIVATE-TOKEN}"
# set this rep to download ssh as https use PRIVATE-TOKEN
$ git config --global url."ssh://github.com/".insteadOf "https://github.com/"
# before above global settings
# test version info
$ git ls-remote -q https://github.com/sinlov-go/go-git-tools.git
# test depends see full version
$ go list -mod readonly -v -m -versions github.com/sinlov-go/go-git-tools
# or use last version add go.mod by script
$ echo "go mod edit -require=$(go list -mod=readonly -m -versions github.com/sinlov-go/go-git-tools | awk '{print $1 "@" $NF}')"
$ echo "go mod vendor"
Features
pkg github.com/sinlov-go/go-git-tools/git
package foo
import (
"github.com/sinlov-go/go-git-tools/git"
)
-
git.NewRepositoryByPath(gitRootPath)
to load local git project-
HeadReference() (*plumbing.Reference, error)
get head reference -
HeadBranchName() (string, error)
get head branch name -
CheckHasSubmodules() (bool, error)
check has submodules -
CheckSubmodulesIsDirty() (bool, error)
check submodules is dirty -
CheckLocalBranchIsDirty() (bool, error)
check local branch is dirty -
Log(fromRev, toRev string) ([]Commit, error)
return all commits between and -
CommitLatestTagByTime() (*Commit, error)
return latest tag commit -
CommitTagSearchByName(tagName string) (*Commit, error)
return tag commit -
CommitTagSearchByFirstLine(firstLine string) (*Commit, error)
return tag commit -
Commit(commitMessage string, paths ...string) error
commit
-
-
support setting
SetAuthMethod(auth transport.AuthMethod)
andSetAuthMethod(auth transport.AuthMethod)
for private git remote
package foo_test
func TestSetAuth(t *testing.T) {
const envFlag = "ENV_TEST_REPO_SET_AUTH"
valEnvPath := env_kit.FetchOsEnvStr(envFlag, "")
if valEnvPath == "" {
t.Skipf("env is empty: %s", envFlag)
}
const envFlagKeyPath = "ENV_TEST_REPO_SET_AUTH_KEY_PATH"
valSshKeyPath := env_kit.FetchOsEnvStr(envFlagKeyPath, "")
if valSshKeyPath == "" {
t.Skipf("env is empty: %s", envFlagKeyPath)
}
const envFlagKeyPassword = "ENV_TEST_REPO_SET_AUTH_KEY_PASS_WORD"
valSshKeyPassWord := env_kit.FetchOsEnvStr(envFlagKeyPassword, "")
repository, err := NewRepositoryByPath(valEnvPath)
if err != nil {
t.Fatal(err)
}
auth, err := ssh.NewPublicKeysFromFile("git", valSshKeyPath, valSshKeyPassWord)
if err != nil {
t.Fatal(err)
}
repository.SetAuth(auth)
err = repository.PullOrigin()
if err != nil {
t.Fatal(err)
}
}
pkg github.com/sinlov-go/go-git-tools/git_info
package foo
import (
"github.com/sinlov-go/go-git-tools/git_info"
)
-
git_info
package to get info of repository-
IsPathUnderGitManagement
check path is under git management -
RepositoryFistRemoteInfo
get repository first remote info -
RepositoryHeadByPath
get repository head by local path -
RepositoryNowBranchByPath
get repository now branch by local path -
RepositoryConfigPath
get repository config by local path
-
-
more perfect test case coverage
-
more perfect benchmark case
dev
- see doc/dev.md
# Packages
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author