diff --git a/packages/angular_devkit/schematics/src/rules/move.ts b/packages/angular_devkit/schematics/src/rules/move.ts index b22e29b7cd..96cfe15737 100644 --- a/packages/angular_devkit/schematics/src/rules/move.ts +++ b/packages/angular_devkit/schematics/src/rules/move.ts @@ -7,6 +7,7 @@ */ import { normalize } from '@angular-devkit/core'; import { Rule } from '../engine/interface'; +import { noop } from './base'; export function move(from: string, to?: string): Rule { @@ -18,6 +19,10 @@ export function move(from: string, to?: string): Rule { const fromPath = normalize('/' + from); const toPath = normalize('/' + to); + if (fromPath === toPath) { + return noop; + } + return tree => tree.visit(path => { if (path.startsWith(fromPath)) { tree.rename(path, toPath + '/' + path.substr(fromPath.length)); diff --git a/packages/angular_devkit/schematics/src/rules/move_spec.ts b/packages/angular_devkit/schematics/src/rules/move_spec.ts index 113e90769f..c9c67a23b3 100644 --- a/packages/angular_devkit/schematics/src/rules/move_spec.ts +++ b/packages/angular_devkit/schematics/src/rules/move_spec.ts @@ -48,4 +48,20 @@ describe('move', () => { }) .then(done, done.fail); }); + + it('becomes a noop with identical from and to', done => { + const tree = new HostTree(); + tree.create('a/b/file1', 'hello world'); + tree.create('a/b/file2', 'hello world'); + tree.create('a/c/file3', 'hello world'); + + callRule(move(''), observableOf(tree), context) + .toPromise() + .then(result => { + expect(result.exists('a/b/file1')).toBe(true); + expect(result.exists('a/b/file2')).toBe(true); + expect(result.exists('a/c/file3')).toBe(true); + }) + .then(done, done.fail); + }); });