Skip to content

Commit

Permalink
fix(core): use file full path in git show (#2537)
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 authored and vsavkin committed Mar 10, 2020
1 parent 17418a8 commit 0a2d5be
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/workspace/src/core/file-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,17 @@ function defaultReadFileAtRevision(
revision: void | string
): string {
try {
const fileFullPath = `${appRootPath}${path.sep}${file}`;
const gitRepositoryPath = execSync('git rev-parse --show-toplevel')
.toString()
.trim();
const filePathInGitRepository = path
.relative(gitRepositoryPath, fileFullPath)
.split(path.sep)
.join('/');
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 0a2d5be

Please sign in to comment.