Skip to content

Commit 5eb9751

Browse files
committed
cleanup
1 parent 7e1f875 commit 5eb9751

File tree

3 files changed

+31
-38
lines changed

3 files changed

+31
-38
lines changed

src/GitVersionCore/Core/GitModel.cs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Linq;
55
using GitVersion.Helpers;
66
using LibGit2Sharp;
7-
using LibGit2Sharp.Handlers;
87

98
namespace GitVersion
109
{
@@ -13,37 +12,6 @@ public class AuthenticationInfo
1312
public string Username { get; set; }
1413
public string Password { get; set; }
1514
public string Token { get; set; }
16-
public CredentialsHandler CredentialsProvider()
17-
{
18-
if (!string.IsNullOrWhiteSpace(Username))
19-
{
20-
return (url, user, types) => new UsernamePasswordCredentials
21-
{
22-
Username = Username,
23-
Password = Password ?? string.Empty
24-
};
25-
}
26-
return null;
27-
}
28-
public FetchOptions ToFetchOptions()
29-
{
30-
var fetchOptions = new FetchOptions
31-
{
32-
CredentialsProvider = CredentialsProvider()
33-
};
34-
35-
return fetchOptions;
36-
}
37-
public CloneOptions ToCloneOptions()
38-
{
39-
var cloneOptions = new CloneOptions
40-
{
41-
Checkout = false,
42-
CredentialsProvider = CredentialsProvider()
43-
};
44-
45-
return cloneOptions;
46-
}
4715
}
4816

4917
public class ObjectId
@@ -369,9 +337,6 @@ public class CommitFilter
369337
public CommitSortStrategies SortBy { get; set; }
370338
}
371339

372-
/// <summary>
373-
/// Determines the sorting strategy when iterating through the commits of the repository
374-
/// </summary>
375340
[Flags]
376341
public enum CommitSortStrategies
377342
{

src/GitVersionCore/Core/GitRepository.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static string Clone(string sourceUrl, string workdirPath, AuthenticationI
4040
{
4141
try
4242
{
43-
return Repository.Clone(sourceUrl, workdirPath, auth.ToCloneOptions());
43+
return Repository.Clone(sourceUrl, workdirPath, GetCloneOptions(auth));
4444
}
4545
catch (LibGit2SharpException ex)
4646
{
@@ -124,7 +124,7 @@ public void CreateBranchForPullRequestBranch(ILog log, AuthenticationInfo auth)
124124
var remote = network.Remotes.Single();
125125

126126
log.Info("Fetching remote refs to see if there is a pull request ref");
127-
var credentialsProvider = auth.CredentialsProvider();
127+
var credentialsProvider = GetCredentialsProvider(auth);
128128
var remoteTips = (credentialsProvider != null
129129
? network.ListReferences(remote, credentialsProvider)
130130
: network.ListReferences(remote))
@@ -225,6 +225,34 @@ private void AddMissingRefSpecs(ILog log, LibGit2Sharp.Remote remote)
225225
repositoryInstance.Network.Remotes.Update(remote.Name, r => r.FetchRefSpecs.Add(allBranchesFetchRefSpec));
226226
}
227227

228+
public static FetchOptions GetFetchOptions(AuthenticationInfo auth)
229+
{
230+
return new FetchOptions
231+
{
232+
CredentialsProvider = GetCredentialsProvider(auth)
233+
};
234+
}
235+
private static CloneOptions GetCloneOptions(AuthenticationInfo auth)
236+
{
237+
return new CloneOptions
238+
{
239+
Checkout = false,
240+
CredentialsProvider = GetCredentialsProvider(auth)
241+
};
242+
}
243+
private static CredentialsHandler GetCredentialsProvider(AuthenticationInfo auth)
244+
{
245+
if (!string.IsNullOrWhiteSpace(auth.Username))
246+
{
247+
return (url, user, types) => new UsernamePasswordCredentials
248+
{
249+
Username = auth.Username,
250+
Password = auth.Password ?? string.Empty
251+
};
252+
}
253+
return null;
254+
}
255+
228256
public bool GetMatchingCommitBranch(Commit baseVersionSource, Branch branch, Commit firstMatchingCommit)
229257
{
230258
var filter = new CommitFilter

src/GitVersionCore/Core/GitRepositoryCommands.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void Checkout(Branch branch)
3030

3131
public void Fetch(string remote, IEnumerable<string> refspecs, AuthenticationInfo auth, string logMessage)
3232
{
33-
Commands.Fetch((Repository)repository, remote, refspecs, auth.ToFetchOptions(), logMessage);
33+
Commands.Fetch((Repository)repository, remote, refspecs, GitRepository.GetFetchOptions(auth), logMessage);
3434
}
3535
}
3636
}

0 commit comments

Comments
 (0)