I am not able to push to an Azure DevOps repository if the project name contains one ore more spaces. I have tested the exact same code with an Azure DevOps repository that is in a project name without spaces and that works. It looks like the %20 in the URL is being unescaped, which causes Azure DevOps to return a 400 Bad Request. All other operations like fetching work just fine.
Reproduction steps
var repository = new LibGit2Sharp.Repository(LibGit2Sharp.Repository.Clone("https://somegitrepositoryurl", "C:\temp\mytempfolder", new CloneOptions
{
Checkout = true,
FetchOptions =
{
CredentialsProvider = new SecureUsernamePasswordCredentials
{
Username = "SomeUsername",
Password = SomePasswordInASecureString
}
}
}));
var remote = _repository.Network.Remotes.Add("target", "https://dev.azure.com/myorganisation/My%20Project%20With%20Spaces/_git/my-repository");
_repository.Network.Push(remote, _repository.Head.CanonicalName, new PushOptions
{
CustomHeaders =
[
$"Authorization: Basic {Convert.ToBase64String("someusername:somepassword"u8.ToArray())}"
]
});
Note that I have first tried using the CredentialsProvider property in PushOptions, but that didn't help. Providing credentials with the custom header works fine in Postman for the same URL.
Expected behavior
Branch is being pushed to Azure DevOps repository.
Actual behavior
Sending GET request to https://dev.azure.com/myorganisation/My Project With Spaces/_git/my-repository/info/refs?service=git-receive-pack
Connecting to remote dev.azure.com port 443
Sending request:
GET /myorganisation/My Project With Spaces/_git/my-repository/info/refs?service=git-receive-pack HTTP/1.1
User-Agent: git/2.0 (libgit2 1.7.1)
Host: dev.azure.com
Accept: */*
Authorization: Basic c29tZXVzZXJuYW1lOnNvbWVwYXNzd29yZA==
Received:
HTTP/1.1 400 Bad Request
Content-Type: text/html; charset=us-ascii
Date: Thu, 18 Jan 2024 13:28:14 GMT
Connection: close
Content-Length: 311
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Bad Request</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Bad Request</h2>
<hr><p>HTTP Error 400. The request is badly formed.</p>
</BODY></HTML>
Version of LibGit2Sharp (release number or SHA1)
0.29.0
Operating system(s) tested; .NET runtime tested
win-x64; .NET 8.0
Let me know if you need any more information or if there's anything I can try to fix it.
My apologies, apparently the library that the URL was being passed through unescaped the URL. Everything is working as it should now. My apologies again!
I am not able to push to an Azure DevOps repository if the project name contains one ore more spaces. I have tested the exact same code with an Azure DevOps repository that is in a project name without spaces and that works. It looks like the %20 in the URL is being unescaped, which causes Azure DevOps to return a 400 Bad Request. All other operations like fetching work just fine.
Reproduction steps
Note that I have first tried using the
CredentialsProvider
property inPushOptions
, but that didn't help. Providing credentials with the custom header works fine in Postman for the same URL.Expected behavior
Branch is being pushed to Azure DevOps repository.
Actual behavior
Version of LibGit2Sharp (release number or SHA1)
0.29.0
Operating system(s) tested; .NET runtime tested
win-x64; .NET 8.0
Let me know if you need any more information or if there's anything I can try to fix it.