fix: can not create branch when detached head has extra commits (#344)

This commit is contained in:
leo 2024-08-09 16:59:48 +08:00
parent ed2d3279e1
commit e05264e35d
No known key found for this signature in database

View file

@ -7,7 +7,8 @@ namespace SourceGit.Commands
{ {
private const string PREFIX_LOCAL = "refs/heads/"; private const string PREFIX_LOCAL = "refs/heads/";
private const string PREFIX_REMOTE = "refs/remotes/"; private const string PREFIX_REMOTE = "refs/remotes/";
private const string PREFIX_DETACHED = "(HEAD detached at"; private const string PREFIX_DETACHED_AT = "(HEAD detached at";
private const string PREFIX_DETACHED_FROM = "(HEAD detached from";
public QueryBranches(string repo) public QueryBranches(string repo)
{ {
@ -37,7 +38,7 @@ namespace SourceGit.Commands
if (refName.EndsWith("/HEAD", StringComparison.Ordinal)) if (refName.EndsWith("/HEAD", StringComparison.Ordinal))
return; return;
if (refName.StartsWith(PREFIX_DETACHED, StringComparison.Ordinal)) if (refName.StartsWith(PREFIX_DETACHED_AT, StringComparison.Ordinal) || refName.StartsWith(PREFIX_DETACHED_FROM, StringComparison.Ordinal))
{ {
branch.IsDetachedHead = true; branch.IsDetachedHead = true;
} }