Skip to content
This repository was archived by the owner on Jun 27, 2019. It is now read-only.

Fix NullReferenceException for dynamic repositories without authentication #37

Merged
merged 2 commits into from
Nov 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions src/GitTools.Core/GitTools.Core.Shared/Git/AuthenticationInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,5 @@ public class AuthenticationInfo
public string Username { get; set; }
public string Password { get; set; }
public string Token { get; set; }

public FetchOptions ToFetchOptions()
{
var fetchOptions = new FetchOptions();

if (!string.IsNullOrEmpty(Username))
{
fetchOptions.CredentialsProvider = (url, user, types) => new UsernamePasswordCredentials
{
Username = Username,
Password = Password
};
}

return fetchOptions;
}
}
}
18 changes: 11 additions & 7 deletions src/GitTools.Core/GitTools.Core.Shared/Git/DynamicRepositories.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,19 @@ static void CheckoutCommit(IRepository repo, string targetCommit)
static void CloneRepository(string repositoryUrl, string gitDirectory, AuthenticationInfo authentication)
{
Credentials credentials = null;
if (!string.IsNullOrWhiteSpace(authentication.Username) && !string.IsNullOrWhiteSpace(authentication.Password))
{
Log.Info(string.Format("Setting up credentials using name '{0}'", authentication.Username));

credentials = new UsernamePasswordCredentials
if (authentication != null)
{
if (!string.IsNullOrWhiteSpace(authentication.Username) && !string.IsNullOrWhiteSpace(authentication.Password))
{
Username = authentication.Username,
Password = authentication.Password
};
Log.Info(string.Format("Setting up credentials using name '{0}'", authentication.Username));

credentials = new UsernamePasswordCredentials
{
Username = authentication.Username,
Password = authentication.Password
};
}
}

Log.Info(string.Format("Retrieving git info from url '{0}'", repositoryUrl));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
namespace GitTools.Git
{
using LibGit2Sharp;
using Logging;

public static class AuthenticationInfoExtensions
{
private static readonly ILog Log = LogProvider.GetCurrentClassLogger();

public static FetchOptions ToFetchOptions(this AuthenticationInfo authenticationInfo)
{
var fetchOptions = new FetchOptions();

if (authenticationInfo != null)
{
if (!string.IsNullOrEmpty(authenticationInfo.Username))
{
fetchOptions.CredentialsProvider = (url, user, types) => new UsernamePasswordCredentials
{
Username = authenticationInfo.Username,
Password = authenticationInfo.Password
};
}
}

return fetchOptions;
}

public static bool IsEmpty(this AuthenticationInfo authenticationInfo)
{
if (authenticationInfo == null)
Expand Down