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

This commit is contained in:
leo 2025-01-13 17:37:23 +08:00
parent 632222a776
commit 5f4c1bb984
No known key found for this signature in database
3 changed files with 34 additions and 60 deletions

View file

@ -83,6 +83,37 @@ namespace SourceGit.ViewModels
}
}
public void OpenOrInitRepository(string path, RepositoryNode parent, bool bMoveExistedNode)
{
if (!Directory.Exists(path))
{
if (File.Exists(path))
path = Path.GetDirectoryName(path);
else
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))
{
InitRepository(path, parent, test.StdErr);
return;
}
var node = Preferences.Instance.FindOrAddNodeByRepositoryPath(test.StdOut.Trim(), parent, bMoveExistedNode);
Refresh();
var launcher = App.GetLauncer();
launcher?.OpenRepositoryInTab(node, launcher.ActivePage);
}
public void InitRepository(string path, RepositoryNode parent, string reason)
{
if (!Preferences.Instance.IsGitConfigured())