MCPcopy Create free account
hub / github.com/cwarden/git-add--interactive / NewRepository

Function NewRepository

internal/git/repository.go:18–44  ·  view source on GitHub ↗
(path string)

Source from the content-addressed store, hash-verified

16}
17
18func NewRepository(path string) (*Repository, error) {
19 cmd := exec.Command("git", "rev-parse", "--git-dir")
20 cmd.Dir = path
21 output, err := cmd.Output()
22 if err != nil {
23 return nil, fmt.Errorf("not a git repository")
24 }
25
26 gitDir := strings.TrimSpace(string(output))
27 if !filepath.IsAbs(gitDir) {
28 gitDir = filepath.Join(path, gitDir)
29 }
30
31 workTreeCmd := exec.Command("git", "rev-parse", "--show-toplevel")
32 workTreeCmd.Dir = path
33 workTreeOutput, err := workTreeCmd.Output()
34 if err != nil {
35 return nil, fmt.Errorf("could not determine work tree: %v", err)
36 }
37
38 workTree := strings.TrimSpace(string(workTreeOutput))
39
40 return &Repository{
41 gitDir: gitDir,
42 workTree: workTree,
43 }, nil
44}
45
46func (r *Repository) GitDir() string {
47 return r.gitDir

Callers 4

mainFunction · 0.92
TestNewRepositoryFunction · 0.85
TestGetConfigBoolFunction · 0.85
TestIsInitialCommitFunction · 0.85

Calls

no outgoing calls

Tested by 3

TestNewRepositoryFunction · 0.68
TestGetConfigBoolFunction · 0.68
TestIsInitialCommitFunction · 0.68