libgit2 / libgit2/libgit2sharp
Checkout branch checks out "(no branch)"
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- C#
- Estrellas
- 3.5k
- Forks
- 925
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con los puntos de entrada CommitChanges y GetBranch que se muestran en el informe, luego reproduce el checkout en el entorno de la pipeline de Ubuntu usando LibGit2Sharp 0.27.2 y compáralo con Windows 10. Traza la rama devuelta por GetBranch y el resultado del checkout; se considera terminado cuando los logs posteriores y el commit permanecen en la rama solicitada en lugar de aparecer como "(no branch)".
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- csharp, git
- Área
- devtools
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100