Skip to content

Commit af602c6

Browse files
committed
Download additional files on way up from workspace to root dir
1 parent ecd3c2d commit af602c6

2 files changed

Lines changed: 41 additions & 8 deletions

File tree

internal/campaigns/executor_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,12 @@ repository_name=github.com/sourcegraph/src-cli`,
299299
".gitignore": "node_modules",
300300
"message.txt": "root-dir",
301301
"a/message.txt": "a-dir",
302+
"a/.gitignore": "node_modules-in-a",
302303
"a/b/message.txt": "b-dir",
303304
}},
304305
{repo: srcCLIRepo, path: "a", files: map[string]string{
305306
"a/message.txt": "a-dir",
307+
"a/.gitignore": "node_modules-in-a",
306308
"a/b/message.txt": "b-dir",
307309
}},
308310
{repo: srcCLIRepo, path: "a/b", files: map[string]string{
@@ -311,7 +313,8 @@ repository_name=github.com/sourcegraph/src-cli`,
311313
},
312314
additionalFiles: []mockRepoAdditionalFiles{
313315
{repo: srcCLIRepo, additionalFiles: map[string]string{
314-
".gitignore": "node_modules",
316+
".gitignore": "node_modules",
317+
"a/.gitignore": "node_modules-in-a",
315318
}},
316319
},
317320
steps: []Step{
@@ -332,10 +335,15 @@ repository_name=github.com/sourcegraph/src-cli`,
332335
Run: `if [[ $(basename $(pwd)) == "a" && -f "../.gitignore" ]]; then echo "yes" >> gitignore-exists; fi`,
333336
Container: "doesntmatter:13",
334337
},
338+
// In `a/b` we want the `.gitignore` file in the root folder and in `a` to be fetched:
335339
{
336340
Run: `if [[ $(basename $(pwd)) == "b" && -f "../../.gitignore" ]]; then echo "yes" >> gitignore-exists; fi`,
337341
Container: "doesntmatter:13",
338342
},
343+
{
344+
Run: `if [[ $(basename $(pwd)) == "b" && -f "../.gitignore" ]]; then echo "yes" >> gitignore-exists-in-a; fi`,
345+
Container: "doesntmatter:13",
346+
},
339347
},
340348
tasks: []*Task{
341349
{
@@ -361,7 +369,7 @@ repository_name=github.com/sourcegraph/src-cli`,
361369
srcCLIRepo.ID: filesByBranch{
362370
"workspace-root-dir": []string{"hello.txt", "gitignore-exists"},
363371
"workspace-a-dir": []string{"a/hello.txt", "a/gitignore-exists"},
364-
"workspace-b-dir": []string{"a/b/hello.txt", "a/b/gitignore-exists"},
372+
"workspace-b-dir": []string{"a/b/hello.txt", "a/b/gitignore-exists", "a/b/gitignore-exists-in-a"},
365373
},
366374
},
367375
},

internal/campaigns/repo_fetcher.go

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,37 @@ func (rf *repoFetcher) zipFor(repo *graphql.Repository, path string) *repoZip {
7373
}
7474

7575
if path != "" {
76-
for _, name := range []string{".gitignore", ".gitattributes"} {
77-
zip.additionalFiles = append(zip.additionalFiles, &additionalFile{
78-
filename: name,
79-
localPath: filepath.Join(rf.dir, slug+"-"+name),
80-
fetched: false,
81-
})
76+
// We're doing another loop here to catch all
77+
// AdditionalWorkspaceFiles on the way *up* from the workspace to the
78+
// root.
79+
//
80+
// Example: path = /examples/cool/project3
81+
//
82+
// Then we want to fetch the following files:
83+
//
84+
// /.gitignore
85+
// /.gitattributes
86+
// /examples/.gitignore
87+
// /examples/.gitattributes
88+
// /examples/cool/.gitignore
89+
// /examples/cool/.gitattributes
90+
91+
pathComponents := strings.Split(path, string(os.PathSeparator))
92+
93+
var currentPath string
94+
for _, component := range pathComponents {
95+
for _, name := range []string{".gitignore", ".gitattributes"} {
96+
filename := filepath.Join(currentPath, name)
97+
localPath := filepath.Join(rf.dir, repo.SlugForPath(filename))
98+
99+
zip.additionalFiles = append(zip.additionalFiles, &additionalFile{
100+
filename: filename,
101+
localPath: localPath,
102+
fetched: false,
103+
})
104+
}
105+
106+
currentPath = filepath.Join(currentPath, component)
82107
}
83108
}
84109

0 commit comments

Comments
 (0)