libgit2 / libgit2/libgit2sharp
Checkout branch checks out "(no branch)"
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- C#
- Star
- 3.5k
- Fork
- 925
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
I encountered a Bug where Checkout would not checkout the provided branch, but rather nothing (?). This somehow does not occur on my local dev-machine, but only on our pipeline agent.
Reproduction steps
This is my code to commit my changes
public Commit? CommitChanges(SemVersion newVersion)
{
using var repo = new Repository(_executionSettings.Git.CloneTarget);
_logger.LogInformation("{head}", repo.Head.FriendlyName);
var status = repo.RetrieveStatus();
if (!status.IsDirty)
{
_logger.LogInformation("No changes in repository, skipping commit");
return null;
}
var targetBranch = LibGit2Sharp.Commands.Checkout(repo, GetBranch(repo, _executionSettings.Git.TargetBranch));
_logger.LogInformation("{head}", repo.Head.FriendlyName);
LibGit2Sharp.Commands.Stage(repo, new[]
{
_executionSettings.FileNames.Changelog,
_executionSettings.FileNames.Version
});
var author = new Signature("Version Agent", "versionagent@example.com", DateTimeOffset.Now);
var commitMessage = $"chore(release): Released {newVersion} to production";
_logger.LogInformation("{head}", repo.Head.FriendlyName);
var commit = repo.Commit(commitMessage, author, author);
_logger.LogInformation("{head}", repo.Head.FriendlyName);
_logger.LogInformation("Commited new changes");
return commit;
}
And this loads the provided branch.
private Branch GetBranch(Repository repo, string branchName)
{
var branch = repo.Branches.SingleOrDefault(branch => branch.FriendlyName == branchName);
if (branch == null)
{
throw new ArgumentException($"Could not find branch '{branchName}'. Did you mean to use 'origin/{branchName}' instead?");
}
_logger.LogInformation("Found branch '{branchName}' with head at {headSha}", branch.CanonicalName, branch.Commits.First().Sha);
return branch;
}
Expected behavior
I would except, that every logging statement would print "develop"
Actual behavior
Only the first logging prints "develop". The following only print "(no branch)"
Version of LibGit2Sharp (release number or SHA1)
0.27.2
Operating system(s) tested; .NET runtime tested
Local dev-machine: Windows 10
Pipeline: ubuntu
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với các entry point CommitChanges và GetBranch được nêu trong báo cáo, sau đó tái hiện checkout trong môi trường pipeline Ubuntu bằng LibGit2Sharp 0.27.2 và so sánh với Windows 10. Theo dõi branch được GetBranch trả về và kết quả checkout; được xem là hoàn tất khi các log tiếp theo và commit vẫn ở trên branch được yêu cầu thay vì ở "(no branch)".
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- csharp, git
- Lĩnh vực
- devtools
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100