newGitRepoWithRemote creates a working clone whose origin is a local bare repo, with origin/HEAD pointing at main, and HEAD at the remote tip.
(t *testing.T)
| 60 | // newGitRepoWithRemote creates a working clone whose origin is a local bare |
| 61 | // repo, with origin/HEAD pointing at main, and HEAD at the remote tip. |
| 62 | func newGitRepoWithRemote(t *testing.T) *gitRepo { |
| 63 | t.Helper() |
| 64 | root := t.TempDir() |
| 65 | bare := filepath.Join(root, "origin.git") |
| 66 | work := filepath.Join(root, "work") |
| 67 | |
| 68 | runGitIn(t, root, "init", "--bare", "--initial-branch=main", bare) |
| 69 | |
| 70 | r := &gitRepo{dir: work} |
| 71 | runGitIn(t, root, "clone", bare, work) |
| 72 | r.config(t) |
| 73 | require.NoError(t, os.WriteFile(filepath.Join(work, "README.md"), []byte("seed\n"), 0o644)) |
| 74 | r.run(t, "add", "README.md") |
| 75 | r.run(t, "commit", "-m", "seed") |
| 76 | r.run(t, "push", "-u", "origin", "main") |
| 77 | // Make origin/HEAD resolvable so remoteDefaultBranch finds it. |
| 78 | r.run(t, "remote", "set-head", "origin", "main") |
| 79 | return r |
| 80 | } |
| 81 | |
| 82 | func (r *gitRepo) config(t *testing.T) { |
| 83 | t.Helper() |
no test coverage detected