mirror of
https://github.com/grdl/git-get.git
synced 2026-02-09 06:49:26 +00:00
Fix issues found by thelper linter
This commit is contained in:
@@ -29,6 +29,8 @@ linters:
|
|||||||
ignore-string-values:
|
ignore-string-values:
|
||||||
- "get"
|
- "get"
|
||||||
- "list"
|
- "list"
|
||||||
|
lll:
|
||||||
|
line-length: 180
|
||||||
|
|
||||||
exclusions:
|
exclusions:
|
||||||
# Typical presets to exclude: https://golangci-lint.run/docs/linters/false-positives/#exclusion-presets
|
# Typical presets to exclude: https://golangci-lint.run/docs/linters/false-positives/#exclusion-presets
|
||||||
|
|||||||
@@ -86,24 +86,29 @@ func (c *gitconfigValid) Get(key string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testConfigEmpty(t *testing.T) {
|
func testConfigEmpty(t *testing.T) {
|
||||||
|
t.Helper()
|
||||||
Init(&gitconfigEmpty{})
|
Init(&gitconfigEmpty{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testConfigOnlyInGitconfig(t *testing.T) {
|
func testConfigOnlyInGitconfig(t *testing.T) {
|
||||||
|
t.Helper()
|
||||||
Init(&gitconfigValid{})
|
Init(&gitconfigValid{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testConfigOnlyInEnvVar(t *testing.T) {
|
func testConfigOnlyInEnvVar(t *testing.T) {
|
||||||
|
t.Helper()
|
||||||
Init(&gitconfigEmpty{})
|
Init(&gitconfigEmpty{})
|
||||||
t.Setenv(envVarName, fromEnv)
|
t.Setenv(envVarName, fromEnv)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testConfigInGitconfigAndEnvVar(t *testing.T) {
|
func testConfigInGitconfigAndEnvVar(t *testing.T) {
|
||||||
|
t.Helper()
|
||||||
Init(&gitconfigValid{})
|
Init(&gitconfigValid{})
|
||||||
t.Setenv(envVarName, fromEnv)
|
t.Setenv(envVarName, fromEnv)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testConfigInFlag(t *testing.T) {
|
func testConfigInFlag(t *testing.T) {
|
||||||
|
t.Helper()
|
||||||
Init(&gitconfigValid{})
|
Init(&gitconfigValid{})
|
||||||
t.Setenv(envVarName, fromEnv)
|
t.Setenv(envVarName, fromEnv)
|
||||||
|
|
||||||
|
|||||||
@@ -65,12 +65,16 @@ func TestGitConfig(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func makeConfigEmpty(t *testing.T) *cfgStub {
|
func makeConfigEmpty(t *testing.T) *cfgStub {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
return &cfgStub{
|
return &cfgStub{
|
||||||
Repo: test.RepoWithEmptyConfig(t),
|
Repo: test.RepoWithEmptyConfig(t),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeConfigValid(t *testing.T) *cfgStub {
|
func makeConfigValid(t *testing.T) *cfgStub {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
return &cfgStub{
|
return &cfgStub{
|
||||||
Repo: test.RepoWithValidConfig(t),
|
Repo: test.RepoWithValidConfig(t),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ func TestExists(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func makeSingleRepo(t *testing.T) string {
|
func makeSingleRepo(t *testing.T) string {
|
||||||
|
t.Helper()
|
||||||
root := test.TempDir(t, "")
|
root := test.TempDir(t, "")
|
||||||
|
|
||||||
test.RepoEmptyInDir(t, root)
|
test.RepoEmptyInDir(t, root)
|
||||||
@@ -80,6 +81,7 @@ func makeSingleRepo(t *testing.T) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func makeNestedRepo(t *testing.T) string {
|
func makeNestedRepo(t *testing.T) string {
|
||||||
|
t.Helper()
|
||||||
// a repo with single nested repo should still be counted as one beacause finder doesn't traverse inside nested repos
|
// a repo with single nested repo should still be counted as one beacause finder doesn't traverse inside nested repos
|
||||||
root := test.TempDir(t, "")
|
root := test.TempDir(t, "")
|
||||||
|
|
||||||
@@ -90,6 +92,7 @@ func makeNestedRepo(t *testing.T) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func makeMultipleNestedRepos(t *testing.T) string {
|
func makeMultipleNestedRepos(t *testing.T) string {
|
||||||
|
t.Helper()
|
||||||
root := test.TempDir(t, "")
|
root := test.TempDir(t, "")
|
||||||
|
|
||||||
// create two repos inside root - should be counted as 2
|
// create two repos inside root - should be counted as 2
|
||||||
|
|||||||
@@ -411,6 +411,7 @@ func TestRemote(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createTestDirTree(t *testing.T) string {
|
func createTestDirTree(t *testing.T) string {
|
||||||
|
t.Helper()
|
||||||
root := test.TempDir(t, "")
|
root := test.TempDir(t, "")
|
||||||
err := os.MkdirAll(filepath.Join(root, "a", "b", "c"), os.ModePerm)
|
err := os.MkdirAll(filepath.Join(root, "a", "b", "c"), os.ModePerm)
|
||||||
err = os.MkdirAll(filepath.Join(root, "a", "x", "y"), os.ModePerm)
|
err = os.MkdirAll(filepath.Join(root, "a", "x", "y"), os.ModePerm)
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ import (
|
|||||||
// TempDir creates a temporary directory inside the parent dir.
|
// TempDir creates a temporary directory inside the parent dir.
|
||||||
// If parent is empty, it will use a system default temp dir (usually /tmp).
|
// If parent is empty, it will use a system default temp dir (usually /tmp).
|
||||||
func TempDir(t *testing.T, parent string) string {
|
func TempDir(t *testing.T, parent string) string {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
dir, err := ioutil.TempDir(parent, "git-get-repo-")
|
dir, err := ioutil.TempDir(parent, "git-get-repo-")
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
@@ -87,6 +89,8 @@ func (r *Repo) fetch() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func checkFatal(t *testing.T, err error) {
|
func checkFatal(t *testing.T, err error) {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed making test repo: %+v", err)
|
t.Fatalf("failed making test repo: %+v", err)
|
||||||
}
|
}
|
||||||
@@ -94,6 +98,7 @@ func checkFatal(t *testing.T, err error) {
|
|||||||
|
|
||||||
// removeTestDir removes a test directory.
|
// removeTestDir removes a test directory.
|
||||||
func removeTestDir(t *testing.T, dir string) {
|
func removeTestDir(t *testing.T, dir string) {
|
||||||
|
t.Helper()
|
||||||
// Skip cleanup on Windows to avoid file locking issues in CI
|
// Skip cleanup on Windows to avoid file locking issues in CI
|
||||||
// The CI runner environment is destroyed after tests anyway
|
// The CI runner environment is destroyed after tests anyway
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
|
|||||||
@@ -19,11 +19,13 @@ func (r *Repo) Path() string {
|
|||||||
|
|
||||||
// RepoEmpty creates an empty git repo.
|
// RepoEmpty creates an empty git repo.
|
||||||
func RepoEmpty(t *testing.T) *Repo {
|
func RepoEmpty(t *testing.T) *Repo {
|
||||||
|
t.Helper()
|
||||||
return RepoEmptyInDir(t, "")
|
return RepoEmptyInDir(t, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
// RepoEmptyInDir creates an empty git repo inside a given parent dir.
|
// RepoEmptyInDir creates an empty git repo inside a given parent dir.
|
||||||
func RepoEmptyInDir(t *testing.T, parent string) *Repo {
|
func RepoEmptyInDir(t *testing.T, parent string) *Repo {
|
||||||
|
t.Helper()
|
||||||
r := &Repo{
|
r := &Repo{
|
||||||
path: TempDir(t, parent),
|
path: TempDir(t, parent),
|
||||||
t: t,
|
t: t,
|
||||||
@@ -36,6 +38,7 @@ func RepoEmptyInDir(t *testing.T, parent string) *Repo {
|
|||||||
|
|
||||||
// RepoWithUntracked creates a git repo with a single untracked file.
|
// RepoWithUntracked creates a git repo with a single untracked file.
|
||||||
func RepoWithUntracked(t *testing.T) *Repo {
|
func RepoWithUntracked(t *testing.T) *Repo {
|
||||||
|
t.Helper()
|
||||||
r := RepoEmpty(t)
|
r := RepoEmpty(t)
|
||||||
r.writeFile("README.md", "I'm a readme file")
|
r.writeFile("README.md", "I'm a readme file")
|
||||||
|
|
||||||
@@ -44,6 +47,7 @@ func RepoWithUntracked(t *testing.T) *Repo {
|
|||||||
|
|
||||||
// RepoWithStaged creates a git repo with a single staged file.
|
// RepoWithStaged creates a git repo with a single staged file.
|
||||||
func RepoWithStaged(t *testing.T) *Repo {
|
func RepoWithStaged(t *testing.T) *Repo {
|
||||||
|
t.Helper()
|
||||||
r := RepoEmpty(t)
|
r := RepoEmpty(t)
|
||||||
r.writeFile("README.md", "I'm a readme file")
|
r.writeFile("README.md", "I'm a readme file")
|
||||||
r.stageFile("README.md")
|
r.stageFile("README.md")
|
||||||
@@ -53,6 +57,7 @@ func RepoWithStaged(t *testing.T) *Repo {
|
|||||||
|
|
||||||
// RepoWithCommit creates a git repo with a single commit.
|
// RepoWithCommit creates a git repo with a single commit.
|
||||||
func RepoWithCommit(t *testing.T) *Repo {
|
func RepoWithCommit(t *testing.T) *Repo {
|
||||||
|
t.Helper()
|
||||||
r := RepoEmpty(t)
|
r := RepoEmpty(t)
|
||||||
r.writeFile("README.md", "I'm a readme file")
|
r.writeFile("README.md", "I'm a readme file")
|
||||||
r.stageFile("README.md")
|
r.stageFile("README.md")
|
||||||
@@ -63,6 +68,7 @@ func RepoWithCommit(t *testing.T) *Repo {
|
|||||||
|
|
||||||
// RepoWithUncommittedAndUntracked creates a git repo with one staged but uncommitted file and one untracked file.
|
// RepoWithUncommittedAndUntracked creates a git repo with one staged but uncommitted file and one untracked file.
|
||||||
func RepoWithUncommittedAndUntracked(t *testing.T) *Repo {
|
func RepoWithUncommittedAndUntracked(t *testing.T) *Repo {
|
||||||
|
t.Helper()
|
||||||
r := RepoEmpty(t)
|
r := RepoEmpty(t)
|
||||||
r.writeFile("README.md", "I'm a readme file")
|
r.writeFile("README.md", "I'm a readme file")
|
||||||
r.stageFile("README.md")
|
r.stageFile("README.md")
|
||||||
@@ -75,6 +81,7 @@ func RepoWithUncommittedAndUntracked(t *testing.T) *Repo {
|
|||||||
|
|
||||||
// RepoWithBranch creates a git repo with a new branch.
|
// RepoWithBranch creates a git repo with a new branch.
|
||||||
func RepoWithBranch(t *testing.T) *Repo {
|
func RepoWithBranch(t *testing.T) *Repo {
|
||||||
|
t.Helper()
|
||||||
r := RepoWithCommit(t)
|
r := RepoWithCommit(t)
|
||||||
r.branch("feature/branch")
|
r.branch("feature/branch")
|
||||||
r.checkout("feature/branch")
|
r.checkout("feature/branch")
|
||||||
@@ -84,6 +91,7 @@ func RepoWithBranch(t *testing.T) *Repo {
|
|||||||
|
|
||||||
// RepoWithTag creates a git repo with a new tag.
|
// RepoWithTag creates a git repo with a new tag.
|
||||||
func RepoWithTag(t *testing.T) *Repo {
|
func RepoWithTag(t *testing.T) *Repo {
|
||||||
|
t.Helper()
|
||||||
r := RepoWithCommit(t)
|
r := RepoWithCommit(t)
|
||||||
r.tag("v0.0.1")
|
r.tag("v0.0.1")
|
||||||
r.checkout("v0.0.1")
|
r.checkout("v0.0.1")
|
||||||
@@ -93,6 +101,7 @@ func RepoWithTag(t *testing.T) *Repo {
|
|||||||
|
|
||||||
// RepoWithBranchWithUpstream creates a git repo by cloning another repo and checking out a remote branch.
|
// RepoWithBranchWithUpstream creates a git repo by cloning another repo and checking out a remote branch.
|
||||||
func RepoWithBranchWithUpstream(t *testing.T) *Repo {
|
func RepoWithBranchWithUpstream(t *testing.T) *Repo {
|
||||||
|
t.Helper()
|
||||||
origin := RepoWithCommit(t)
|
origin := RepoWithCommit(t)
|
||||||
origin.branch("feature/branch")
|
origin.branch("feature/branch")
|
||||||
|
|
||||||
@@ -104,6 +113,7 @@ func RepoWithBranchWithUpstream(t *testing.T) *Repo {
|
|||||||
|
|
||||||
// RepoWithBranchWithoutUpstream creates a git repo by cloning another repo and checking out a new local branch.
|
// RepoWithBranchWithoutUpstream creates a git repo by cloning another repo and checking out a new local branch.
|
||||||
func RepoWithBranchWithoutUpstream(t *testing.T) *Repo {
|
func RepoWithBranchWithoutUpstream(t *testing.T) *Repo {
|
||||||
|
t.Helper()
|
||||||
origin := RepoWithCommit(t)
|
origin := RepoWithCommit(t)
|
||||||
|
|
||||||
r := origin.clone()
|
r := origin.clone()
|
||||||
@@ -115,6 +125,7 @@ func RepoWithBranchWithoutUpstream(t *testing.T) *Repo {
|
|||||||
|
|
||||||
// RepoWithBranchAhead creates a git repo with a branch being ahead of a remote branch by 1 commit.
|
// RepoWithBranchAhead creates a git repo with a branch being ahead of a remote branch by 1 commit.
|
||||||
func RepoWithBranchAhead(t *testing.T) *Repo {
|
func RepoWithBranchAhead(t *testing.T) *Repo {
|
||||||
|
t.Helper()
|
||||||
origin := RepoWithCommit(t)
|
origin := RepoWithCommit(t)
|
||||||
origin.branch("feature/branch")
|
origin.branch("feature/branch")
|
||||||
|
|
||||||
@@ -130,6 +141,7 @@ func RepoWithBranchAhead(t *testing.T) *Repo {
|
|||||||
|
|
||||||
// RepoWithBranchBehind creates a git repo with a branch being behind a remote branch by 1 commit.
|
// RepoWithBranchBehind creates a git repo with a branch being behind a remote branch by 1 commit.
|
||||||
func RepoWithBranchBehind(t *testing.T) *Repo {
|
func RepoWithBranchBehind(t *testing.T) *Repo {
|
||||||
|
t.Helper()
|
||||||
origin := RepoWithCommit(t)
|
origin := RepoWithCommit(t)
|
||||||
origin.branch("feature/branch")
|
origin.branch("feature/branch")
|
||||||
origin.checkout("feature/branch")
|
origin.checkout("feature/branch")
|
||||||
@@ -148,6 +160,7 @@ func RepoWithBranchBehind(t *testing.T) *Repo {
|
|||||||
|
|
||||||
// RepoWithBranchAheadAndBehind creates a git repo with a branch being 2 commits ahead and 1 behind a remote branch.
|
// RepoWithBranchAheadAndBehind creates a git repo with a branch being 2 commits ahead and 1 behind a remote branch.
|
||||||
func RepoWithBranchAheadAndBehind(t *testing.T) *Repo {
|
func RepoWithBranchAheadAndBehind(t *testing.T) *Repo {
|
||||||
|
t.Helper()
|
||||||
origin := RepoWithCommit(t)
|
origin := RepoWithCommit(t)
|
||||||
origin.branch("feature/branch")
|
origin.branch("feature/branch")
|
||||||
origin.checkout("feature/branch")
|
origin.checkout("feature/branch")
|
||||||
@@ -174,6 +187,7 @@ func RepoWithBranchAheadAndBehind(t *testing.T) *Repo {
|
|||||||
|
|
||||||
// RepoWithEmptyConfig creates a git repo with empty .git/config file.
|
// RepoWithEmptyConfig creates a git repo with empty .git/config file.
|
||||||
func RepoWithEmptyConfig(t *testing.T) *Repo {
|
func RepoWithEmptyConfig(t *testing.T) *Repo {
|
||||||
|
t.Helper()
|
||||||
r := RepoEmpty(t)
|
r := RepoEmpty(t)
|
||||||
r.writeFile(filepath.Join(".git", "config"), "")
|
r.writeFile(filepath.Join(".git", "config"), "")
|
||||||
|
|
||||||
@@ -182,6 +196,7 @@ func RepoWithEmptyConfig(t *testing.T) *Repo {
|
|||||||
|
|
||||||
// RepoWithValidConfig creates a git repo with valid content in .git/config file.
|
// RepoWithValidConfig creates a git repo with valid content in .git/config file.
|
||||||
func RepoWithValidConfig(t *testing.T) *Repo {
|
func RepoWithValidConfig(t *testing.T) *Repo {
|
||||||
|
t.Helper()
|
||||||
r := RepoEmpty(t)
|
r := RepoEmpty(t)
|
||||||
|
|
||||||
gitconfig := `
|
gitconfig := `
|
||||||
|
|||||||
Reference in New Issue
Block a user