Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change method of obtaining git root (#3214) #8052

Merged
merged 9 commits into from Mar 19, 2019
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -34,6 +34,7 @@
- `[jest-circus]`: Throw explicit error when errors happen after test is considered complete ([#8005](https://github.com/facebook/jest/pull/8005))
- `[expect]` Remove duck typing and obsolete browser support code when comparing DOM nodes and use DOM-Level-3 API instead ([#7995](https://github.com/facebook/jest/pull/7995))
- `[jest-mock]` Adds a type check to `prototype` to allow mocks of objects with a primitive `prototype` property. ([#8040](https://github.com/facebook/jest/pull/8040))
- `[jest-changed-files]` Change method of obtaining git root (fixes #3214) ([#8052](https://github.com/facebook/jest/pull/8052))
- `[jest-util]`Make sure to not fail if unable to assign `toStringTag` to the `process` object, which is read only in Node 12 ([#8050](https://github.com/facebook/jest/pull/8050))
- `[expect]` Revert change to distinguish undefined value from no property ([#8067](https://github.com/facebook/jest/pull/8067))

Expand Down
12 changes: 6 additions & 6 deletions e2e/__tests__/jestChangedFiles.test.ts
Expand Up @@ -54,8 +54,8 @@ test('gets hg SCM roots and dedups them', async () => {
// NOTE: This test can break if you have a .hg repo initialized inside your
// os tmp directory.
expect(hgRepos).toHaveLength(2);
expect(hgRepos[0]).toMatch(/\/jest-changed-files-test-dir\/first-repo$/);
expect(hgRepos[1]).toMatch(/\/jest-changed-files-test-dir\/second-repo$/);
expect(hgRepos[0]).toMatch(/\/jest-changed-files-test-dir\/first-repo\/?$/);
expect(hgRepos[1]).toMatch(/\/jest-changed-files-test-dir\/second-repo\/?$/);
});

test('gets git SCM roots and dedups them', async () => {
Expand Down Expand Up @@ -88,8 +88,8 @@ test('gets git SCM roots and dedups them', async () => {
// NOTE: This test can break if you have a .git repo initialized inside your
// os tmp directory.
expect(gitRepos).toHaveLength(2);
expect(gitRepos[0]).toMatch(/\/jest-changed-files-test-dir\/first-repo$/);
expect(gitRepos[1]).toMatch(/\/jest-changed-files-test-dir\/second-repo$/);
expect(gitRepos[0]).toMatch(/\/jest-changed-files-test-dir\/first-repo\/?$/);
expect(gitRepos[1]).toMatch(/\/jest-changed-files-test-dir\/second-repo\/?$/);
});

test('gets mixed git and hg SCM roots and dedups them', async () => {
Expand Down Expand Up @@ -121,8 +121,8 @@ test('gets mixed git and hg SCM roots and dedups them', async () => {
// inside your os tmp directory.
expect(gitRepos).toHaveLength(1);
expect(hgRepos).toHaveLength(1);
expect(gitRepos[0]).toMatch(/\/jest-changed-files-test-dir\/first-repo$/);
expect(hgRepos[0]).toMatch(/\/jest-changed-files-test-dir\/second-repo$/);
expect(gitRepos[0]).toMatch(/\/jest-changed-files-test-dir\/first-repo\/?$/);
expect(hgRepos[0]).toMatch(/\/jest-changed-files-test-dir\/second-repo\/?$/);
});

test('gets changed files for git', async () => {
Expand Down
10 changes: 6 additions & 4 deletions packages/jest-changed-files/src/git.ts
Expand Up @@ -29,8 +29,10 @@ const adapter: SCMAdapter = {
const changedSince: string | undefined =
options && (options.withAncestor ? 'HEAD^' : options.changedSince);

const includePaths: Array<Config.Path> =
(options && options.includePaths) || [];
const includePaths: Array<Config.Path> = (
(options && options.includePaths) ||
[]
).map(absoluteRoot => path.normalize(path.relative(cwd, absoluteRoot)));
SimenB marked this conversation as resolved.
Show resolved Hide resolved

if (options && options.lastCommit) {
return findChangedFilesUsingCommand(
Expand Down Expand Up @@ -72,12 +74,12 @@ const adapter: SCMAdapter = {
},

getRoot: async cwd => {
const options = ['rev-parse', '--show-toplevel'];
const options = ['rev-parse', '--show-cdup'];

try {
const result = await execa('git', options, {cwd});

return result.stdout;
return path.join(cwd, result.stdout);
bwiercinski marked this conversation as resolved.
Show resolved Hide resolved
bwiercinski marked this conversation as resolved.
Show resolved Hide resolved
} catch (e) {
return null;
}
Expand Down