@@ -78,6 +78,7 @@ export const GitErrors = {
7878 changesWouldBeOverwritten : / Y o u r l o c a l c h a n g e s t o t h e f o l l o w i n g f i l e s w o u l d b e o v e r w r i t t e n / i,
7979 commitChangesFirst : / P l e a s e , c o m m i t y o u r c h a n g e s b e f o r e y o u c a n / i,
8080 conflict : / ^ C O N F L I C T \( [ ^ ) ] + \) : \b / m,
81+ conflictsInWip : / h i n t : A f t e r r e s o l v i n g t h e c o n f l i c t s , m a r k t h e m / i,
8182 failedToDeleteDirectoryNotEmpty : / f a i l e d t o d e l e t e ' ( .* ?) ' : D i r e c t o r y n o t e m p t y / i,
8283 invalidObjectName : / i n v a l i d o b j e c t n a m e : ( .* ) \s / i,
8384 invalidObjectNameList : / c o u l d n o t o p e n o b j e c t n a m e l i s t : ( .* ) \s / i,
@@ -165,6 +166,12 @@ function getStdinUniqueKey(): number {
165166type ExitCodeOnlyGitCommandOptions = GitCommandOptions & { exitCodeOnly : true } ;
166167export type PushForceOptions = { withLease : true ; ifIncludes ?: boolean } | { withLease : false ; ifIncludes ?: never } ;
167168
169+ const cherryPickErrorAndReason = [
170+ [ GitErrors . changesWouldBeOverwritten , CherryPickErrorReason . AbortedWouldOverwrite ] ,
171+ [ GitErrors . conflict , CherryPickErrorReason . Conflicts ] ,
172+ [ GitErrors . conflictsInWip , CherryPickErrorReason . Conflicts ] ,
173+ ] ;
174+
168175const tagErrorAndReason : [ RegExp , TagErrorReason ] [ ] = [
169176 [ GitErrors . tagAlreadyExists , TagErrorReason . TagAlreadyExists ] ,
170177 [ GitErrors . tagNotFound , TagErrorReason . TagNotFound ] ,
@@ -617,28 +624,18 @@ export class Git {
617624 return this . git < string > ( { cwd : repoPath } , ...params ) ;
618625 }
619626
620- async cherrypick ( repoPath : string , sha : string , options : { noCommit ?: boolean ; errors ?: GitErrorHandling } = { } ) {
621- const params = [ 'cherry-pick' ] ;
622- if ( options ?. noCommit ) {
623- params . push ( '-n' ) ;
624- }
625- params . push ( sha ) ;
626-
627+ async cherryPick ( repoPath : string , args : string [ ] ) {
627628 try {
628- await this . git < string > ( { cwd : repoPath , errors : options ?. errors } , ...params ) ;
629+ await this . git < string > ( { cwd : repoPath } , 'cherry-pick' , ...args ) ;
629630 } catch ( ex ) {
630631 const msg : string = ex ?. toString ( ) ?? '' ;
631- let reason : CherryPickErrorReason = CherryPickErrorReason . Other ;
632- if (
633- GitErrors . changesWouldBeOverwritten . test ( msg ) ||
634- GitErrors . changesWouldBeOverwritten . test ( ex . stderr ?? '' )
635- ) {
636- reason = CherryPickErrorReason . AbortedWouldOverwrite ;
637- } else if ( GitErrors . conflict . test ( msg ) || GitErrors . conflict . test ( ex . stdout ?? '' ) ) {
638- reason = CherryPickErrorReason . Conflicts ;
632+ for ( const [ error , reason ] of cherryPickErrorAndReason ) {
633+ if ( error . test ( msg ) || error . test ( ex . stderr ?? '' ) ) {
634+ throw new CherryPickError ( reason , ex ) ;
635+ }
639636 }
640637
641- throw new CherryPickError ( reason , ex , sha ) ;
638+ throw new CherryPickError ( CherryPickErrorReason . Other , ex ) ;
642639 }
643640 }
644641
0 commit comments