@@ -95,6 +95,11 @@ const cli = yargs(process.argv.slice(2))
95
95
"additional git log arguments as space separated string, example '--first-parent --cherry-pick'" ,
96
96
type : 'string' ,
97
97
} ,
98
+ last : {
99
+ alias : 'l' ,
100
+ description : 'just analyze the last commit; applies if edit=false' ,
101
+ type : 'boolean' ,
102
+ } ,
98
103
format : {
99
104
alias : 'o' ,
100
105
description : 'output format of the results' ,
@@ -214,15 +219,34 @@ async function main(args: MainArgs): Promise<void> {
214
219
215
220
const fromStdin = checkFromStdin ( raw , flags ) ;
216
221
217
- const input = await ( fromStdin
218
- ? stdin ( )
219
- : read ( {
220
- to : flags . to ,
221
- from : flags . from ,
222
- edit : flags . edit ,
223
- cwd : flags . cwd ,
224
- gitLogArgs : flags [ 'git-log-args' ] ,
225
- } ) ) ;
222
+ if (
223
+ Object . hasOwn ( flags , 'last' ) &&
224
+ ( Object . hasOwn ( flags , 'from' ) || Object . hasOwn ( flags , 'to' ) || flags . edit )
225
+ ) {
226
+ const err = new CliError (
227
+ 'Please use the --last flag alone. The --last flag should not be used with --to or --from or --edit.' ,
228
+ pkg . name
229
+ ) ;
230
+ cli . showHelp ( 'log' ) ;
231
+ console . log ( err . message ) ;
232
+ throw err ;
233
+ }
234
+
235
+ let input ;
236
+ if ( Object . hasOwn ( flags , 'last' ) ) {
237
+ const executeGitCommand = await execa ( 'git' , [ 'log' , '-1' , '--pretty=%B' ] ) ;
238
+ input = executeGitCommand . stdout ;
239
+ } else {
240
+ input = await ( fromStdin
241
+ ? stdin ( )
242
+ : read ( {
243
+ to : flags . to ,
244
+ from : flags . from ,
245
+ edit : flags . edit ,
246
+ cwd : flags . cwd ,
247
+ gitLogArgs : flags [ 'git-log-args' ] ,
248
+ } ) ) ;
249
+ }
226
250
227
251
const messages = ( Array . isArray ( input ) ? input : [ input ] )
228
252
. filter ( ( message ) => typeof message === 'string' )
@@ -231,7 +255,7 @@ async function main(args: MainArgs): Promise<void> {
231
255
232
256
if ( messages . length === 0 && ! checkFromRepository ( flags ) ) {
233
257
const err = new CliError (
234
- '[input] is required: supply via stdin, or --env or --edit or --from and --to' ,
258
+ '[input] is required: supply via stdin, or --env or --edit or --last or -- from and --to' ,
235
259
pkg . name
236
260
) ;
237
261
cli . showHelp ( 'log' ) ;
@@ -374,7 +398,11 @@ function checkFromEdit(flags: CliFlags): boolean {
374
398
}
375
399
376
400
function checkFromHistory ( flags : CliFlags ) : boolean {
377
- return typeof flags . from === 'string' || typeof flags . to === 'string' ;
401
+ return (
402
+ typeof flags . from === 'string' ||
403
+ typeof flags . to === 'string' ||
404
+ typeof flags . last === 'boolean'
405
+ ) ;
378
406
}
379
407
380
408
function normalizeFlags ( flags : CliFlags ) : CliFlags {
0 commit comments