Skip to content

Commit 980397d

Browse files
committed
Uses original method to get remote tips, and overload which takes credentials when username and password are present
1 parent 5552b52 commit 980397d

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

GitVersionCore/BuildServers/GitHelper.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace GitVersion
22
{
3+
using System.Collections.Generic;
34
using System.Linq;
45
using LibGit2Sharp;
56

@@ -73,12 +74,10 @@ static FetchOptions BuildFetchOptions(string username, string password)
7374
static void CreateFakeBranchPointingAtThePullRequestTip(Repository repo, Arguments arguments)
7475
{
7576
var remote = repo.Network.Remotes.Single();
76-
var credentials = string.IsNullOrEmpty(arguments.Username) ? (Credentials) new DefaultCredentials() : new UsernamePasswordCredentials()
77-
{
78-
Username = arguments.Username,
79-
Password = arguments.Password
80-
};
81-
var remoteTips = repo.Network.ListReferences(remote, credentials);
77+
78+
var remoteTips = string.IsNullOrEmpty(arguments.Username) ?
79+
GetRemoteTipsForAnonymousUser(repo, remote) :
80+
GetRemoteTipsUsingUsernamePasswordCredentials(repo, remote, arguments.Username, arguments.Password);
8281

8382
var headTipSha = repo.Head.Tip.Sha;
8483

@@ -115,6 +114,21 @@ static void CreateFakeBranchPointingAtThePullRequestTip(Repository repo, Argumen
115114
repo.Checkout(fakeBranchName);
116115
}
117116

117+
static IEnumerable<DirectReference> GetRemoteTipsUsingUsernamePasswordCredentials(Repository repo, Remote remote, string username, string password)
118+
{
119+
return repo.Network.ListReferences(remote,
120+
new UsernamePasswordCredentials
121+
{
122+
Username = username,
123+
Password = password
124+
});
125+
}
126+
127+
static IEnumerable<DirectReference> GetRemoteTipsForAnonymousUser(Repository repo, Remote remote)
128+
{
129+
return repo.Network.ListReferences(remote);
130+
}
131+
118132
static void CreateMissingLocalBranchesFromRemoteTrackingOnes(Repository repo, string remoteName)
119133
{
120134
var prefix = string.Format("refs/remotes/{0}/", remoteName);

0 commit comments

Comments
 (0)