mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2025-01-23 01:36:57 -08:00
enhance: do not show Initialize Repository
popup for bare repositories (#891)
This commit is contained in:
parent
632222a776
commit
5f4c1bb984
3 changed files with 34 additions and 60 deletions
|
@ -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())
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
|
@ -197,7 +196,7 @@ namespace SourceGit.Views
|
|||
{
|
||||
foreach (var item in items)
|
||||
{
|
||||
OpenOrInitRepository(item.Path.LocalPath);
|
||||
ViewModels.Welcome.Instance.OpenOrInitRepository(item.Path.LocalPath, null, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -261,7 +260,7 @@ namespace SourceGit.Views
|
|||
{
|
||||
foreach (var item in items)
|
||||
{
|
||||
OpenOrInitRepository(item.Path.LocalPath, to);
|
||||
ViewModels.Welcome.Instance.OpenOrInitRepository(item.Path.LocalPath, to, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -290,37 +289,6 @@ namespace SourceGit.Views
|
|||
}
|
||||
}
|
||||
|
||||
private void OpenOrInitRepository(string path, ViewModels.RepositoryNode parent = null)
|
||||
{
|
||||
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))
|
||||
{
|
||||
ViewModels.Welcome.Instance.InitRepository(path, parent, test.StdErr);
|
||||
return;
|
||||
}
|
||||
|
||||
var node = ViewModels.Preferences.Instance.FindOrAddNodeByRepositoryPath(test.StdOut.Trim(), parent, true);
|
||||
ViewModels.Welcome.Instance.Refresh();
|
||||
|
||||
var launcher = this.FindAncestorOfType<Launcher>()?.DataContext as ViewModels.Launcher;
|
||||
launcher?.OpenRepositoryInTab(node, launcher.ActivePage);
|
||||
}
|
||||
|
||||
private bool _pressedTreeNode = false;
|
||||
private Point _pressedTreeNodePosition = new Point();
|
||||
private bool _startDragTreeNode = false;
|
||||
|
|
|
@ -4,7 +4,6 @@ using System.IO;
|
|||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Platform.Storage;
|
||||
using Avalonia.VisualTree;
|
||||
|
||||
namespace SourceGit.Views
|
||||
{
|
||||
|
@ -36,7 +35,7 @@ namespace SourceGit.Views
|
|||
{
|
||||
var selected = await topLevel.StorageProvider.OpenFolderPickerAsync(options);
|
||||
if (selected.Count == 1)
|
||||
OpenOrInitRepository(selected[0].Path.LocalPath);
|
||||
ViewModels.Welcome.Instance.OpenOrInitRepository(selected[0].Path.LocalPath, null, false);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
|
@ -45,30 +44,6 @@ namespace SourceGit.Views
|
|||
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void OpenOrInitRepository(string path, ViewModels.RepositoryNode parent = null)
|
||||
{
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
if (File.Exists(path))
|
||||
path = Path.GetDirectoryName(path);
|
||||
else
|
||||
return;
|
||||
}
|
||||
|
||||
var test = new Commands.QueryRepositoryRootPath(path).ReadToEnd();
|
||||
if (!test.IsSuccess || string.IsNullOrEmpty(test.StdOut))
|
||||
{
|
||||
ViewModels.Welcome.Instance.InitRepository(path, parent, test.StdErr);
|
||||
return;
|
||||
}
|
||||
|
||||
var node = ViewModels.Preferences.Instance.FindOrAddNodeByRepositoryPath(test.StdOut.Trim(), parent, false);
|
||||
ViewModels.Welcome.Instance.Refresh();
|
||||
|
||||
var launcher = this.FindAncestorOfType<Launcher>()?.DataContext as ViewModels.Launcher;
|
||||
launcher?.OpenRepositoryInTab(node, launcher.ActivePage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue