@@ -78,6 +78,8 @@ 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+ cherryPickUnmerged :
82+ / e r r o r : C h e r r y - p i c k i n g .* u n m e r g e d f i l e s \. \n h i n t : .* \n h i n t : .* m a k e a c o m m i t \. \n f a t a l : c h e r r y - p i c k f a i l e d / i,
8183 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,
8284 invalidObjectName : / i n v a l i d o b j e c t n a m e : ( .* ) \s / i,
8385 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 +167,12 @@ function getStdinUniqueKey(): number {
165167type ExitCodeOnlyGitCommandOptions = GitCommandOptions & { exitCodeOnly : true } ;
166168export type PushForceOptions = { withLease : true ; ifIncludes ?: boolean } | { withLease : false ; ifIncludes ?: never } ;
167169
170+ const cherryPickErrorAndReason = [
171+ [ GitErrors . changesWouldBeOverwritten , CherryPickErrorReason . AbortedWouldOverwrite ] ,
172+ [ GitErrors . conflict , CherryPickErrorReason . Conflicts ] ,
173+ [ GitErrors . cherryPickUnmerged , CherryPickErrorReason . Conflicts ] ,
174+ ] ;
175+
168176const tagErrorAndReason : [ RegExp , TagErrorReason ] [ ] = [
169177 [ GitErrors . tagAlreadyExists , TagErrorReason . TagAlreadyExists ] ,
170178 [ GitErrors . tagNotFound , TagErrorReason . TagNotFound ] ,
@@ -617,28 +625,18 @@ export class Git {
617625 return this . git < string > ( { cwd : repoPath } , ...params ) ;
618626 }
619627
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-
628+ async cherryPick ( repoPath : string , args : string [ ] ) {
627629 try {
628- await this . git < string > ( { cwd : repoPath , errors : options ?. errors } , ...params ) ;
630+ await this . git < string > ( { cwd : repoPath } , 'cherry-pick' , ...args ) ;
629631 } catch ( ex ) {
630632 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 ;
633+ for ( const [ error , reason ] of cherryPickErrorAndReason ) {
634+ if ( error . test ( msg ) || error . test ( ex . stderr ?? '' ) ) {
635+ throw new CherryPickError ( reason , ex ) ;
636+ }
639637 }
640638
641- throw new CherryPickError ( reason , ex , sha ) ;
639+ throw new CherryPickError ( CherryPickErrorReason . Other , ex ) ;
642640 }
643641 }
644642
0 commit comments