libgit2 / libgit2/libgit2sharp
Checkout branch checks out "(no branch)"
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- C#
- Sterne
- 3.5k
- Forks
- 925
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit den im Bericht gezeigten Einstiegspunkten CommitChanges und GetBranch. Reproduziere anschließend den Checkout in der Ubuntu-Pipeline-Umgebung mit LibGit2Sharp 0.27.2 und vergleiche ihn mit Windows 10. Verfolge den von GetBranch zurückgegebenen Branch und das Checkout-Ergebnis; erledigt ist die Aufgabe, wenn die nachfolgenden Logs und der Commit auf dem angeforderten Branch verbleiben und nicht auf "(no branch)" stehen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- csharp, git
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100