Skip to content

Commit

Permalink
Include unstaged changes in affected
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasLYang committed Sep 10, 2024
1 parent c84638a commit 1426755
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 7 deletions.
6 changes: 5 additions & 1 deletion crates/turborepo-scm/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,20 @@ impl Git {
} else {
let output =
self.execute_git_command(&["diff", "--name-only", valid_from], pathspec)?;

self.add_files_from_stdout(&mut files, turbo_root, output);
}

// We only care about non-tracked files if we haven't specified both ends up the
// comparison or if we are using `--affected`
if include_uncommitted {
// Add untracked files, i.e. files that are not in git at all
let output = self
.execute_git_command(&["ls-files", "--others", "--exclude-standard"], pathspec)?;
self.add_files_from_stdout(&mut files, turbo_root, output);

// Then add files that are in git, but have been modified (but not committed)
let output = self.execute_git_command(&["diff", "--name-only", "HEAD"], pathspec)?;
self.add_files_from_stdout(&mut files, turbo_root, output);
}

Ok(files)
Expand Down
65 changes: 59 additions & 6 deletions turborepo-tests/integration/tests/affected.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,68 @@ Create a new branch
$ git checkout -b my-branch
Switched to a new branch 'my-branch'

Edit a file that affects `my-app`
$ echo "foo" >> apps/my-app/index.js
Ensure that nothing is affected
$ ${TURBO} ls --affected
WARNING ls command is experimental and may change in the future
0 no packages (npm)


Create a new file that affects `my-app`
$ echo "foo" > apps/my-app/new.js

Validate that we only run `my-app#build` with change not committed
$ ${TURBO} run build --affected --log-order grouped
\xe2\x80\xa2 Packages in scope: my-app (esc)
\xe2\x80\xa2 Running build in 1 packages (esc)
\xe2\x80\xa2 Remote caching disabled (esc)
my-app:build: cache miss, executing 1b83c3b24476ec9c
my-app:build:
my-app:build: > build
my-app:build: > echo building
my-app:build:
my-app:build: building

Tasks: 1 successful, 1 total
Cached: 0 cached, 1 total
Time:\s*[\.0-9]+m?s (re)



Do the same thing with the `ls` command
$ ${TURBO} ls --affected
WARNING ls command is experimental and may change in the future
1 package (npm)

my-app apps[\/\\]my-app (re)



Do the same thing with the `query` command
$ ${TURBO} query "query { affectedPackages { name } }"
WARNING query command is experimental and may change in the future
{
"data": {
"affectedPackages": [
{
"name": "my-app"
}
]
}
}


Remove the new file
$ rm apps/my-app/new.js

Add field to `apps/my-app/package.json`
$ jq '. += {"description": "foo"}' apps/my-app/package.json > apps/my-app/package.json.new

Validate that we only run `my-app#build` with change not committed
$ ${TURBO} run build --affected --log-order grouped
\xe2\x80\xa2 Packages in scope: my-app (esc)
\xe2\x80\xa2 Running build in 1 packages (esc)
\xe2\x80\xa2 Remote caching disabled (esc)
my-app:build: cache miss, executing 97b34acb6e848096
my-app:build: cache miss, executing 3e9d077cf0ab92e5
my-app:build:
my-app:build: > build
my-app:build: > echo building
Expand Down Expand Up @@ -55,7 +108,7 @@ Validate that we only run `my-app#build` with change committed
\xe2\x80\xa2 Packages in scope: my-app (esc)
\xe2\x80\xa2 Running build in 1 packages (esc)
\xe2\x80\xa2 Remote caching disabled (esc)
my-app:build: cache hit, replaying logs 97b34acb6e848096
my-app:build: cache hit, replaying logs 3e9d077cf0ab92e5
my-app:build:
my-app:build: > build
my-app:build: > echo building
Expand Down Expand Up @@ -159,7 +212,7 @@ Run the build and expect only `my-app` to be affected, since between
\xe2\x80\xa2 Packages in scope: my-app (esc)
\xe2\x80\xa2 Running build in 1 packages (esc)
\xe2\x80\xa2 Remote caching disabled (esc)
my-app:build: cache hit, replaying logs 97b34acb6e848096
my-app:build: cache hit, replaying logs 3e9d077cf0ab92e5
my-app:build:
my-app:build: > build
my-app:build: > echo building
Expand Down Expand Up @@ -205,7 +258,7 @@ Now try running `--affected` again, we should run all tasks
\xe2\x80\xa2 Packages in scope: //, another, my-app, util (esc)
\xe2\x80\xa2 Running build in 4 packages (esc)
\xe2\x80\xa2 Remote caching disabled (esc)
my-app:build: cache hit, replaying logs 97b34acb6e848096
my-app:build: cache hit, replaying logs 3e9d077cf0ab92e5
my-app:build:
my-app:build: > build
my-app:build: > echo building
Expand Down

0 comments on commit 1426755

Please sign in to comment.