Skip to content

Commit 6ba0593

Browse files
committed
Teach GitVersion to fetch from private repositories
Fix #85
1 parent f019dc4 commit 6ba0593

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

GitFlowVersion/BuildServers/GitHelper.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace GitFlowVersion.GitFlowVersion
22
{
3+
using System;
34
using System.Linq;
45
using LibGit2Sharp;
56

@@ -14,7 +15,8 @@ public static void NormalizeGitDirectory(string gitDirectory)
1415
Logger.WriteInfo(string.Format("Fetching from remote '{0}' using the following refspecs: {1}.",
1516
remote.Name, string.Join(", ", remote.FetchRefSpecs.Select(r => r.Specification))));
1617

17-
repo.Network.Fetch(remote);
18+
var fetchOptions = BuildFetchOptions();
19+
repo.Network.Fetch(remote, fetchOptions);
1820

1921
CreateMissingLocalBranchesFromRemoteTrackingOnes(repo, remote.Name);
2022

@@ -30,6 +32,21 @@ public static void NormalizeGitDirectory(string gitDirectory)
3032
}
3133
}
3234

35+
static FetchOptions BuildFetchOptions()
36+
{
37+
var username = Environment.GetEnvironmentVariable("GITVERSION_REMOTE_USERNAME");
38+
var password = Environment.GetEnvironmentVariable("GITVERSION_REMOTE_PASSWORD");
39+
40+
var fetchOptions = new FetchOptions();
41+
42+
if (!string.IsNullOrEmpty(username))
43+
{
44+
fetchOptions.Credentials = new Credentials { Username = username, Password = password };
45+
}
46+
47+
return fetchOptions;
48+
}
49+
3350
static void CreateFakeBranchPointingAtThePullRequestTip(Repository repo)
3451
{
3552
var remote = repo.Network.Remotes.Single();

0 commit comments

Comments
 (0)