@@ -496,18 +496,28 @@ export default class GitHelper {
496
496
/**
497
497
* @param {string } workDir work dir
498
498
* @param {string } branch branch
499
- * @param {boolean } withTag with tag?
500
499
* @param {Context } context context
500
+ * @param {object } options options
501
501
* @return {Promise<void> } void
502
502
*/
503
- public push = async ( workDir : string , branch : string , withTag : boolean , context : Context ) : Promise < void > => {
504
- const url = this . getOrigin ( context ) ;
505
- const tags = withTag ? ' --tags' : '' ;
503
+ public push = async ( workDir : string , branch : string , context : Context , options ?: { withTag ?: boolean ; force ?: boolean ; args ?: Array < string > } ) : Promise < void > => {
504
+ const url = this . getOrigin ( context ) ;
505
+ const args : Array < string > = [ ] ;
506
+ if ( options ?. withTag ) {
507
+ args . push ( '--tags' ) ;
508
+ }
509
+ if ( options ?. force ) {
510
+ args . push ( '--force' ) ;
511
+ }
512
+ if ( options ?. args ) {
513
+ args . push ( ...options . args ) ;
514
+ }
506
515
await this . runCommand ( workDir , {
507
516
command : 'git push' ,
508
- args : [ withTag ? '--tags' : '' , url , `${ branch } :refs/heads/${ branch } ` ] ,
517
+ args : args . concat ( [ url , `${ branch } :refs/heads/${ branch } ` ] ) ,
509
518
quiet : this . isQuiet ( ) ,
510
- altCommand : `git push${ tags } origin ${ branch } :refs/heads/${ branch } ` ,
519
+ altCommand : `git push${ args . concat ( [ 'origin' , `${ branch } :refs/heads/${ branch } ` ] ) . join ( ' ' ) } ` ,
520
+ suppressError : true ,
511
521
} ) ;
512
522
} ;
513
523
@@ -517,15 +527,7 @@ export default class GitHelper {
517
527
* @param {Context } context context
518
528
* @return {Promise<void> } void
519
529
*/
520
- public forcePush = async ( workDir : string , branch : string , context : Context ) : Promise < void > => {
521
- const url = this . getOrigin ( context ) ;
522
- await this . runCommand ( workDir , {
523
- command : 'git push' ,
524
- args : [ '--force' , url , `${ branch } :refs/heads/${ branch } ` ] ,
525
- quiet : this . isQuiet ( ) ,
526
- altCommand : `git push --force origin ${ branch } :refs/heads/${ branch } ` ,
527
- } ) ;
528
- } ;
530
+ public forcePush = async ( workDir : string , branch : string , context : Context ) : Promise < void > => this . push ( workDir , branch , context , { force : true } ) ;
529
531
530
532
/**
531
533
* @param {string } workDir work dir
0 commit comments