@@ -98,77 +98,74 @@ private int GetNumberOfUncommittedChangesInternal()
9898 }
9999 public void CreateBranchForPullRequestBranch ( AuthenticationInfo auth )
100100 {
101- new OperationWithExponentialBackoff < LockedFileException > ( new ThreadSleep ( ) , log , ( ) =>
101+ RepositoryExtensions . RunSafe ( ( ) =>
102102 {
103- CreateBranchForPullRequestBranchInternal ( auth ) ;
104- } ) . ExecuteAsync ( ) . Wait ( ) ;
105- }
106- private void CreateBranchForPullRequestBranchInternal ( AuthenticationInfo auth )
107- {
108- var network = repositoryInstance . Network ;
109- var remote = network . Remotes . Single ( ) ;
103+ var network = repositoryInstance . Network ;
104+ var remote = network . Remotes . Single ( ) ;
110105
111- log . Info ( "Fetching remote refs to see if there is a pull request ref" ) ;
112- var credentialsProvider = GetCredentialsProvider ( auth ) ;
113- var remoteTips = ( credentialsProvider != null
114- ? network . ListReferences ( remote , credentialsProvider )
115- : network . ListReferences ( remote ) )
116- . Select ( r => r . ResolveToDirectReference ( ) ) . ToList ( ) ;
106+ log . Info ( "Fetching remote refs to see if there is a pull request ref" ) ;
107+ var credentialsProvider = GetCredentialsProvider ( auth ) ;
108+ var remoteTips = ( credentialsProvider != null
109+ ? network . ListReferences ( remote , credentialsProvider )
110+ : network . ListReferences ( remote ) )
111+ . Select ( r => r . ResolveToDirectReference ( ) ) . ToList ( ) ;
117112
118- log . Info ( $ "Remote Refs:{ System . Environment . NewLine } " + string . Join ( System . Environment . NewLine , remoteTips . Select ( r => r . CanonicalName ) ) ) ;
113+ log . Info ( $ "Remote Refs:{ System . Environment . NewLine } " + string . Join ( System . Environment . NewLine , remoteTips . Select ( r => r . CanonicalName ) ) ) ;
119114
120- var headTipSha = Head . Tip ? . Sha ;
115+ var headTipSha = Head . Tip ? . Sha ;
121116
122- var refs = remoteTips . Where ( r => r . TargetIdentifier == headTipSha ) . ToList ( ) ;
117+ var refs = remoteTips . Where ( r => r . TargetIdentifier == headTipSha ) . ToList ( ) ;
123118
124- if ( refs . Count == 0 )
125- {
126- var message = $ "Couldn't find any remote tips from remote '{ remote . Url } ' pointing at the commit '{ headTipSha } '.";
127- throw new WarningException ( message ) ;
128- }
119+ if ( refs . Count == 0 )
120+ {
121+ var message = $ "Couldn't find any remote tips from remote '{ remote . Url } ' pointing at the commit '{ headTipSha } '.";
122+ throw new WarningException ( message ) ;
123+ }
129124
130- if ( refs . Count > 1 )
131- {
132- var names = string . Join ( ", " , refs . Select ( r => r . CanonicalName ) ) ;
133- var message = $ "Found more than one remote tip from remote '{ remote . Url } ' pointing at the commit '{ headTipSha } '. Unable to determine which one to use ({ names } ).";
134- throw new WarningException ( message ) ;
135- }
125+ if ( refs . Count > 1 )
126+ {
127+ var names = string . Join ( ", " , refs . Select ( r => r . CanonicalName ) ) ;
128+ var message = $ "Found more than one remote tip from remote '{ remote . Url } ' pointing at the commit '{ headTipSha } '. Unable to determine which one to use ({ names } ).";
129+ throw new WarningException ( message ) ;
130+ }
136131
137- var reference = refs . First ( ) ;
138- var canonicalName = reference . CanonicalName ;
139- var referenceName = ReferenceName . Parse ( reference . CanonicalName ) ;
140- log . Info ( $ "Found remote tip '{ canonicalName } ' pointing at the commit '{ headTipSha } '.") ;
132+ var reference = refs . First ( ) ;
133+ var canonicalName = reference . CanonicalName ;
134+ var referenceName = ReferenceName . Parse ( reference . CanonicalName ) ;
135+ log . Info ( $ "Found remote tip '{ canonicalName } ' pointing at the commit '{ headTipSha } '.") ;
141136
142- if ( referenceName . IsTag )
143- {
144- log . Info ( $ "Checking out tag '{ canonicalName } '") ;
145- Checkout ( reference . Target . Sha ) ;
146- }
147- else if ( referenceName . IsPullRequest )
148- {
149- var fakeBranchName = canonicalName . Replace ( "refs/pull/" , "refs/heads/pull/" ) . Replace ( "refs/pull-requests/" , "refs/heads/pull-requests/" ) ;
137+ if ( referenceName . IsTag )
138+ {
139+ log . Info ( $ "Checking out tag '{ canonicalName } '") ;
140+ Checkout ( reference . Target . Sha ) ;
141+ }
142+ else if ( referenceName . IsPullRequest )
143+ {
144+ var fakeBranchName = canonicalName . Replace ( "refs/pull/" , "refs/heads/pull/" ) . Replace ( "refs/pull-requests/" , "refs/heads/pull-requests/" ) ;
150145
151- log . Info ( $ "Creating fake local branch '{ fakeBranchName } '.") ;
152- Refs . Add ( fakeBranchName , headTipSha ) ;
146+ log . Info ( $ "Creating fake local branch '{ fakeBranchName } '.") ;
147+ Refs . Add ( fakeBranchName , headTipSha ) ;
153148
154- log . Info ( $ "Checking local branch '{ fakeBranchName } ' out.") ;
155- Checkout ( fakeBranchName ) ;
156- }
157- else
158- {
159- var message = $ "Remote tip '{ canonicalName } ' from remote '{ remote . Url } ' doesn't look like a valid pull request.";
160- throw new WarningException ( message ) ;
161- }
149+ log . Info ( $ "Checking local branch '{ fakeBranchName } ' out.") ;
150+ Checkout ( fakeBranchName ) ;
151+ }
152+ else
153+ {
154+ var message = $ "Remote tip '{ canonicalName } ' from remote '{ remote . Url } ' doesn't look like a valid pull request.";
155+ throw new WarningException ( message ) ;
156+ }
157+ } ) ;
162158 }
163159 public void Clone ( string sourceUrl , string workdirPath , AuthenticationInfo auth )
164160 {
165161 try
166162 {
167- new OperationWithExponentialBackoff < LockedFileException > ( new ThreadSleep ( ) , log , ( ) =>
168- {
169- var path = Repository . Clone ( sourceUrl , workdirPath , GetCloneOptions ( auth ) ) ;
170- log . Info ( $ "Returned path after repository clone: { path } ") ;
171- } ) . ExecuteAsync ( ) . Wait ( ) ;
163+ var path = Repository . Clone ( sourceUrl , workdirPath , GetCloneOptions ( auth ) ) ;
164+ log . Info ( $ "Returned path after repository clone: { path } ") ;
165+ }
166+ catch ( LibGit2Sharp . LockedFileException ex )
167+ {
168+ throw new LockedFileException ( ex ) ;
172169 }
173170 catch ( LibGit2SharpException ex )
174171 {
@@ -191,11 +188,17 @@ public void Clone(string sourceUrl, string workdirPath, AuthenticationInfo auth)
191188 }
192189 public void Checkout ( string commitOrBranchSpec )
193190 {
194- new OperationWithExponentialBackoff < LockedFileException > ( new ThreadSleep ( ) , log , ( ) => Commands . Checkout ( repositoryInstance , commitOrBranchSpec ) ) . ExecuteAsync ( ) . Wait ( ) ;
191+ RepositoryExtensions . RunSafe ( ( ) =>
192+ {
193+ Commands . Checkout ( repositoryInstance , commitOrBranchSpec ) ;
194+ } ) ;
195195 }
196196 public void Fetch ( string remote , IEnumerable < string > refSpecs , AuthenticationInfo auth , string logMessage )
197197 {
198- new OperationWithExponentialBackoff < LockedFileException > ( new ThreadSleep ( ) , log , ( ) => Commands . Fetch ( ( Repository ) repositoryInstance , remote , refSpecs , GetFetchOptions ( auth ) , logMessage ) ) . ExecuteAsync ( ) . Wait ( ) ;
198+ RepositoryExtensions . RunSafe ( ( ) =>
199+ {
200+ Commands . Fetch ( ( Repository ) repositoryInstance , remote , refSpecs , GetFetchOptions ( auth ) , logMessage ) ;
201+ } ) ;
199202 }
200203 internal static string Discover ( string path ) => Repository . Discover ( path ) ;
201204
0 commit comments