Skip to content

Commit ff91095

Browse files
brentvatneFacebook Github Bot 8
authored andcommitted
Fixes file change watcher to work with git submodules
Summary:When using git submodules the path to the submodule parent is returned rather than the submodule itself and this broke the watcher in my project For example: if we have `/Users/brent/monorepo` and `/Users/brent/monorepo/product-a`, when we run `jest --onlyChanged` it should search `/Users/brent/monorepo/product-a` but instead it would search `/Users/brent/monorepo/` because `/Users/brent/monorepo/.git/modules/product-a` is returned from `git rev-parse --git-dir` and `path.dirname` for that returns `/Users/brent/monorepo` You can probably come up with a cleaner solution using some node or git apis that I'm not aware of, just throwing this out there as one possible fix. Closes jestjs#832 Differential Revision: D3138457 fb-gh-sync-id: 136124a22acc1a921925c09c62d3f83648a27273 fbshipit-source-id: 136124a22acc1a921925c09c62d3f83648a27273
1 parent f11e70e commit ff91095

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/lib/git.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,14 @@ function findChangedFiles(cwd) {
4040
function isGitRepository(cwd) {
4141
return new Promise(resolve => {
4242
let stdout = '';
43-
const child = childProcess.spawn('git', ['rev-parse', '--git-dir'], {cwd});
43+
const child = childProcess.spawn(
44+
'git',
45+
['rev-parse', '--show-toplevel'],
46+
{cwd}
47+
);
4448
child.stdout.on('data', data => stdout += data);
4549
child.on('close',
46-
code => resolve(code === 0 ? path.dirname(stdout.trim()) : null)
50+
code => resolve(code === 0 ? stdout.trim() : null)
4751
);
4852
});
4953
}

0 commit comments

Comments
 (0)