AddFile adds and stages a file in `repo` at path `relativePath` with the specified `contents`. This must be run in a non-bare repository.
(t *testing.T, relativePath, contents string)
| 210 | // with the specified `contents`. This must be run in a non-bare |
| 211 | // repository. |
| 212 | func (repo *TestRepo) AddFile(t *testing.T, relativePath, contents string) { |
| 213 | t.Helper() |
| 214 | |
| 215 | dirPath := filepath.Dir(relativePath) |
| 216 | if dirPath != "." { |
| 217 | require.NoError( |
| 218 | t, |
| 219 | os.MkdirAll(filepath.Join(repo.Path, dirPath), 0o777), |
| 220 | "creating subdir", |
| 221 | ) |
| 222 | } |
| 223 | |
| 224 | filename := filepath.Join(repo.Path, relativePath) |
| 225 | f, err := os.Create(filename) |
| 226 | require.NoErrorf(t, err, "creating file %q", filename) |
| 227 | _, err = f.WriteString(contents) |
| 228 | require.NoErrorf(t, err, "writing to file %q", filename) |
| 229 | require.NoErrorf(t, f.Close(), "closing file %q", filename) |
| 230 | |
| 231 | cmd := repo.GitCommand(t, "add", relativePath) |
| 232 | require.NoErrorf(t, cmd.Run(), "adding file %q", relativePath) |
| 233 | } |
| 234 | |
| 235 | // CreateReferencedOrphan creates a simple new orphan commit and |
| 236 | // points the reference with name `refname` at it. This can be run in |