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

Method CreateObject

internal/testutils/repoutils.go:172–207  ·  view source on GitHub ↗

CreateObject creates a new Git object, of the specified type, in the repository at `repoPath`. `writer` is a function that generates the object contents in `git hash-object` input format.

(
	t *testing.T, otype git.ObjectType, writer func(io.Writer) error,
)

Source from the content-addressed store, hash-verified

170// the repository at `repoPath`. `writer` is a function that generates
171// the object contents in `git hash-object` input format.
172func (repo *TestRepo) CreateObject(
173 t *testing.T, otype git.ObjectType, writer func(io.Writer) error,
174) git.OID {
175 t.Helper()
176
177 cmd := repo.GitCommand(t, "hash-object", "-w", "-t", string(otype), "--stdin")
178 in, err := cmd.StdinPipe()
179 require.NoError(t, err)
180
181 out, err := cmd.StdoutPipe()
182 require.NoError(t, err)
183 cmd.Stderr = os.Stderr
184
185 err = cmd.Start()
186 require.NoError(t, err)
187
188 err = writer(in)
189 err2 := in.Close()
190 if !assert.NoError(t, err) {
191 _ = cmd.Wait()
192 t.FailNow()
193 }
194 if !assert.NoError(t, err2) {
195 _ = cmd.Wait()
196 t.FailNow()
197 }
198
199 output, err := io.ReadAll(out)
200 err2 = cmd.Wait()
201 require.NoError(t, err)
202 require.NoError(t, err2)
203
204 oid, err := git.NewOID(string(bytes.TrimSpace(output)))
205 require.NoError(t, err)
206 return oid
207}
208
209// AddFile adds and stages a file in `repo` at path `relativePath`
210// with the specified `contents`. This must be run in a non-bare

Callers 2

newGitBombFunction · 0.80

Calls 5

GitCommandMethod · 0.95
NewOIDFunction · 0.92
StartMethod · 0.65
WaitMethod · 0.65
CloseMethod · 0.45

Tested by 1

newGitBombFunction · 0.64