Skip to content

Commit

Permalink
fix(core): use file full path in git show
Browse files Browse the repository at this point in the history
Use file full path in git show to identify affected files to fix an issue when nx workspace is not at the root of git repository

Closes #2292
  • Loading branch information
jsaguet committed Feb 23, 2020
1 parent c508241 commit c3be5d6
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/workspace/src/core/file-utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as path from 'path';
import * as fs from 'fs';
import { appRootPath } from '../utils/app-root';
import { extname } from 'path';
import {extname, relative} from 'path';
import { jsonDiff } from '../utils/json-diff';
import { readFileSync } from 'fs';
import { execSync } from 'child_process';
Expand Down Expand Up @@ -89,9 +89,12 @@ function defaultReadFileAtRevision(
revision: void | string
): string {
try {
const fileFullPath = `${appRootPath}/${file}`;
const gitRepositoryPath = execSync('git rev-parse --show-toplevel').toString().trim();
const filePathInGitRepository = relative(gitRepositoryPath, fileFullPath);
return !revision
? readFileSync(file).toString()
: execSync(`git show ${revision}:${file}`, {
: execSync(`git show ${revision}:${filePathInGitRepository}`, {
maxBuffer: TEN_MEGABYTES
})
.toString()
Expand Down

0 comments on commit c3be5d6

Please sign in to comment.