MCPcopy
hub / github.com/github/git-sizer / AddFile

Method AddFile

internal/testutils/repoutils.go:212–233  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

210// with the specified `contents`. This must be run in a non-bare
211// repository.
212func (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

Callers 2

TestFromSubdirFunction · 0.95
TestSubmoduleFunction · 0.95

Calls 3

GitCommandMethod · 0.95
RunMethod · 0.80
CloseMethod · 0.45

Tested by 2

TestFromSubdirFunction · 0.76
TestSubmoduleFunction · 0.76