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

Function isAncestor

vcs/git/git.go:149–166  ·  view source on GitHub ↗

isAncestor checks if possibleAncestor is an ancestor of possibleDescendant. Returns true if possibleAncestor is older than (or equal to) possibleDescendant.

(repoPath, possibleAncestor, possibleDescendant string)

Source from the content-addressed store, hash-verified

147// isAncestor checks if possibleAncestor is an ancestor of possibleDescendant.
148// Returns true if possibleAncestor is older than (or equal to) possibleDescendant.
149func isAncestor(repoPath, possibleAncestor, possibleDescendant string) (bool, error) {
150 if err := validateGitRef(possibleAncestor); err != nil {
151 return false, err
152 }
153 if err := validateGitRef(possibleDescendant); err != nil {
154 return false, err
155 }
156
157 _, _, err := runGitCommand(repoPath, "merge-base", "--is-ancestor", possibleAncestor, possibleDescendant)
158 if err != nil {
159 // Exit code 1 means not an ancestor, which is not an error for our purposes
160 if exitErr, ok := err.(*exec.ExitError); ok && exitErr.ExitCode() == 1 {
161 return false, nil
162 }
163 return false, err
164 }
165 return true, nil
166}
167
168// NormalizeCommitRange ensures commits are in chronological order (older first).
169// If the commits are reversed (newer...older), it swaps them.

Callers 4

NormalizeCommitRangeFunction · 0.85
TestIsAncestor_TrueFunction · 0.85
TestIsAncestor_FalseFunction · 0.85

Calls 2

validateGitRefFunction · 0.85
runGitCommandFunction · 0.85

Tested by 3

TestIsAncestor_TrueFunction · 0.68
TestIsAncestor_FalseFunction · 0.68