@@ -78,6 +78,8 @@ export const GitErrors = {
78
78
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,
79
79
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,
80
80
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,
81
83
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,
82
84
invalidObjectName : / i n v a l i d o b j e c t n a m e : ( .* ) \s / i,
83
85
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 {
165
167
type ExitCodeOnlyGitCommandOptions = GitCommandOptions & { exitCodeOnly : true } ;
166
168
export type PushForceOptions = { withLease : true ; ifIncludes ?: boolean } | { withLease : false ; ifIncludes ?: never } ;
167
169
170
+ const cherryPickErrorAndReason = [
171
+ [ GitErrors . changesWouldBeOverwritten , CherryPickErrorReason . AbortedWouldOverwrite ] ,
172
+ [ GitErrors . conflict , CherryPickErrorReason . Conflicts ] ,
173
+ [ GitErrors . cherryPickUnmerged , CherryPickErrorReason . Conflicts ] ,
174
+ ] ;
175
+
168
176
const tagErrorAndReason : [ RegExp , TagErrorReason ] [ ] = [
169
177
[ GitErrors . tagAlreadyExists , TagErrorReason . TagAlreadyExists ] ,
170
178
[ GitErrors . tagNotFound , TagErrorReason . TagNotFound ] ,
@@ -617,28 +625,18 @@ export class Git {
617
625
return this . git < string > ( { cwd : repoPath } , ...params ) ;
618
626
}
619
627
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 [ ] ) {
627
629
try {
628
- await this . git < string > ( { cwd : repoPath , errors : options ?. errors } , ...params ) ;
630
+ await this . git < string > ( { cwd : repoPath } , 'cherry-pick' , ...args ) ;
629
631
} catch ( ex ) {
630
632
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
+ }
639
637
}
640
638
641
- throw new CherryPickError ( reason , ex , sha ) ;
639
+ throw new CherryPickError ( CherryPickErrorReason . Other , ex ) ;
642
640
}
643
641
}
644
642
0 commit comments