Skip to content

Commit

Permalink
Change method of obtaining git root (#8052)
Browse files Browse the repository at this point in the history
  • Loading branch information
bwiercinski authored and SimenB committed Mar 19, 2019
1 parent ce65aac commit 31e10db
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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)));

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

0 comments on commit 31e10db

Please sign in to comment.