libgit2 / libgit2/libgit2sharp
Checkout branch checks out "(no branch)"
Personne n'a encore pris cette issue.
- Langage dominant
- C#
- Étoiles
- 3.5k
- Forks
- 925
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
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
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par les points d’entrée CommitChanges et GetBranch présentés dans le rapport, puis reproduisez le checkout dans l’environnement du pipeline Ubuntu avec LibGit2Sharp 0.27.2 et comparez-le à Windows 10. Suivez la branche renvoyée par GetBranch et le résultat du checkout ; c’est terminé lorsque les logs suivants et le commit restent sur la branche demandée plutôt que sur "(no branch)".
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- csharp, git
- Domaine
- devtools
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100