@@ -93,12 +93,6 @@ function isEven(git, branch1, branch2) {
93
93
! ( yield isBehind ( git , branch1 , branch2 ) ) ) ;
94
94
} ) ;
95
95
}
96
- function hasDiff ( git , branch1 , branch2 ) {
97
- return __awaiter ( this , void 0 , void 0 , function * ( ) {
98
- const result = yield git . diff ( [ `${ branch1 } ..${ branch2 } ` ] ) ;
99
- return result . length > 0 ;
100
- } ) ;
101
- }
102
96
function splitLines ( multilineString ) {
103
97
return multilineString
104
98
. split ( '\n' )
@@ -192,7 +186,7 @@ function createOrUpdateBranch(git, commitMessage, base, branch, branchRemoteName
192
186
// squash merged but not deleted. We need to reset to make sure it doesn't appear
193
187
// to have a diff with the base due to different commits for the same changes.
194
188
// For changes on base this reset is equivalent to a rebase of the pull request branch.
195
- if ( ( yield hasDiff ( git , branch , tempBranch ) ) ||
189
+ if ( ( yield git . hasDiff ( [ ` ${ branch } .. ${ tempBranch } ` ] ) ) ||
196
190
! ( yield isAhead ( git , base , tempBranch ) ) ) {
197
191
core . info ( `Resetting '${ branch } '` ) ;
198
192
// Alternatively, git switch -C branch tempBranch
@@ -662,16 +656,6 @@ class GitCommandManager {
662
656
return output . exitCode === 0 ;
663
657
} ) ;
664
658
}
665
- diff ( options ) {
666
- return __awaiter ( this , void 0 , void 0 , function * ( ) {
667
- const args = [ '-c' , 'core.pager=cat' , 'diff' ] ;
668
- if ( options ) {
669
- args . push ( ...options ) ;
670
- }
671
- const output = yield this . exec ( args ) ;
672
- return output . stdout . trim ( ) ;
673
- } ) ;
674
- }
675
659
fetch ( refSpec , remoteName , options ) {
676
660
return __awaiter ( this , void 0 , void 0 , function * ( ) {
677
661
const args = [ '-c' , 'protocol.version=2' , 'fetch' ] ;
@@ -712,19 +696,28 @@ class GitCommandManager {
712
696
getWorkingDirectory ( ) {
713
697
return this . workingDirectory ;
714
698
}
699
+ hasDiff ( options ) {
700
+ return __awaiter ( this , void 0 , void 0 , function * ( ) {
701
+ const args = [ 'diff' , '--quiet' ] ;
702
+ if ( options ) {
703
+ args . push ( ...options ) ;
704
+ }
705
+ const output = yield this . exec ( args , true ) ;
706
+ return output . exitCode === 1 ;
707
+ } ) ;
708
+ }
715
709
isDirty ( untracked ) {
716
710
return __awaiter ( this , void 0 , void 0 , function * ( ) {
717
- const diffArgs = [ '--abbrev=40' , '--full-index' , '--raw' ] ;
718
- // Check staged changes
719
- if ( yield this . diff ( [ ...diffArgs , '--staged' ] ) ) {
711
+ // Check untracked changes
712
+ if ( untracked && ( yield this . status ( [ '--porcelain' , '-unormal' ] ) ) ) {
720
713
return true ;
721
714
}
722
715
// Check working index changes
723
- if ( yield this . diff ( diffArgs ) ) {
716
+ if ( yield this . hasDiff ( ) ) {
724
717
return true ;
725
718
}
726
- // Check untracked changes
727
- if ( untracked && ( yield this . status ( [ '--porcelain' , '-unormal' ] ) ) ) {
719
+ // Check staged changes
720
+ if ( yield this . hasDiff ( [ '--staged' ] ) ) {
728
721
return true ;
729
722
}
730
723
return false ;
0 commit comments