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
5 changes: 3 additions & 2 deletions CHANGELOG.md
Expand Up @@ -6,20 +6,21 @@

### Fixes

- `[jest-changed-files]` Change method of obtaining git root ([#8052](https://github.com/facebook/jest/pull/8052))
- `[jest-each]` Fix test function type ([#8145](https://github.com/facebook/jest/pull/8145))
- `[pretty-format]` Print `BigInt` as a readable number instead of `{}` ([#8138](https://github.com/facebook/jest/pull/8138))
- `[jest-fake-timers]` `getTimerCount` not taking immediates and ticks into account ([#8139](https://github.com/facebook/jest/pull/8139))
- `[jest-worker]` Move from `process.exit` to `exit` ([#7327](https://github.com/facebook/jest/pull/7327))
- `[pretty-format]` Print `BigInt` as a readable number instead of `{}` ([#8138](https://github.com/facebook/jest/pull/8138))

### Chore & Maintenance

- `[*]` Remove flow from code base ([#8061](https://github.com/facebook/jest/pull/8061))
- `[*]` Use property initializer syntax in Jest codebase ([#8117](https://github.com/facebook/jest/pull/8117))
- `[docs]` Improve description of optional arguments in ExpectAPI.md ([#8126](https://github.com/facebook/jest/pull/8126)
- `[*]` Move @types/node to the root package.json [#8129](https://github.com/facebook/jest/pull/8129))
- `[*]` Add documentation and tests related to auto-mocking ([#8099](https://github.com/facebook/jest/pull/8099))
- `[*]` Add `jest-watch-typeahead` as a devDependency ([#6449](https://github.com/facebook/jest/pull/6449))
- `[*]` upgrade TS to 3.4.0-dev\* for inceremental builds ([#8149](https://github.com/facebook/jest/pull/8149))
- `[docs]` Improve description of optional arguments in ExpectAPI.md ([#8126](https://github.com/facebook/jest/pull/8126)

### Performance

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.resolve(cwd, result.stdout);
} catch (e) {
return null;
}
Expand Down