11import { Options , StringTask } from '../types' ;
2- import { LogResult } from '../../../typings' ;
2+ import { LogResult , SimpleGit } from '../../../typings' ;
33import {
44 COMMIT_BOUNDARY ,
55 createListLogSummaryParser ,
66 SPLITTER ,
77 START_BOUNDARY
88} from '../parsers/parse-list-log-summary' ;
9- import { appendTaskOptions } from '../utils' ;
9+ import {
10+ appendTaskOptions ,
11+ filterArray ,
12+ filterString ,
13+ filterType ,
14+ trailingFunctionArgument ,
15+ trailingOptionsArgument
16+ } from '../utils' ;
17+ import { SimpleGitApi } from '../simple-git-api' ;
18+ import { configurationErrorTask } from './task' ;
1019
1120enum excludeOptions {
1221 '--pretty' ,
@@ -45,7 +54,13 @@ export type LogOptions<T = DefaultLogFields> = {
4554 to ?: string ;
4655} ;
4756
48- function prettyFormat ( format : { [ key : string ] : string | unknown } , splitter : string ) : [ string [ ] , string ] {
57+ interface ParsedLogOptions {
58+ fields : string [ ] ;
59+ splitter : string ;
60+ commands : string [ ]
61+ }
62+
63+ function prettyFormat ( format : { [ key : string ] : string | unknown } , splitter : string ) : [ string [ ] , string ] {
4964 const fields : string [ ] = [ ] ;
5065 const formatStr : string [ ] = [ ] ;
5166
@@ -69,7 +84,7 @@ function userOptions<T>(input: T): Exclude<Omit<T, keyof typeof excludeOptions>,
6984 return output ;
7085}
7186
72- export function parseLogOptions < T extends Options > ( opt : LogOptions < T > = { } , customArgs : string [ ] = [ ] ) {
87+ export function parseLogOptions < T extends Options > ( opt : LogOptions < T > = { } , customArgs : string [ ] = [ ] ) : ParsedLogOptions {
7388 const splitter = opt . splitter || SPLITTER ;
7489 const format = opt . format || {
7590 hash : '%H' ,
@@ -91,7 +106,7 @@ export function parseLogOptions<T extends Options>(opt: LogOptions<T> = {}, cust
91106
92107 const maxCount : number | undefined = ( opt as any ) . n || ( opt as any ) [ 'max-count' ] || opt . maxCount ;
93108 if ( maxCount ) {
94- command . push ( `--max-count=${ maxCount } ` ) ;
109+ command . push ( `--max-count=${ maxCount } ` ) ;
95110 }
96111
97112 if ( opt . from && opt . to ) {
@@ -122,3 +137,27 @@ export function logTask<T>(splitter: string, fields: string[], customArgs: strin
122137 parser : createListLogSummaryParser ( splitter , fields ) ,
123138 } ;
124139}
140+
141+ export default function ( ) : Pick < SimpleGit , 'log' > {
142+ return {
143+ log < T extends Options > ( this : SimpleGitApi , ...rest : unknown [ ] ) {
144+ const next = trailingFunctionArgument ( arguments ) ;
145+ const task = rejectDeprecatedSignatures ( ...rest ) ||
146+ createLogTask ( parseLogOptions < T > ( trailingOptionsArgument ( arguments ) , filterType ( arguments [ 0 ] , filterArray ) ) )
147+
148+ return this . _runTask ( task , next ) ;
149+ }
150+ }
151+
152+ function createLogTask ( options : ParsedLogOptions ) {
153+ return logTask ( options . splitter , options . fields , options . commands ) ;
154+ }
155+
156+ function rejectDeprecatedSignatures ( from ?: unknown , to ?: unknown ) {
157+ return (
158+ filterString ( from ) &&
159+ filterString ( to ) &&
160+ configurationErrorTask ( `git.log(string, string) should be replaced with git.log({ from: string, to: string })` )
161+ ) ;
162+ }
163+ }
0 commit comments