|
1 | 1 | namespace GitVersion
|
2 | 2 | {
|
| 3 | + using System.Collections.Generic; |
3 | 4 | using System.Linq;
|
4 | 5 | using LibGit2Sharp;
|
5 | 6 |
|
@@ -73,12 +74,10 @@ static FetchOptions BuildFetchOptions(string username, string password)
|
73 | 74 | static void CreateFakeBranchPointingAtThePullRequestTip(Repository repo, Arguments arguments)
|
74 | 75 | {
|
75 | 76 | 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); |
82 | 81 |
|
83 | 82 | var headTipSha = repo.Head.Tip.Sha;
|
84 | 83 |
|
@@ -115,6 +114,21 @@ static void CreateFakeBranchPointingAtThePullRequestTip(Repository repo, Argumen
|
115 | 114 | repo.Checkout(fakeBranchName);
|
116 | 115 | }
|
117 | 116 |
|
| 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 | + |
118 | 132 | static void CreateMissingLocalBranchesFromRemoteTrackingOnes(Repository repo, string remoteName)
|
119 | 133 | {
|
120 | 134 | var prefix = string.Format("refs/remotes/{0}/", remoteName);
|
|
0 commit comments