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