Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions civisibility/utils/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,20 @@ func getGitVersion() (major int, minor int, patch int, err error) {
return gitVersionValue.major, gitVersionValue.minor, gitVersionValue.patch, gitVersionValue.err
}

// GetSourceRoot returns the absolute path to the git repository root
// (the result of `git rev-parse --show-toplevel`).
// Returns empty string if git is not available or the current directory is not in a git repo.
func GetSourceRoot() string {
if !isGitFound() {
return ""
}
out, err := execGitString("rev-parse", "--show-toplevel")
if err != nil {
return ""
}
return out
}

// getLocalGitData retrieves information about the local Git repository from the current HEAD.
// It gathers details such as the repository URL, current branch, latest commit SHA, author and committer details, and commit message.
//
Expand Down
14 changes: 13 additions & 1 deletion internal/runner/dd_test_optimization.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,26 @@ func (tr *TestRunner) PrepareTestOptimization(ctx context.Context) error {
discoveredTestsCount := len(discoveredTests)
skippableTestsCount := 0

// Compute subdirectory prefix once for all paths.
// When running from a monorepo subdirectory (e.g., "cd core && ddtest plan"),
// full discovery may return repo-root-relative paths (e.g., "core/spec/...").
// We normalize them to CWD-relative paths so workers can find the files.
subdirPrefix := getCwdSubdirPrefix()
if subdirPrefix != "" {
slog.Info("Running from subdirectory, will normalize repo-root-relative paths", "subdirPrefix", subdirPrefix)
}

tr.testFiles = make(map[string]int)
for _, test := range discoveredTests {
if !skippableTests[test.FQN()] {
slog.Debug("Test is not skipped", "test", test.FQN(), "sourceFile", test.SuiteSourceFile)
if test.SuiteSourceFile != "" {
// Normalize repo-root-relative path to CWD-relative path.
// No-op when running from repo root or when path doesn't match subdir prefix.
normalizedPath := normalizeTestFilePathWithPrefix(test.SuiteSourceFile, subdirPrefix)
// increment the number of tests in the file
// it should track the test suite's duration here in the future
tr.testFiles[test.SuiteSourceFile]++
tr.testFiles[normalizedPath]++
}
} else {
skippableTestsCount++
Expand Down
Loading
Loading