diff --git a/src/Commands/IsBareRepository.cs b/src/Commands/IsBareRepository.cs new file mode 100644 index 00000000..f92d0888 --- /dev/null +++ b/src/Commands/IsBareRepository.cs @@ -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"; + } + } +} diff --git a/src/Views/Welcome.axaml.cs b/src/Views/Welcome.axaml.cs index 3400d0d8..ffb8332b 100644 --- a/src/Views/Welcome.axaml.cs +++ b/src/Views/Welcome.axaml.cs @@ -300,6 +300,13 @@ namespace SourceGit.Views 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(); if (!test.IsSuccess || string.IsNullOrEmpty(test.StdOut)) {