File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
packages/angular_devkit/schematics/src/rules Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change 7
7
*/
8
8
import { normalize } from '@angular-devkit/core' ;
9
9
import { Rule } from '../engine/interface' ;
10
+ import { noop } from './base' ;
10
11
11
12
12
13
export function move ( from : string , to ?: string ) : Rule {
@@ -18,6 +19,10 @@ export function move(from: string, to?: string): Rule {
18
19
const fromPath = normalize ( '/' + from ) ;
19
20
const toPath = normalize ( '/' + to ) ;
20
21
22
+ if ( fromPath === toPath ) {
23
+ return noop ;
24
+ }
25
+
21
26
return tree => tree . visit ( path => {
22
27
if ( path . startsWith ( fromPath ) ) {
23
28
tree . rename ( path , toPath + '/' + path . substr ( fromPath . length ) ) ;
Original file line number Diff line number Diff line change @@ -48,4 +48,20 @@ describe('move', () => {
48
48
} )
49
49
. then ( done , done . fail ) ;
50
50
} ) ;
51
+
52
+ it ( 'becomes a noop with identical from and to' , done => {
53
+ const tree = new HostTree ( ) ;
54
+ tree . create ( 'a/b/file1' , 'hello world' ) ;
55
+ tree . create ( 'a/b/file2' , 'hello world' ) ;
56
+ tree . create ( 'a/c/file3' , 'hello world' ) ;
57
+
58
+ callRule ( move ( '' ) , observableOf ( tree ) , context )
59
+ . toPromise ( )
60
+ . then ( result => {
61
+ expect ( result . exists ( 'a/b/file1' ) ) . toBe ( true ) ;
62
+ expect ( result . exists ( 'a/b/file2' ) ) . toBe ( true ) ;
63
+ expect ( result . exists ( 'a/c/file3' ) ) . toBe ( true ) ;
64
+ } )
65
+ . then ( done , done . fail ) ;
66
+ } ) ;
51
67
} ) ;
You can’t perform that action at this time.
0 commit comments