Skip to content

Commit 6c6ae08

Browse files
msbitvikerman
authored andcommitted
fix(@angular/cli): Determine relative paths correctly
As `git status --porcelain` always shows paths relative to the top level, fetch the top level path in `checkCleanGit` and properly determine whether any modified files are actually within the Angular workspace root.
1 parent ab70e61 commit 6c6ae08

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

packages/angular/cli/commands/update-impl.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {
551551

552552
checkCleanGit() {
553553
try {
554+
const topLevel = execSync('git rev-parse --show-toplevel', { encoding: 'utf8', stdio: 'pipe' });
554555
const result = execSync('git status --porcelain', { encoding: 'utf8', stdio: 'pipe' });
555556
if (result.trim().length === 0) {
556557
return true;
@@ -560,7 +561,7 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {
560561
for (const entry of result.split('\n')) {
561562
const relativeEntry = path.relative(
562563
path.resolve(this.workspace.root),
563-
path.resolve(entry.slice(3).trim()),
564+
path.resolve(topLevel.trim(), entry.slice(3).trim()),
564565
);
565566

566567
if (!relativeEntry.startsWith('..') && !path.isAbsolute(relativeEntry)) {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { createDir, writeFile } from '../../utils/fs';
2+
import { expectToFail } from '../../utils/utils';
3+
import { getGlobalVariable } from '../../utils/env';
4+
import { ng, silentGit } from '../../utils/process';
5+
import { prepareProjectForE2e } from '../../utils/project'
6+
7+
export default async function() {
8+
process.chdir(getGlobalVariable('tmp-root'));
9+
10+
await createDir('./subdirectory');
11+
process.chdir('./subdirectory');
12+
13+
await silentGit('init', '.');
14+
15+
await ng('new', 'subdirectory-test-project', '--skip-install');
16+
process.chdir('./subdirectory-test-project');
17+
await prepareProjectForE2e('subdirectory-test-project');
18+
19+
await writeFile('../added.ts', 'console.log(\'created\');\n');
20+
await silentGit('add', '../added.ts');
21+
22+
const { message } = await expectToFail(() => ng('update', '--all'));
23+
if (message && message.includes('Repository is not clean.')) {
24+
throw new Error('Expected clean repository');
25+
}
26+
}

0 commit comments

Comments
 (0)