Skip to content

Conversation

@maxild
Copy link
Contributor

@maxild maxild commented Apr 28, 2020

This is to avoid runtime errors when using personal access tokens to authenticate
when fetching etc. from private github repos.

The standard way to authenticate:

new UsernamePasswordCredentials
{
Username = "github-personal-access-token", // GITVERSION_REMOTE_USERNAME
Password = string.Empty
};

GitVersion should support this authentication scheme necessary when having 2FA.

When using environment variables to propagate credentials password will end up
being null, because GITVERSION_REMOTE_PASSWORD is not present when passing empty
value.

This commit guards against libgit2sharp throwing LibGit2SharpException:
"UsernamePasswordCredentials contains a null Username or Password."

Description, Motivation and Context

Fixes #2247.

How Has This Been Tested?

I have cross-compiled (self-contained) gitversion.exe for win-x64 and seen that all my builds of private github repos with this 5.2.5-xxxx does succeed again.

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

My change can be done in various ways. 3 changes (in 3 different files) are where UsernamePasswordCredentials are instantiated and passed to libgit2sharp. Feel free to refactor.
No tests, because the change is trivial, and should not break anybodys use of gitversion.

…word.

It also supports null/empty password, but guards against passing null to
libgit2sharp.

This is to avoid runtime errors when using personal access tokens to authenticate
when fetching etc. from private github repos.

The standard way to authenticate:

new UsernamePasswordCredentials
{
    Username = "<github-personal-access-token>", // GITVERSION_REMOTE_USERNAME
    Password = string.Empty
};

GitVersion should support this authentication scheme necessary when having 2FA.

When using environment variables to propagate credentials password will end up
being null, because GITVERSION_REMOTE_PASSWORD is not present when passing empty
value.

This commit guards against libgit2sharp throwing LibGit2SharpException:
"UsernamePasswordCredentials contains a null Username or Password."
@arturcic arturcic merged commit be6b65f into GitTools:master Apr 28, 2020
@arturcic
Copy link
Member

Thanks for figuring out! It will be released in 5.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] GitVersion must ensure non-null password

2 participants