@@ -2,6 +2,7 @@ import execa, {ExecaError} from 'execa';
2
2
import load from '@commitlint/load' ;
3
3
import lint from '@commitlint/lint' ;
4
4
import read from '@commitlint/read' ;
5
+ import { simpleGit } from 'simple-git' ;
5
6
import isFunction from 'lodash.isfunction' ;
6
7
import resolveFrom from 'resolve-from' ;
7
8
import resolveGlobal from 'resolve-global' ;
@@ -213,16 +214,39 @@ async function main(args: MainArgs): Promise<void> {
213
214
throw err ;
214
215
}
215
216
216
- const input = await ( fromStdin
217
- ? stdin ( )
218
- : read ( {
219
- to : flags . to ,
220
- from : flags . from ,
221
- edit : flags . edit ,
222
- cwd : flags . cwd ,
223
- gitLogArgs : flags [ 'git-log-args' ] ,
224
- } ) ) ;
217
+ if ( flags . from != null && flags . to != null && flags . from === flags . to ) {
218
+ const err = new CliError (
219
+ 'Please use a different commit hash for --from and --to, not the same. (Or use the --last flag for analyzing just the last commit.)' ,
220
+ pkg . name
221
+ ) ;
222
+ yargs . showHelp ( 'log' ) ;
223
+ console . log ( err . message ) ;
224
+ throw err ;
225
+ }
226
+
227
+ let input ;
225
228
229
+ if ( flags . last != null ) {
230
+ const log = await simpleGit ( { baseDir : flags . cwd } ) . log ( {
231
+ maxCount : 1 ,
232
+ } ) ;
233
+ input = '' ;
234
+ if ( log . latest ) {
235
+ input = log . latest . message ;
236
+ } else {
237
+ throw new CliError ( 'No commits found in the repository.' , pkg . name ) ;
238
+ }
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
const messages = ( Array . isArray ( input ) ? input : [ input ] )
227
251
. filter ( ( message ) => typeof message === 'string' )
228
252
. filter ( ( message ) => message . trim ( ) !== '' )
0 commit comments