@@ -141,6 +141,52 @@ describe('ref', () => {
141
141
expect ( ref ) . toEqual ( 'refs/tags/8.0.0' ) ;
142
142
} ) ;
143
143
144
+ it ( 'returns mocked detached tag ref (shallow clone)' , async ( ) => {
145
+ jest . spyOn ( Exec , 'getExecOutput' ) . mockImplementation ( ( cmd , args ) : Promise < ExecOutput > => {
146
+ const fullCmd = `${ cmd } ${ args ?. join ( ' ' ) } ` ;
147
+ let result = '' ;
148
+ switch ( fullCmd ) {
149
+ case 'git branch --show-current' :
150
+ result = '' ;
151
+ break ;
152
+ case 'git show -s --pretty=%D' :
153
+ result = 'grafted, HEAD, tag: 8.0.0' ;
154
+ break ;
155
+ }
156
+ return Promise . resolve ( {
157
+ stdout : result ,
158
+ stderr : '' ,
159
+ exitCode : 0
160
+ } ) ;
161
+ } ) ;
162
+
163
+ const ref = await Git . ref ( ) ;
164
+
165
+ expect ( ref ) . toEqual ( 'refs/tags/8.0.0' ) ;
166
+ } ) ;
167
+
168
+ it ( 'should throws an error when detached HEAD ref is not supported' , 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 = 'wrong, HEAD, tag: 8.0.0' ;
178
+ break ;
179
+ }
180
+ return Promise . resolve ( {
181
+ stdout : result ,
182
+ stderr : '' ,
183
+ exitCode : 0
184
+ } ) ;
185
+ } ) ;
186
+
187
+ await expect ( Git . ref ( ) ) . rejects . toThrow ( 'Cannot find detached HEAD ref in "wrong, HEAD, tag: 8.0.0"' ) ;
188
+ } ) ;
189
+
144
190
it ( 'returns mocked detached branch ref' , async ( ) => {
145
191
jest . spyOn ( Exec , 'getExecOutput' ) . mockImplementation ( ( cmd , args ) : Promise < ExecOutput > => {
146
192
const fullCmd = `${ cmd } ${ args ?. join ( ' ' ) } ` ;
0 commit comments