Skip to content

Commit eea180c

Browse files
authored
Backport fix for workspace globbing (#664)
See https://github.com/sourcegraph/sourcegraph/pull/28230 for more details.
1 parent 661611d commit eea180c

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ All notable changes to `src-cli` are documented in this file.
2121

2222
- Excess newlines in between outputs in logfiles written when `--keep-logs` is used have been fixed. [#665](https://github.com/sourcegraph/src-cli/pull/665)
2323
- `src` would sometimes panic when Ctrl-C was pressed while executing batch change steps due to a bug in the library used to render the execution progress bars. This has been fixed. [🤘 #666](https://github.com/sourcegraph/src-cli/pull/666)
24+
- In batch changes, when using `workspaces` src would incorrectly treat `in` not being set as _don't match anything_. This is fixed and it matches everything like `*`. [#664](https://github.com/sourcegraph/src-cli/pull/664)
2425

2526
### Removed
2627

internal/batches/service/workspaces.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,14 @@ func findWorkspaces(
4343
// Pre-compile all globs.
4444
workspaceMatchers := make(map[batcheslib.WorkspaceConfiguration]glob.Glob)
4545
for _, conf := range spec.Workspaces {
46-
g, err := glob.Compile(conf.In)
46+
in := conf.In
47+
// Empty `in` should fall back to matching all, instead of nothing.
48+
if in == "" {
49+
in = "*"
50+
}
51+
g, err := glob.Compile(in)
4752
if err != nil {
48-
return nil, batcheslib.NewValidationError(errors.Errorf("failed to compile glob %q: %v", conf.In, err))
53+
return nil, batcheslib.NewValidationError(errors.Errorf("failed to compile glob %q: %v", in, err))
4954
}
5055
workspaceMatchers[conf] = g
5156
}

internal/batches/service/workspaces_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,24 @@ func TestFindWorkspaces(t *testing.T) {
118118
{Repo: repos[2], Steps: steps, Path: "d/e/f", OnlyFetchWorkspace: true},
119119
},
120120
},
121+
"workspace configuration without 'in' matches all": {
122+
spec: &batcheslib.BatchSpec{
123+
Steps: steps,
124+
Workspaces: []batcheslib.WorkspaceConfiguration{
125+
{
126+
RootAtLocationOf: "package.json",
127+
},
128+
},
129+
},
130+
finderResults: finderResults{
131+
repos[0]: {"a/b"},
132+
repos[2]: {"a/b"},
133+
},
134+
wantWorkspaces: []RepoWorkspace{
135+
{Repo: repos[0], Steps: steps, Path: "a/b"},
136+
{Repo: repos[2], Steps: steps, Path: "a/b"},
137+
},
138+
},
121139
}
122140

123141
for name, tt := range tests {

0 commit comments

Comments
 (0)