File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -165,6 +165,30 @@ describe('ref', () => {
165165 expect ( ref ) . toEqual ( 'refs/tags/8.0.0' ) ;
166166 } ) ;
167167
168+ it ( 'returns mocked detached pull request merge ref (shallow clone)' , async ( ) => {
169+ jest . spyOn ( Exec , 'getExecOutput' ) . mockImplementation ( ( cmd , args ) : Promise < ExecOutput > => {
170+ const fullCmd = `${ cmd } ${ args ?. join ( ' ' ) } ` ;
171+ let result = '' ;
172+ switch ( fullCmd ) {
173+ case 'git branch --show-current' :
174+ result = '' ;
175+ break ;
176+ case 'git show -s --pretty=%D' :
177+ result = 'grafted, HEAD, pull/221/merge' ;
178+ break ;
179+ }
180+ return Promise . resolve ( {
181+ stdout : result ,
182+ stderr : '' ,
183+ exitCode : 0
184+ } ) ;
185+ } ) ;
186+
187+ const ref = await Git . ref ( ) ;
188+
189+ expect ( ref ) . toEqual ( 'refs/pull/221/merge' ) ;
190+ } ) ;
191+
168192 it ( 'should throws an error when detached HEAD ref is not supported' , async ( ) => {
169193 jest . spyOn ( Exec , 'getExecOutput' ) . mockImplementation ( ( cmd , args ) : Promise < ExecOutput > => {
170194 const fullCmd = `${ cmd } ${ args ?. join ( ' ' ) } ` ;
Original file line number Diff line number Diff line change @@ -137,12 +137,18 @@ export class Git {
137137 return `refs/tags/${ ref . split ( ':' ) [ 1 ] . trim ( ) } ` ;
138138 }
139139
140- // Otherwise, it's a branch "<origin>/<branch-name>, <branch-name>"
140+ // Branch refs are formatted as "<origin>/<branch-name>, <branch-name>"
141141 const branchMatch = ref . match ( / ^ [ ^ / ] + \/ [ ^ / ] + , ( .+ ) $ / ) ;
142142 if ( branchMatch ) {
143143 return `refs/heads/${ branchMatch [ 1 ] . trim ( ) } ` ;
144144 }
145145
146+ // Pull request merge refs are formatted as "pull/<number>/<state>"
147+ const prMatch = ref . match ( / ^ p u l l \/ \d + \/ ( h e a d | m e r g e ) $ / ) ;
148+ if ( prMatch ) {
149+ return `refs/${ ref } ` ;
150+ }
151+
146152 throw new Error ( `Unsupported detached HEAD ref in "${ res } "` ) ;
147153 }
148154
You can’t perform that action at this time.
0 commit comments