MCPcopy Create free account
hub / github.com/LegacyCodeHQ/clarity-cli / ResolveFirstParent

Function ResolveFirstParent

vcs/git/git_ls_files.go:42–61  ·  view source on GitHub ↗

ResolveFirstParent resolves the first parent of a commit. Returns hasParent=false for root commits.

(repoPath, commitID string)

Source from the content-addressed store, hash-verified

40// ResolveFirstParent resolves the first parent of a commit.
41// Returns hasParent=false for root commits.
42func ResolveFirstParent(repoPath, commitID string) (parent string, hasParent bool, err error) {
43 if err := validateCommit(repoPath, commitID); err != nil {
44 return "", false, err
45 }
46
47 stdout, stderr, err := runGitCommand(repoPath, "rev-list", "--parents", "-n", "1", commitID)
48 if err != nil {
49 return "", false, gitCommandError(err, stderr)
50 }
51
52 fields := strings.Fields(strings.TrimSpace(string(stdout)))
53 if len(fields) < 1 {
54 return "", false, fmt.Errorf("unexpected git rev-list output for commit %s", commitID)
55 }
56 if len(fields) == 1 {
57 return "", false, nil
58 }
59
60 return fields[1], true, nil
61}
62
63func ensureRepoRoot(repoPath string) (string, error) {
64 if _, err := os.Stat(repoPath); os.IsNotExist(err) {

Callers 1

Calls 3

validateCommitFunction · 0.85
runGitCommandFunction · 0.85
gitCommandErrorFunction · 0.85

Tested by

no test coverage detected