Skip to content

Commit 7924a9e

Browse files
committed
main_test.gitCommand(): take a path rather than Repository arg
Let's decouple the tests from the `git` package.
1 parent ebb8ece commit 7924a9e

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

git_sizer_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ func TestExec(t *testing.T) {
2525
assert.NoErrorf(t, err, "command failed; output: %#v", string(output))
2626
}
2727

28-
func gitCommand(t *testing.T, repo *git.Repository, args ...string) *exec.Cmd {
28+
func gitCommand(t *testing.T, repoPath string, args ...string) *exec.Cmd {
2929
t.Helper()
3030

3131
cmd := exec.Command("git", args...)
32-
cmd.Env = append(os.Environ(), "GIT_DIR="+repo.Path())
32+
cmd.Env = append(os.Environ(), "GIT_DIR="+repoPath)
3333
return cmd
3434
}
3535

@@ -46,7 +46,7 @@ func addFile(t *testing.T, repoPath string, repo *git.Repository, relativePath,
4646
require.NoErrorf(t, err, "writing to file %q", filename)
4747
require.NoErrorf(t, f.Close(), "closing file %q", filename)
4848

49-
cmd := gitCommand(t, repo, "add", relativePath)
49+
cmd := gitCommand(t, repo.Path(), "add", relativePath)
5050
cmd.Dir = repoPath
5151
require.NoErrorf(t, cmd.Run(), "adding file %q", relativePath)
5252
}
@@ -207,21 +207,21 @@ func TestTaggedTags(t *testing.T) {
207207

208208
timestamp := time.Unix(1112911993, 0)
209209

210-
cmd = gitCommand(t, repo, "commit", "-m", "initial", "--allow-empty")
210+
cmd = gitCommand(t, repo.Path(), "commit", "-m", "initial", "--allow-empty")
211211
addAuthorInfo(cmd, &timestamp)
212212
require.NoError(t, cmd.Run(), "creating commit")
213213

214214
// The lexicographical order of these tags is important, hence
215215
// their strange names.
216-
cmd = gitCommand(t, repo, "tag", "-m", "tag 1", "tag", "master")
216+
cmd = gitCommand(t, repo.Path(), "tag", "-m", "tag 1", "tag", "master")
217217
addAuthorInfo(cmd, &timestamp)
218218
require.NoError(t, cmd.Run(), "creating tag 1")
219219

220-
cmd = gitCommand(t, repo, "tag", "-m", "tag 2", "bag", "tag")
220+
cmd = gitCommand(t, repo.Path(), "tag", "-m", "tag 2", "bag", "tag")
221221
addAuthorInfo(cmd, &timestamp)
222222
require.NoError(t, cmd.Run(), "creating tag 2")
223223

224-
cmd = gitCommand(t, repo, "tag", "-m", "tag 3", "wag", "bag")
224+
cmd = gitCommand(t, repo.Path(), "tag", "-m", "tag 3", "wag", "bag")
225225
addAuthorInfo(cmd, &timestamp)
226226
require.NoError(t, cmd.Run(), "creating tag 3")
227227

@@ -250,7 +250,7 @@ func TestFromSubdir(t *testing.T) {
250250

251251
addFile(t, path, repo, "subdir/file.txt", "Hello, world!\n")
252252

253-
cmd = gitCommand(t, repo, "commit", "-m", "initial")
253+
cmd = gitCommand(t, repo.Path(), "commit", "-m", "initial")
254254
addAuthorInfo(cmd, &timestamp)
255255
require.NoError(t, cmd.Run(), "creating commit")
256256

@@ -283,7 +283,7 @@ func TestSubmodule(t *testing.T) {
283283
addFile(t, submPath, submRepo, "submfile2.txt", "Hello again, submodule!\n")
284284
addFile(t, submPath, submRepo, "submfile3.txt", "Hello again, submodule!\n")
285285

286-
cmd = gitCommand(t, submRepo, "commit", "-m", "subm initial")
286+
cmd = gitCommand(t, submRepo.Path(), "commit", "-m", "subm initial")
287287
addAuthorInfo(cmd, &timestamp)
288288
require.NoError(t, cmd.Run(), "creating subm commit")
289289

@@ -294,16 +294,16 @@ func TestSubmodule(t *testing.T) {
294294
require.NoError(t, err, "initializing main Repository object")
295295
addFile(t, mainPath, mainRepo, "mainfile.txt", "Hello, main!\n")
296296

297-
cmd = gitCommand(t, mainRepo, "commit", "-m", "main initial")
297+
cmd = gitCommand(t, mainRepo.Path(), "commit", "-m", "main initial")
298298
addAuthorInfo(cmd, &timestamp)
299299
require.NoError(t, cmd.Run(), "creating main commit")
300300

301301
// Make subm a submodule of main:
302-
cmd = gitCommand(t, mainRepo, "submodule", "add", submPath, "sub")
302+
cmd = gitCommand(t, mainRepo.Path(), "submodule", "add", submPath, "sub")
303303
cmd.Dir = mainPath
304304
require.NoError(t, cmd.Run(), "adding submodule")
305305

306-
cmd = gitCommand(t, mainRepo, "commit", "-m", "add submodule")
306+
cmd = gitCommand(t, mainRepo.Path(), "commit", "-m", "add submodule")
307307
addAuthorInfo(cmd, &timestamp)
308308
require.NoError(t, cmd.Run(), "committing submodule to main")
309309

0 commit comments

Comments
 (0)