Skip to content

Commit b5eb6e7

Browse files
committed
Fixing up and adding tests
1 parent c56285f commit b5eb6e7

File tree

4 files changed

+131
-27
lines changed

4 files changed

+131
-27
lines changed

crates/turborepo-lib/src/query/mod.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,26 +358,38 @@ impl RepositoryQuery {
358358
Ok(File::new(self.run.clone(), abs_path))
359359
}
360360

361+
/// Get the files that have changed between the `base` and `head` commits.
362+
///
363+
/// # Arguments
364+
///
365+
/// * `base`: Defaults to `main` or `master`
366+
/// * `head`: Defaults to `HEAD`
367+
/// * `include_uncommitted`: Defaults to `true` if `head` is not provided
368+
/// * `allow_unknown_objects`: Defaults to `false`
369+
/// * `merge_base`: Defaults to `true`
370+
///
371+
/// returns: Result<Array<File>, Error>
361372
async fn affected_files(
362373
&self,
363374
base: Option<String>,
364375
head: Option<String>,
365-
/// Defaults to true if `head` is not provided
366376
include_uncommitted: Option<bool>,
367-
/// Defaults to true
377+
allow_unknown_objects: Option<bool>,
368378
merge_base: Option<bool>,
369379
) -> Result<Array<File>, Error> {
370380
let base = base.as_deref();
371381
let head = head.as_deref();
372382
let include_uncommitted = include_uncommitted.unwrap_or_else(|| head.is_none());
373383
let merge_base = merge_base.unwrap_or(true);
384+
let allow_unknown_objects = allow_unknown_objects.unwrap_or(false);
385+
374386
let repo_root = self.run.repo_root();
375387
let change_result = self.run.scm().changed_files(
376388
repo_root,
377389
base,
378390
head,
379391
include_uncommitted,
380-
false,
392+
allow_unknown_objects,
381393
merge_base,
382394
)?;
383395

turborepo-tests/integration/tests/affected.t

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,21 @@ Do the same thing with the `query` command
5757
}
5858

5959
Also with `affectedFiles` in `turbo query`
60-
$ ${TURBO} query "query { affectedFiles(base: \"main\", head: \"HEAD\") { items { path } } }"
60+
$ ${TURBO} query "query { affectedFiles { items { path, affectedPackages { items { name } } } } }"
61+
WARNING query command is experimental and may change in the future
6162
{
6263
"data": {
6364
"affectedFiles": {
6465
"items": [
6566
{
66-
"path": "apps/my-app/new.js"
67+
"path": "apps/my-app/new.js",
68+
"affectedPackages": {
69+
"items": [
70+
{
71+
"name": "my-app"
72+
}
73+
]
74+
}
6775
}
6876
]
6977
}
@@ -118,13 +126,21 @@ Do the same thing with the `query` command
118126
}
119127

120128
Also with `affectedFiles` in `turbo query`
121-
$ ${TURBO} query "query { affectedFiles(base: \"main\", head: \"HEAD\") { items { path } } }"
129+
$ ${TURBO} query "query { affectedFiles { items { path, affectedPackages { items { name } } } } }"
130+
WARNING query command is experimental and may change in the future
122131
{
123132
"data": {
124133
"affectedFiles": {
125134
"items": [
126135
{
127-
"path": "apps/my-app/package.json"
136+
"path": "apps/my-app/package.json",
137+
"affectedPackages": {
138+
"items": [
139+
{
140+
"name": "my-app"
141+
}
142+
]
143+
}
128144
}
129145
]
130146
}
@@ -206,6 +222,17 @@ Do the same thing with the `query` command
206222
}
207223
}
208224
225+
Also with `affectedFiles` in `turbo query`
226+
$ ${TURBO} query "query { affectedFiles(base: \"HEAD\") { items { path, affectedPackages { items { name } } } } }"
227+
WARNING query command is experimental and may change in the future
228+
{
229+
"data": {
230+
"affectedFiles": {
231+
"items": []
232+
}
233+
}
234+
}
235+
209236
Override the SCM head to be main, so nothing runs
210237
$ TURBO_SCM_HEAD="main" ${TURBO} run build --affected --log-order grouped
211238
\xe2\x80\xa2 Packages in scope: (esc)
@@ -237,6 +264,17 @@ Do the same thing with the `query` command
237264
}
238265
}
239266
267+
Also with `affectedFiles` in `turbo query`
268+
$ ${TURBO} query "query { affectedFiles(head: \"main\") { items { path, affectedPackages { items { name } } } } }"
269+
WARNING query command is experimental and may change in the future
270+
{
271+
"data": {
272+
"affectedFiles": {
273+
"items": []
274+
}
275+
}
276+
}
277+
240278
Now add a commit to `main` so the merge base is different from `main`
241279
$ git checkout main --quiet
242280
$ echo "foo" >> packages/util/index.js
@@ -286,6 +324,28 @@ Do the same thing with the `query` command
286324
}
287325
}
288326
327+
Also with `affectedFiles` in `turbo query`
328+
$ ${TURBO} query "query { affectedFiles { items { path, affectedPackages { items { name } } } } }"
329+
WARNING query command is experimental and may change in the future
330+
{
331+
"data": {
332+
"affectedFiles": {
333+
"items": [
334+
{
335+
"path": "apps/my-app/package.json",
336+
"affectedPackages": {
337+
"items": [
338+
{
339+
"name": "my-app"
340+
}
341+
]
342+
}
343+
}
344+
]
345+
}
346+
}
347+
}
348+
289349
Now do some magic to change the repo to be shallow
290350
$ SHALLOW=$(git rev-parse --show-toplevel)/.git/shallow
291351
$ git rev-parse HEAD > "$SHALLOW"

turborepo-tests/integration/tests/command-query.t

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,5 +213,31 @@ Run the query
213213
{
214214
"data": {
215215
"version": "2.1.3-canary.2"
216+
},
217+
}
218+
219+
Query a file
220+
$ ${TURBO} query "query { file(path: \"apps/my-app/package.json\") { path, contents } }"
221+
WARNING query command is experimental and may change in the future
222+
{
223+
"data": {
224+
"file": {
225+
"path": "apps/my-app/package.json",
226+
"contents": "{\n \"name\": \"my-app\",\n \"scripts\": {\n \"build\": \"echo building\",\n \"maybefails\": \"exit 4\"\n },\n \"dependencies\": {\n \"util\": \"*\"\n }\n}\n"
227+
}
228+
}
229+
}
230+
231+
Get the file's package
232+
$ ${TURBO} query "query { file(path: \"apps/my-app/package.json\") { path, package { ... on Package { name } } } }"
233+
WARNING query command is experimental and may change in the future
234+
{
235+
"data": {
236+
"file": {
237+
"path": "apps/my-app/package.json",
238+
"package": {
239+
"name": "my-app"
240+
}
241+
}
216242
}
217243
}

turborepo-tests/integration/tests/turbo-trace.t

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,49 +11,55 @@ Setup
1111
}
1212
}
1313
14-
$ ${TURBO} query "query { file(path: \"main.ts\") { path, dependencies { path } } }"
14+
$ ${TURBO} query "query { file(path: \"main.ts\") { path, fileDependencies { items { path } } } }"
1515
WARNING query command is experimental and may change in the future
1616
{
1717
"data": {
1818
"file": {
1919
"path": "main.ts",
20-
"dependencies": [
21-
{
22-
"path": "button.tsx"
23-
},
24-
{
25-
"path": "foo.js"
26-
},
27-
{
28-
"path": "node_modules(\/|\\\\)repeat-string(\/|\\\\)index.js" (re)
29-
}
30-
]
20+
"fileDependencies": {
21+
"items": [
22+
{
23+
"path": "button.tsx"
24+
},
25+
{
26+
"path": "foo.js"
27+
},
28+
{
29+
"path": "node_modules(\/|\\\\)repeat-string(\/|\\\\)index.js" (re)
30+
}
31+
]
32+
}
3133
}
3234
}
3335
}
3436
35-
$ ${TURBO} query "query { file(path: \"button.tsx\") { path, dependencies { path } } }"
37+
$ ${TURBO} query "query { file(path: \"button.tsx\") { path, fileDependencies { items { path } } } }"
3638
WARNING query command is experimental and may change in the future
3739
{
3840
"data": {
3941
"file": {
4042
"path": "button.tsx",
41-
"dependencies": []
43+
"fileDependencies": {
44+
"items": []
45+
}
4246
}
4347
}
4448
}
4549
46-
$ ${TURBO} query "query { file(path: \"circular.ts\") { path, dependencies { path } } }"
50+
$ ${TURBO} query "query { file(path: \"circular.ts\") { path, fileDependencies { items { path } } } }"
4751
WARNING query command is experimental and may change in the future
4852
{
4953
"data": {
5054
"file": {
5155
"path": "circular.ts",
52-
"dependencies": [
53-
{
54-
"path": "circular2.ts"
55-
}
56-
]
56+
"fileDependencies": {
57+
"items": [
58+
{
59+
"path": "circular2.ts"
60+
}
61+
]
62+
}
5763
}
5864
}
5965
}

0 commit comments

Comments
 (0)