Skip to content
Closed
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
8 changes: 8 additions & 0 deletions packages/sandbox/daemon-go/internal/config/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func validateGit(git *GitConfig) string {
return fmt.Sprintf("git.repository.branch invalid: %s", b)
}
}
seenRepoNames := make(map[string]bool, len(git.Repositories))
for i, repo := range git.Repositories {
if repo.CloneUrl == nil || *repo.CloneUrl == "" {
return fmt.Sprintf("git.repositories[%d].cloneUrl is required", i)
Expand All @@ -89,6 +90,13 @@ func validateGit(git *GitConfig) string {
if repo.RepoName == nil || !repoNameRe.MatchString(*repo.RepoName) {
return fmt.Sprintf("git.repositories[%d].repoName invalid", i)
}
// Two repos resolving to the same directory would clone concurrently
// into it (cloneSecondaryRepos fans out before any dir exists to skip
// on), corrupting both checkouts.
if seenRepoNames[*repo.RepoName] {
return fmt.Sprintf("git.repositories[%d].repoName duplicates another entry: %s", i, *repo.RepoName)
}
seenRepoNames[*repo.RepoName] = true
if repo.Branch != nil {
b := *repo.Branch
if !IsSyntheticBranch(b) && (!branchRe.MatchString(b) || strings.HasPrefix(b, "-")) {
Expand Down
13 changes: 13 additions & 0 deletions packages/sandbox/daemon-go/internal/config/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,16 @@ func TestValidateApplicationRejectsEscapingPmPath(t *testing.T) {
t.Fatal("validateApplication accepted a packageManager.path that escapes the repo root")
}
}

func TestValidateGitRejectsDuplicateSecondaryRepoNames(t *testing.T) {
git := &GitConfig{
Repository: &GitRepository{CloneUrl: Str("https://example.com/primary.git")},
Repositories: []GitRepository{
{CloneUrl: Str("https://example.com/a.git"), RepoName: Str("storefront")},
{CloneUrl: Str("https://example.com/b.git"), RepoName: Str("storefront")},
},
}
if reason := validateGit(git); reason == "" {
t.Fatal("validateGit accepted two secondary repositories with the same repoName, which resolve to the same clone directory")
}
}
Loading