@@ -10,7 +10,8 @@ import {
1010 getRepositoryName ,
1111 getRepositoryUrl ,
1212 pushBranch ,
13- safeGitUrlForLogging
13+ safeGitUrlForLogging ,
14+ tryGetGitOrigin
1415} from "../lib/gitutils" ;
1516import { disableVerboseLogging , enableVerboseLogging } from "../logger" ;
1617import { exec } from "./shell" ;
@@ -211,6 +212,35 @@ describe("pushBranch", () => {
211212 } ) ;
212213} ) ;
213214
215+ describe ( "tryGetGitOrigin" , ( ) => {
216+ it ( "attempts to retrieve azdo git origin" , async ( ) => {
217+ const originUrl = "http://github.com/repo/url" ;
218+
219+ when ( exec as jest . Mock )
220+ . calledWith ( "echo" , [ "$(Build.Repository.Uri)" ] )
221+ . mockReturnValue ( originUrl ) ;
222+
223+ const originUrlResponse = await tryGetGitOrigin ( ) ;
224+ expect ( originUrlResponse ) . toEqual ( originUrl ) ;
225+ } ) ;
226+
227+ it ( "attempts to retrieve git origin from using git cli" , async ( ) => {
228+ const originUrl = "http://github.com/repo/url" ;
229+ // Echoing variable from AzDo fails… trying Git
230+ when ( exec as jest . Mock )
231+ . calledWith ( "echo" , [ "$(Build.Repository.Uri)" ] )
232+ . mockRejectedValue ( "some reason" ) ;
233+
234+ // Retrieving url from Git succeeds
235+ when ( exec as jest . Mock )
236+ . calledWith ( "git" , [ "config" , "--get" , "remote.origin.url" ] )
237+ . mockReturnValue ( originUrl ) ;
238+
239+ const originUrlResponse = await tryGetGitOrigin ( ) ;
240+ expect ( originUrlResponse ) . toEqual ( originUrl ) ;
241+ } ) ;
242+ } ) ;
243+
214244describe ( "getOriginUrl" , ( ) => {
215245 it ( "should call exec with the proper git arguments" , async ( ) => {
216246 const originUrl = "foo" ;
0 commit comments