File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -69,21 +69,14 @@ export class CommitSplit {
6969 newPath = newPath . replace ( / ^ \/ / , '' ) ;
7070 newPath = newPath . replace ( / $ / , '/' ) ;
7171 newPath = newPath . replace ( / ^ / , '/' ) ;
72- for ( let exPath of paths ) {
73- exPath = exPath . replace ( / $ / , '/' ) ;
74- exPath = exPath . replace ( / ^ / , '/' ) ;
75- if ( newPath . startsWith ( exPath ) || exPath . startsWith ( newPath ) ) {
76- throw new Error (
77- `Path prefixes must be unique: ${ newPath } , ${ exPath } `
78- ) ;
79- }
80- }
8172 // store them with leading and trailing slashes removed.
8273 newPath = newPath . replace ( / \/ $ / , '' ) ;
8374 newPath = newPath . replace ( / ^ \/ / , '' ) ;
8475 paths . push ( newPath ) ;
8576 }
86- this . packagePaths = paths ;
77+
78+ // sort by longest paths first
79+ this . packagePaths = paths . sort ( ( a , b ) => b . length - a . length ) ;
8780 }
8881 }
8982
Original file line number Diff line number Diff line change @@ -56,6 +56,26 @@ describe('CommitSplit', () => {
5656 expect ( splitCommits [ 'pkg5' ] ) . lengthOf ( 1 ) ;
5757 expect ( splitCommits [ 'pkg6/pkg5' ] ) . lengthOf ( 1 ) ;
5858 } ) ;
59+ it ( 'handles nested folders' , ( ) => {
60+ const commits : Commit [ ] = [
61+ {
62+ sha : 'abc123' ,
63+ message : 'commit abc123' ,
64+ files : [ 'core/foo.txt' , 'pkg2/bar.txt' ] ,
65+ } ,
66+ {
67+ sha : 'def234' ,
68+ message : 'commit def234' ,
69+ files : [ 'core/subpackage/foo2.txt' , 'pkg3/asdf.txt' ] ,
70+ } ,
71+ ] ;
72+ const commitSplit = new CommitSplit ( {
73+ packagePaths : [ 'core' , 'core/subpackage' ] ,
74+ } ) ;
75+ const splitCommits = commitSplit . split ( commits ) ;
76+ expect ( splitCommits [ 'core' ] ) . lengthOf ( 1 ) ;
77+ expect ( splitCommits [ 'core/subpackage' ] ) . lengthOf ( 1 ) ;
78+ } ) ;
5979 describe ( 'including empty commits' , ( ) => {
6080 it ( 'should separate commits' , ( ) => {
6181 const commitSplit = new CommitSplit ( {
You can’t perform that action at this time.
0 commit comments