enhance: do not show Initialize Repository popup for bare repositories (#891)

This commit is contained in:
leo 2025-01-13 10:25:58 +08:00
parent a205e17bf2
commit 6e6cd7a7f3
No known key found for this signature in database
2 changed files with 31 additions and 0 deletions

View file

@ -0,0 +1,24 @@
using System.IO;
namespace SourceGit.Commands
{
public class IsBareRepository : Command
{
public IsBareRepository(string path)
{
WorkingDirectory = path;
Args = "rev-parse --is-bare-repository";
}
public bool Result()
{
if (!Directory.Exists(Path.Combine(WorkingDirectory, "refs")) ||
!Directory.Exists(Path.Combine(WorkingDirectory, "objects")) ||
!File.Exists(Path.Combine(WorkingDirectory, "HEAD")))
return false;
var rs = ReadToEnd();
return rs.IsSuccess && rs.StdOut.Trim() == "true";
}
}
}

View file

@ -300,6 +300,13 @@ namespace SourceGit.Views
return; return;
} }
var isBare = new Commands.IsBareRepository(path).Result();
if (isBare)
{
App.RaiseException(string.Empty, $"'{path}' is a bare repository, which is not supported by SourceGit!");
return;
}
var test = new Commands.QueryRepositoryRootPath(path).ReadToEnd(); var test = new Commands.QueryRepositoryRootPath(path).ReadToEnd();
if (!test.IsSuccess || string.IsNullOrEmpty(test.StdOut)) if (!test.IsSuccess || string.IsNullOrEmpty(test.StdOut))
{ {