@@ -45,102 +45,91 @@ export async function getChangedFiles(options = {}) {
45
45
*/
46
46
export async function getChangedFilesStatuses ( options = { } ) {
47
47
const { baseCommitish = "HEAD^" , cwd, headCommitish = "HEAD" , logger } = options ;
48
- try {
49
- const result = await simpleGit ( cwd ) . diff ( [ "--name-status" , baseCommitish , headCommitish ] ) ;
50
-
51
- const categorizedFiles = {
52
- additions : /** @type {string[] } */ ( [ ] ) ,
53
- modifications : /** @type {string[] } */ ( [ ] ) ,
54
- deletions : /** @type {string[] } */ ( [ ] ) ,
55
- renames : /** @type {{from: string, to: string}[] } */ ( [ ] ) ,
56
- total : 0 ,
57
- } ;
58
-
59
- if ( result . trim ( ) ) {
60
- const lines = result . trim ( ) . split ( "\n" ) ;
61
-
62
- for ( const line of lines ) {
63
- const parts = line . split ( "\t" ) ;
64
- const status = parts [ 0 ] ;
65
-
66
- switch ( status [ 0 ] ) {
67
- case "A" :
68
- categorizedFiles . additions . push ( parts [ 1 ] ) ;
69
- break ;
70
- case "M" :
71
- categorizedFiles . modifications . push ( parts [ 1 ] ) ;
72
- break ;
73
- case "D" :
74
- categorizedFiles . deletions . push ( parts [ 1 ] ) ;
75
- break ;
76
- case "R" :
77
- categorizedFiles . renames . push ( {
78
- from : parts [ 1 ] ,
79
- to : parts [ 2 ] ,
80
- } ) ;
81
- break ;
82
- case "C" :
83
- categorizedFiles . additions . push ( parts [ 2 ] ) ;
84
- break ;
85
- default :
86
- categorizedFiles . modifications . push ( parts [ 1 ] ) ;
87
- }
48
+ const result = await simpleGit ( cwd ) . diff ( [ "--name-status" , baseCommitish , headCommitish ] ) ;
49
+
50
+ const categorizedFiles = {
51
+ additions : /** @type {string[] } */ ( [ ] ) ,
52
+ modifications : /** @type {string[] } */ ( [ ] ) ,
53
+ deletions : /** @type {string[] } */ ( [ ] ) ,
54
+ renames : /** @type {{from: string, to: string}[] } */ ( [ ] ) ,
55
+ total : 0 ,
56
+ } ;
57
+
58
+ if ( result . trim ( ) ) {
59
+ const lines = result . trim ( ) . split ( "\n" ) ;
60
+
61
+ for ( const line of lines ) {
62
+ const parts = line . split ( "\t" ) ;
63
+ const status = parts [ 0 ] ;
64
+
65
+ switch ( status [ 0 ] ) {
66
+ case "A" :
67
+ categorizedFiles . additions . push ( parts [ 1 ] ) ;
68
+ break ;
69
+ case "M" :
70
+ categorizedFiles . modifications . push ( parts [ 1 ] ) ;
71
+ break ;
72
+ case "D" :
73
+ categorizedFiles . deletions . push ( parts [ 1 ] ) ;
74
+ break ;
75
+ case "R" :
76
+ categorizedFiles . renames . push ( {
77
+ from : parts [ 1 ] ,
78
+ to : parts [ 2 ] ,
79
+ } ) ;
80
+ break ;
81
+ case "C" :
82
+ categorizedFiles . additions . push ( parts [ 2 ] ) ;
83
+ break ;
84
+ default :
85
+ categorizedFiles . modifications . push ( parts [ 1 ] ) ;
88
86
}
89
-
90
- categorizedFiles . total =
91
- categorizedFiles . additions . length +
92
- categorizedFiles . modifications . length +
93
- categorizedFiles . deletions . length +
94
- categorizedFiles . renames . length ;
95
87
}
96
88
97
- // Log all changed files by categories
98
- if ( logger ) {
99
- logger . info ( "Categorized Changed Files:" ) ;
89
+ categorizedFiles . total =
90
+ categorizedFiles . additions . length +
91
+ categorizedFiles . modifications . length +
92
+ categorizedFiles . deletions . length +
93
+ categorizedFiles . renames . length ;
94
+ }
100
95
101
- if ( categorizedFiles . additions . length > 0 ) {
102
- logger . info ( ` Additions (${ categorizedFiles . additions . length } ):` ) ;
103
- for ( const file of categorizedFiles . additions ) {
104
- logger . info ( ` + ${ file } ` ) ;
105
- }
106
- }
96
+ // Log all changed files by categories
97
+ if ( logger ) {
98
+ logger . info ( "Categorized Changed Files:" ) ;
107
99
108
- if ( categorizedFiles . modifications . length > 0 ) {
109
- logger . info ( ` Modifications (${ categorizedFiles . modifications . length } ):` ) ;
110
- for ( const file of categorizedFiles . modifications ) {
111
- logger . info ( ` M ${ file } ` ) ;
112
- }
100
+ if ( categorizedFiles . additions . length > 0 ) {
101
+ logger . info ( ` Additions (${ categorizedFiles . additions . length } ):` ) ;
102
+ for ( const file of categorizedFiles . additions ) {
103
+ logger . info ( ` + ${ file } ` ) ;
113
104
}
105
+ }
114
106
115
- if ( categorizedFiles . deletions . length > 0 ) {
116
- logger . info ( ` Deletions (${ categorizedFiles . deletions . length } ):` ) ;
117
- for ( const file of categorizedFiles . deletions ) {
118
- logger . info ( ` - ${ file } ` ) ;
119
- }
107
+ if ( categorizedFiles . modifications . length > 0 ) {
108
+ logger . info ( ` Modifications (${ categorizedFiles . modifications . length } ):` ) ;
109
+ for ( const file of categorizedFiles . modifications ) {
110
+ logger . info ( ` M ${ file } ` ) ;
120
111
}
112
+ }
121
113
122
- if ( categorizedFiles . renames . length > 0 ) {
123
- logger . info ( ` Renames (${ categorizedFiles . renames . length } ):` ) ;
124
- for ( const rename of categorizedFiles . renames ) {
125
- logger . info ( ` R ${ rename . from } -> ${ rename . to } ` ) ;
126
- }
114
+ if ( categorizedFiles . deletions . length > 0 ) {
115
+ logger . info ( ` Deletions (${ categorizedFiles . deletions . length } ):` ) ;
116
+ for ( const file of categorizedFiles . deletions ) {
117
+ logger . info ( ` - ${ file } ` ) ;
127
118
}
119
+ }
128
120
129
- logger . info ( ` Total: ${ categorizedFiles . total } files` ) ;
130
- logger . info ( "" ) ;
121
+ if ( categorizedFiles . renames . length > 0 ) {
122
+ logger . info ( ` Renames (${ categorizedFiles . renames . length } ):` ) ;
123
+ for ( const rename of categorizedFiles . renames ) {
124
+ logger . info ( ` R ${ rename . from } -> ${ rename . to } ` ) ;
125
+ }
131
126
}
132
127
133
- return categorizedFiles ;
134
- } catch ( error ) {
135
- logger ?. error ( `Error getting categorized changed files: ${ error } ` ) ;
136
- return {
137
- additions : /** @type {string[] } */ ( [ ] ) ,
138
- modifications : /** @type {string[] } */ ( [ ] ) ,
139
- deletions : /** @type {string[] } */ ( [ ] ) ,
140
- renames : /** @type {{from: string, to: string}[] } */ ( [ ] ) ,
141
- total : 0 ,
142
- } ;
128
+ logger . info ( ` Total: ${ categorizedFiles . total } files` ) ;
129
+ logger . info ( "" ) ;
143
130
}
131
+
132
+ return categorizedFiles ;
144
133
}
145
134
146
135
// Functions suitable for passing to string[].filter(), ordered roughly in order of increasing specificity
0 commit comments