MCPcopy Create free account
hub / github.com/github/gh-aw / TestReadFileFromHEAD

Function TestReadFileFromHEAD

pkg/gitutil/gitutil_test.go:381–407  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

379}
380
381func TestReadFileFromHEAD(t *testing.T) {
382 t.Run("reads a committed file with pre-computed root", func(t *testing.T) {
383 gitRoot, err := FindGitRoot()
384 require.NoError(t, err, "must be inside a git repository")
385
386 content, err := ReadFileFromHEAD(filepath.Join(gitRoot, "go.mod"), gitRoot)
387 require.NoError(t, err, "go.mod should be readable from HEAD with pre-computed root")
388 assert.NotEmpty(t, content, "go.mod content should not be empty")
389 assert.Contains(t, content, "module ", "go.mod should contain a module declaration")
390 })
391
392 t.Run("returns error for path outside git root", func(t *testing.T) {
393 gitRoot, err := FindGitRoot()
394 require.NoError(t, err, "must be inside a git repository")
395
396 outsidePath := filepath.Join(t.TempDir(), "file.yml")
397 _, err = ReadFileFromHEAD(outsidePath, gitRoot)
398 require.Error(t, err, "should fail for a file outside the git root")
399 assert.Contains(t, err.Error(), "outside the git repository root", "error should mention path is outside repo")
400 })
401
402 t.Run("returns error for empty gitRoot", func(t *testing.T) {
403 _, err := ReadFileFromHEAD("some/file.yml", "")
404 require.Error(t, err, "should fail when gitRoot is empty")
405 assert.Contains(t, err.Error(), "gitRoot must not be empty", "error should mention empty gitRoot")
406 })
407}

Callers

nothing calls this directly

Calls 4

FindGitRootFunction · 0.85
ReadFileFromHEADFunction · 0.85
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected