Skip to content

Commit

Permalink
fix(@angular/cli): Determine relative paths correctly
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
msbit authored and vikerman committed Oct 17, 2019
1 parent 1713e63 commit f8c515e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/angular/cli/commands/update-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ export class UpdateCommand extends SchematicCommand<UpdateCommandSchema> {

checkCleanGit() {
try {
const topLevel = execSync('git rev-parse --show-toplevel', { encoding: 'utf8', stdio: 'pipe' });
const result = execSync('git status --porcelain', { encoding: 'utf8', stdio: 'pipe' });
if (result.trim().length === 0) {
return true;
Expand All @@ -368,7 +369,7 @@ export class UpdateCommand extends SchematicCommand<UpdateCommandSchema> {
for (const entry of result.split('\n')) {
const relativeEntry = path.relative(
path.resolve(this.workspace.root),
path.resolve(entry.slice(3).trim()),
path.resolve(topLevel.trim(), entry.slice(3).trim()),
);

if (!relativeEntry.startsWith('..') && !path.isAbsolute(relativeEntry)) {
Expand Down
26 changes: 26 additions & 0 deletions tests/legacy-cli/e2e/tests/misc/update-git-clean-subdirectory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { createDir, writeFile } from '../../utils/fs';
import { expectToFail } from '../../utils/utils';
import { getGlobalVariable } from '../../utils/env';
import { ng, silentGit } from '../../utils/process';
import { prepareProjectForE2e } from '../../utils/project'

export default async function() {
process.chdir(getGlobalVariable('tmp-root'));

await createDir('./subdirectory');
process.chdir('./subdirectory');

await silentGit('init', '.');

await ng('new', 'subdirectory-test-project', '--skip-install');
process.chdir('./subdirectory-test-project');
await prepareProjectForE2e('subdirectory-test-project');

await writeFile('../added.ts', 'console.log(\'created\');\n');
await silentGit('add', '../added.ts');

const { message } = await expectToFail(() => ng('update', '--all'));
if (message && message.includes('Repository is not clean.')) {
throw new Error('Expected clean repository');
}
}

0 comments on commit f8c515e

Please sign in to comment.