@@ -98,77 +98,74 @@ private int GetNumberOfUncommittedChangesInternal()
98
98
}
99
99
public void CreateBranchForPullRequestBranch ( AuthenticationInfo auth )
100
100
{
101
- new OperationWithExponentialBackoff < LockedFileException > ( new ThreadSleep ( ) , log , ( ) =>
101
+ RepositoryExtensions . RunSafe ( ( ) =>
102
102
{
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 ( ) ;
110
105
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 ( ) ;
117
112
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 ) ) ) ;
119
114
120
- var headTipSha = Head . Tip ? . Sha ;
115
+ var headTipSha = Head . Tip ? . Sha ;
121
116
122
- var refs = remoteTips . Where ( r => r . TargetIdentifier == headTipSha ) . ToList ( ) ;
117
+ var refs = remoteTips . Where ( r => r . TargetIdentifier == headTipSha ) . ToList ( ) ;
123
118
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
+ }
129
124
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
+ }
136
131
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 } '.") ;
141
136
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/" ) ;
150
145
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 ) ;
153
148
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
+ } ) ;
162
158
}
163
159
public void Clone ( string sourceUrl , string workdirPath , AuthenticationInfo auth )
164
160
{
165
161
try
166
162
{
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 ) ;
172
169
}
173
170
catch ( LibGit2SharpException ex )
174
171
{
@@ -191,11 +188,17 @@ public void Clone(string sourceUrl, string workdirPath, AuthenticationInfo auth)
191
188
}
192
189
public void Checkout ( string commitOrBranchSpec )
193
190
{
194
- new OperationWithExponentialBackoff < LockedFileException > ( new ThreadSleep ( ) , log , ( ) => Commands . Checkout ( repositoryInstance , commitOrBranchSpec ) ) . ExecuteAsync ( ) . Wait ( ) ;
191
+ RepositoryExtensions . RunSafe ( ( ) =>
192
+ {
193
+ Commands . Checkout ( repositoryInstance , commitOrBranchSpec ) ;
194
+ } ) ;
195
195
}
196
196
public void Fetch ( string remote , IEnumerable < string > refSpecs , AuthenticationInfo auth , string logMessage )
197
197
{
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
+ } ) ;
199
202
}
200
203
internal static string Discover ( string path ) => Repository . Discover ( path ) ;
201
204
0 commit comments