Skip to content

Commit 1426755

Browse files
committed
Include unstaged changes in affected
1 parent c84638a commit 1426755

File tree

2 files changed

+64
-7
lines changed

2 files changed

+64
-7
lines changed

crates/turborepo-scm/src/git.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,20 @@ impl Git {
132132
} else {
133133
let output =
134134
self.execute_git_command(&["diff", "--name-only", valid_from], pathspec)?;
135-
136135
self.add_files_from_stdout(&mut files, turbo_root, output);
137136
}
138137

139138
// We only care about non-tracked files if we haven't specified both ends up the
140139
// comparison or if we are using `--affected`
141140
if include_uncommitted {
141+
// Add untracked files, i.e. files that are not in git at all
142142
let output = self
143143
.execute_git_command(&["ls-files", "--others", "--exclude-standard"], pathspec)?;
144144
self.add_files_from_stdout(&mut files, turbo_root, output);
145+
146+
// Then add files that are in git, but have been modified (but not committed)
147+
let output = self.execute_git_command(&["diff", "--name-only", "HEAD"], pathspec)?;
148+
self.add_files_from_stdout(&mut files, turbo_root, output);
145149
}
146150

147151
Ok(files)

turborepo-tests/integration/tests/affected.t

+59-6
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,68 @@ Create a new branch
55
$ git checkout -b my-branch
66
Switched to a new branch 'my-branch'
77

8-
Edit a file that affects `my-app`
9-
$ echo "foo" >> apps/my-app/index.js
8+
Ensure that nothing is affected
9+
$ ${TURBO} ls --affected
10+
WARNING ls command is experimental and may change in the future
11+
0 no packages (npm)
12+
13+
14+
Create a new file that affects `my-app`
15+
$ echo "foo" > apps/my-app/new.js
16+
17+
Validate that we only run `my-app#build` with change not committed
18+
$ ${TURBO} run build --affected --log-order grouped
19+
\xe2\x80\xa2 Packages in scope: my-app (esc)
20+
\xe2\x80\xa2 Running build in 1 packages (esc)
21+
\xe2\x80\xa2 Remote caching disabled (esc)
22+
my-app:build: cache miss, executing 1b83c3b24476ec9c
23+
my-app:build:
24+
my-app:build: > build
25+
my-app:build: > echo building
26+
my-app:build:
27+
my-app:build: building
28+
29+
Tasks: 1 successful, 1 total
30+
Cached: 0 cached, 1 total
31+
Time:\s*[\.0-9]+m?s (re)
32+
33+
34+
35+
Do the same thing with the `ls` command
36+
$ ${TURBO} ls --affected
37+
WARNING ls command is experimental and may change in the future
38+
1 package (npm)
39+
40+
my-app apps[\/\\]my-app (re)
41+
42+
43+
44+
Do the same thing with the `query` command
45+
$ ${TURBO} query "query { affectedPackages { name } }"
46+
WARNING query command is experimental and may change in the future
47+
{
48+
"data": {
49+
"affectedPackages": [
50+
{
51+
"name": "my-app"
52+
}
53+
]
54+
}
55+
}
56+
57+
58+
Remove the new file
59+
$ rm apps/my-app/new.js
60+
61+
Add field to `apps/my-app/package.json`
62+
$ jq '. += {"description": "foo"}' apps/my-app/package.json > apps/my-app/package.json.new
1063

1164
Validate that we only run `my-app#build` with change not committed
1265
$ ${TURBO} run build --affected --log-order grouped
1366
\xe2\x80\xa2 Packages in scope: my-app (esc)
1467
\xe2\x80\xa2 Running build in 1 packages (esc)
1568
\xe2\x80\xa2 Remote caching disabled (esc)
16-
my-app:build: cache miss, executing 97b34acb6e848096
69+
my-app:build: cache miss, executing 3e9d077cf0ab92e5
1770
my-app:build:
1871
my-app:build: > build
1972
my-app:build: > echo building
@@ -55,7 +108,7 @@ Validate that we only run `my-app#build` with change committed
55108
\xe2\x80\xa2 Packages in scope: my-app (esc)
56109
\xe2\x80\xa2 Running build in 1 packages (esc)
57110
\xe2\x80\xa2 Remote caching disabled (esc)
58-
my-app:build: cache hit, replaying logs 97b34acb6e848096
111+
my-app:build: cache hit, replaying logs 3e9d077cf0ab92e5
59112
my-app:build:
60113
my-app:build: > build
61114
my-app:build: > echo building
@@ -159,7 +212,7 @@ Run the build and expect only `my-app` to be affected, since between
159212
\xe2\x80\xa2 Packages in scope: my-app (esc)
160213
\xe2\x80\xa2 Running build in 1 packages (esc)
161214
\xe2\x80\xa2 Remote caching disabled (esc)
162-
my-app:build: cache hit, replaying logs 97b34acb6e848096
215+
my-app:build: cache hit, replaying logs 3e9d077cf0ab92e5
163216
my-app:build:
164217
my-app:build: > build
165218
my-app:build: > echo building
@@ -205,7 +258,7 @@ Now try running `--affected` again, we should run all tasks
205258
\xe2\x80\xa2 Packages in scope: //, another, my-app, util (esc)
206259
\xe2\x80\xa2 Running build in 4 packages (esc)
207260
\xe2\x80\xa2 Remote caching disabled (esc)
208-
my-app:build: cache hit, replaying logs 97b34acb6e848096
261+
my-app:build: cache hit, replaying logs 3e9d077cf0ab92e5
209262
my-app:build:
210263
my-app:build: > build
211264
my-app:build: > echo building

0 commit comments

Comments
 (0)