Skip to content

Commit a4a89a3

Browse files
Getting the HEAD commit of a branch with a slash fails (#891)
* Getting the HEAD commit of a branch with a slash fails * Add test
1 parent 2feda60 commit a4a89a3

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

NGitLab.Tests/CommitsTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@ public async Task Test_can_get_commit()
2222
Assert.That(commit.ShortId, Is.Not.Null);
2323
}
2424

25+
[Test]
26+
[NGitLabRetry]
27+
public async Task Test_can_get_commit_of_branch()
28+
{
29+
using var context = await GitLabTestContext.CreateAsync();
30+
var project = context.CreateProject(initializeWithCommits: true);
31+
32+
var branch = context.Client.GetRepository(project.Id).Branches.Create(new()
33+
{
34+
Name = "feature/my-branch",
35+
Ref = project.DefaultBranch,
36+
});
37+
38+
var commit = context.Client.GetCommits(project.Id).GetCommit(branch.Name);
39+
Assert.That(commit.Message, Is.Not.Null);
40+
Assert.That(commit.ShortId, Is.Not.Null);
41+
}
42+
2543
[Test]
2644
[NGitLabRetry]
2745
public async Task Test_can_get_stats_in_commit()

NGitLab/Impl/CommitClient.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ public CommitClient(API api, ProjectId projectId)
1818

1919
public Commit GetCommit(string @ref)
2020
{
21-
return _api.Get().To<Commit>(_repoPath + $"/commits/{@ref}");
21+
var encodedRef = WebUtility.UrlEncode(@ref);
22+
23+
return _api.Get().To<Commit>(_repoPath + $"/commits/{encodedRef}");
2224
}
2325

2426
public Commit CherryPick(CommitCherryPick cherryPick)

0 commit comments

Comments
 (0)