Skip to content

Commit 6e6cd7a

Browse files
committed
enhance: do not show Initialize Repository popup for bare repositories (#891)
1 parent a205e17 commit 6e6cd7a

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/Commands/IsBareRepository.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.IO;
2+
3+
namespace SourceGit.Commands
4+
{
5+
public class IsBareRepository : Command
6+
{
7+
public IsBareRepository(string path)
8+
{
9+
WorkingDirectory = path;
10+
Args = "rev-parse --is-bare-repository";
11+
}
12+
13+
public bool Result()
14+
{
15+
if (!Directory.Exists(Path.Combine(WorkingDirectory, "refs")) ||
16+
!Directory.Exists(Path.Combine(WorkingDirectory, "objects")) ||
17+
!File.Exists(Path.Combine(WorkingDirectory, "HEAD")))
18+
return false;
19+
20+
var rs = ReadToEnd();
21+
return rs.IsSuccess && rs.StdOut.Trim() == "true";
22+
}
23+
}
24+
}

src/Views/Welcome.axaml.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,13 @@ private void OpenOrInitRepository(string path, ViewModels.RepositoryNode parent
300300
return;
301301
}
302302

303+
var isBare = new Commands.IsBareRepository(path).Result();
304+
if (isBare)
305+
{
306+
App.RaiseException(string.Empty, $"'{path}' is a bare repository, which is not supported by SourceGit!");
307+
return;
308+
}
309+
303310
var test = new Commands.QueryRepositoryRootPath(path).ReadToEnd();
304311
if (!test.IsSuccess || string.IsNullOrEmpty(test.StdOut))
305312
{

0 commit comments

Comments
 (0)