@@ -478,16 +478,23 @@ async function main() {
478
478
title : core . getInput ( "title" ) ,
479
479
body : core . getInput ( "body" ) ,
480
480
branch : core . getInput ( "branch" ) ,
481
+ path : core . getInput ( "path" ) ,
481
482
commitMessage : core . getInput ( "commit-message" ) ,
482
483
author : core . getInput ( "author" )
483
484
} ;
484
485
485
486
core . debug ( `Inputs: ${ inspect ( inputs ) } ` ) ;
486
487
487
- const { hasChanges, hasUncommitedChanges } = await getLocalChanges ( ) ;
488
+ const { hasChanges, hasUncommitedChanges } = await getLocalChanges (
489
+ inputs . path
490
+ ) ;
488
491
489
492
if ( ! hasChanges ) {
490
- core . info ( "No local changes" ) ;
493
+ if ( inputs . path ) {
494
+ core . info ( `No local changes matchin "${ inputs . path } "` ) ;
495
+ } else {
496
+ core . info ( "No local changes" ) ;
497
+ }
491
498
process . exit ( 0 ) ; // there is currently no neutral exit code
492
499
}
493
500
@@ -511,10 +518,16 @@ async function main() {
511
518
} ) ;
512
519
}
513
520
514
- core . debug ( `Comitting local changes` ) ;
515
- await command ( "git add ." , { shell : true } ) ;
521
+ if ( inputs . path ) {
522
+ core . debug ( `Committing local changes matching "${ inputs . path } "` ) ;
523
+ await command ( `git add "${ inputs . path } "` , { shell : true } ) ;
524
+ } else {
525
+ core . debug ( `Committing all local changes` ) ;
526
+ await command ( "git add ." , { shell : true } ) ;
527
+ }
528
+
516
529
await command (
517
- `git commit -a - m "${ inputs . commitMessage } " --author "${ inputs . author } "` ,
530
+ `git commit -m "${ inputs . commitMessage } " --author "${ inputs . author } "` ,
518
531
{ shell : true }
519
532
) ;
520
533
} else {
@@ -525,12 +538,11 @@ async function main() {
525
538
const remoteBranchExists = await checkOutRemoteBranch ( inputs . branch ) ;
526
539
527
540
core . debug ( `Pushing local changes` ) ;
528
- const { stdout : pushStdOut , stderr : pushStdErr } = await command (
541
+ await command (
529
542
`git push -f https://x-access-token:${ process . env . GITHUB_TOKEN } @github.com/${ process . env . GITHUB_REPOSITORY } .git HEAD:refs/heads/${ inputs . branch } ` ,
530
543
{ shell : true }
531
544
) ;
532
545
533
- // no idea why the `git push` output goes into stderr. Checking in both just in case.
534
546
if ( remoteBranchExists ) {
535
547
core . info ( `Existing pull request for "${ inputs . branch } " updated` ) ;
536
548
return ;
@@ -556,8 +568,10 @@ async function main() {
556
568
}
557
569
}
558
570
559
- async function getLocalChanges ( ) {
560
- const { stdout } = await command ( "git status" , { shell : true } ) ;
571
+ async function getLocalChanges ( path ) {
572
+ const { stdout } = await command ( `git status ${ path || "*" } ` , {
573
+ shell : true
574
+ } ) ;
561
575
562
576
if ( / Y o u r b r a n c h i s u p t o d a t e / . test ( stdout ) ) {
563
577
return ;
@@ -603,16 +617,27 @@ async function setGitUser({ name, email }) {
603
617
604
618
async function checkOutRemoteBranch ( branch ) {
605
619
try {
620
+ const { stdout } = await command ( `git rev-parse --abbrev-ref HEAD` , {
621
+ shell : true
622
+ } ) ;
623
+
624
+ if ( stdout === branch ) {
625
+ core . info ( `Already in "${ branch } ".` ) ;
626
+ return true ;
627
+ }
628
+
606
629
await command (
607
630
`git fetch https://x-access-token:${ process . env . GITHUB_TOKEN } @github.com/${ process . env . GITHUB_REPOSITORY } .git ${ branch } :${ branch } ` ,
608
631
{ shell : true }
609
632
) ;
633
+
610
634
await command ( `git checkout ${ branch } ` , { shell : true } ) ;
611
635
core . info ( `Remote branch "${ branch } " checked out locally.` ) ;
612
- await command ( `git rebase -Xtheirs -` , { shell : true } ) ;
636
+ await command ( `git rebase -Xtheirs --autostash - ` , { shell : true } ) ;
613
637
return true ;
614
638
} catch ( error ) {
615
639
core . info ( `Branch "${ branch } " does not yet exist on remote.` ) ;
640
+ await command ( `git checkout -b ${ branch } ` , { shell : true } ) ;
616
641
return false ;
617
642
}
618
643
}
0 commit comments