mirror of
https://github.com/grdl/git-get.git
synced 2026-02-04 20:54:41 +00:00
Fix issues found by thelper linter
This commit is contained in:
@@ -14,6 +14,8 @@ import (
|
||||
// TempDir creates a temporary directory inside the parent dir.
|
||||
// If parent is empty, it will use a system default temp dir (usually /tmp).
|
||||
func TempDir(t *testing.T, parent string) string {
|
||||
t.Helper()
|
||||
|
||||
dir, err := ioutil.TempDir(parent, "git-get-repo-")
|
||||
checkFatal(t, err)
|
||||
|
||||
@@ -87,6 +89,8 @@ func (r *Repo) fetch() {
|
||||
}
|
||||
|
||||
func checkFatal(t *testing.T, err error) {
|
||||
t.Helper()
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed making test repo: %+v", err)
|
||||
}
|
||||
@@ -94,6 +98,7 @@ func checkFatal(t *testing.T, err error) {
|
||||
|
||||
// removeTestDir removes a test directory.
|
||||
func removeTestDir(t *testing.T, dir string) {
|
||||
t.Helper()
|
||||
// Skip cleanup on Windows to avoid file locking issues in CI
|
||||
// The CI runner environment is destroyed after tests anyway
|
||||
if runtime.GOOS == "windows" {
|
||||
|
||||
@@ -19,11 +19,13 @@ func (r *Repo) Path() string {
|
||||
|
||||
// RepoEmpty creates an empty git repo.
|
||||
func RepoEmpty(t *testing.T) *Repo {
|
||||
t.Helper()
|
||||
return RepoEmptyInDir(t, "")
|
||||
}
|
||||
|
||||
// RepoEmptyInDir creates an empty git repo inside a given parent dir.
|
||||
func RepoEmptyInDir(t *testing.T, parent string) *Repo {
|
||||
t.Helper()
|
||||
r := &Repo{
|
||||
path: TempDir(t, parent),
|
||||
t: t,
|
||||
@@ -36,6 +38,7 @@ func RepoEmptyInDir(t *testing.T, parent string) *Repo {
|
||||
|
||||
// RepoWithUntracked creates a git repo with a single untracked file.
|
||||
func RepoWithUntracked(t *testing.T) *Repo {
|
||||
t.Helper()
|
||||
r := RepoEmpty(t)
|
||||
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.
|
||||
func RepoWithStaged(t *testing.T) *Repo {
|
||||
t.Helper()
|
||||
r := RepoEmpty(t)
|
||||
r.writeFile("README.md", "I'm a readme file")
|
||||
r.stageFile("README.md")
|
||||
@@ -53,6 +57,7 @@ func RepoWithStaged(t *testing.T) *Repo {
|
||||
|
||||
// RepoWithCommit creates a git repo with a single commit.
|
||||
func RepoWithCommit(t *testing.T) *Repo {
|
||||
t.Helper()
|
||||
r := RepoEmpty(t)
|
||||
r.writeFile("README.md", "I'm a readme file")
|
||||
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.
|
||||
func RepoWithUncommittedAndUntracked(t *testing.T) *Repo {
|
||||
t.Helper()
|
||||
r := RepoEmpty(t)
|
||||
r.writeFile("README.md", "I'm a readme file")
|
||||
r.stageFile("README.md")
|
||||
@@ -75,6 +81,7 @@ func RepoWithUncommittedAndUntracked(t *testing.T) *Repo {
|
||||
|
||||
// RepoWithBranch creates a git repo with a new branch.
|
||||
func RepoWithBranch(t *testing.T) *Repo {
|
||||
t.Helper()
|
||||
r := RepoWithCommit(t)
|
||||
r.branch("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.
|
||||
func RepoWithTag(t *testing.T) *Repo {
|
||||
t.Helper()
|
||||
r := RepoWithCommit(t)
|
||||
r.tag("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.
|
||||
func RepoWithBranchWithUpstream(t *testing.T) *Repo {
|
||||
t.Helper()
|
||||
origin := RepoWithCommit(t)
|
||||
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.
|
||||
func RepoWithBranchWithoutUpstream(t *testing.T) *Repo {
|
||||
t.Helper()
|
||||
origin := RepoWithCommit(t)
|
||||
|
||||
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.
|
||||
func RepoWithBranchAhead(t *testing.T) *Repo {
|
||||
t.Helper()
|
||||
origin := RepoWithCommit(t)
|
||||
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.
|
||||
func RepoWithBranchBehind(t *testing.T) *Repo {
|
||||
t.Helper()
|
||||
origin := RepoWithCommit(t)
|
||||
origin.branch("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.
|
||||
func RepoWithBranchAheadAndBehind(t *testing.T) *Repo {
|
||||
t.Helper()
|
||||
origin := RepoWithCommit(t)
|
||||
origin.branch("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.
|
||||
func RepoWithEmptyConfig(t *testing.T) *Repo {
|
||||
t.Helper()
|
||||
r := RepoEmpty(t)
|
||||
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.
|
||||
func RepoWithValidConfig(t *testing.T) *Repo {
|
||||
t.Helper()
|
||||
r := RepoEmpty(t)
|
||||
|
||||
gitconfig := `
|
||||
|
||||
Reference in New Issue
Block a user