Skip to content

Commit 5f4c1bb

Browse files
committed
enhance: do not show Initialize Repository popup for bare repositories (#891)
1 parent 632222a commit 5f4c1bb

File tree

3 files changed

+34
-60
lines changed

3 files changed

+34
-60
lines changed

src/ViewModels/Welcome.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,37 @@ public void ToggleNodeIsExpanded(RepositoryNode node)
8383
}
8484
}
8585

86+
public void OpenOrInitRepository(string path, RepositoryNode parent, bool bMoveExistedNode)
87+
{
88+
if (!Directory.Exists(path))
89+
{
90+
if (File.Exists(path))
91+
path = Path.GetDirectoryName(path);
92+
else
93+
return;
94+
}
95+
96+
var isBare = new Commands.IsBareRepository(path).Result();
97+
if (isBare)
98+
{
99+
App.RaiseException(string.Empty, $"'{path}' is a bare repository, which is not supported by SourceGit!");
100+
return;
101+
}
102+
103+
var test = new Commands.QueryRepositoryRootPath(path).ReadToEnd();
104+
if (!test.IsSuccess || string.IsNullOrEmpty(test.StdOut))
105+
{
106+
InitRepository(path, parent, test.StdErr);
107+
return;
108+
}
109+
110+
var node = Preferences.Instance.FindOrAddNodeByRepositoryPath(test.StdOut.Trim(), parent, bMoveExistedNode);
111+
Refresh();
112+
113+
var launcher = App.GetLauncer();
114+
launcher?.OpenRepositoryInTab(node, launcher.ActivePage);
115+
}
116+
86117
public void InitRepository(string path, RepositoryNode parent, string reason)
87118
{
88119
if (!Preferences.Instance.IsGitConfigured())

src/Views/Welcome.axaml.cs

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.IO;
32

43
using Avalonia;
54
using Avalonia.Controls;
@@ -197,7 +196,7 @@ private void DropOnTreeView(object sender, DragEventArgs e)
197196
{
198197
foreach (var item in items)
199198
{
200-
OpenOrInitRepository(item.Path.LocalPath);
199+
ViewModels.Welcome.Instance.OpenOrInitRepository(item.Path.LocalPath, null, true);
201200
break;
202201
}
203202
}
@@ -261,7 +260,7 @@ private void DropOnTreeNode(object sender, DragEventArgs e)
261260
{
262261
foreach (var item in items)
263262
{
264-
OpenOrInitRepository(item.Path.LocalPath, to);
263+
ViewModels.Welcome.Instance.OpenOrInitRepository(item.Path.LocalPath, to, true);
265264
break;
266265
}
267266
}
@@ -290,37 +289,6 @@ private void OnDoubleTappedTreeNode(object sender, TappedEventArgs e)
290289
}
291290
}
292291

293-
private void OpenOrInitRepository(string path, ViewModels.RepositoryNode parent = null)
294-
{
295-
if (!Directory.Exists(path))
296-
{
297-
if (File.Exists(path))
298-
path = Path.GetDirectoryName(path);
299-
else
300-
return;
301-
}
302-
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-
310-
var test = new Commands.QueryRepositoryRootPath(path).ReadToEnd();
311-
if (!test.IsSuccess || string.IsNullOrEmpty(test.StdOut))
312-
{
313-
ViewModels.Welcome.Instance.InitRepository(path, parent, test.StdErr);
314-
return;
315-
}
316-
317-
var node = ViewModels.Preferences.Instance.FindOrAddNodeByRepositoryPath(test.StdOut.Trim(), parent, true);
318-
ViewModels.Welcome.Instance.Refresh();
319-
320-
var launcher = this.FindAncestorOfType<Launcher>()?.DataContext as ViewModels.Launcher;
321-
launcher?.OpenRepositoryInTab(node, launcher.ActivePage);
322-
}
323-
324292
private bool _pressedTreeNode = false;
325293
private Point _pressedTreeNodePosition = new Point();
326294
private bool _startDragTreeNode = false;

src/Views/WelcomeToolbar.axaml.cs

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using Avalonia.Controls;
55
using Avalonia.Interactivity;
66
using Avalonia.Platform.Storage;
7-
using Avalonia.VisualTree;
87

98
namespace SourceGit.Views
109
{
@@ -36,7 +35,7 @@ private async void OpenLocalRepository(object _1, RoutedEventArgs e)
3635
{
3736
var selected = await topLevel.StorageProvider.OpenFolderPickerAsync(options);
3837
if (selected.Count == 1)
39-
OpenOrInitRepository(selected[0].Path.LocalPath);
38+
ViewModels.Welcome.Instance.OpenOrInitRepository(selected[0].Path.LocalPath, null, false);
4039
}
4140
catch (Exception exception)
4241
{
@@ -45,30 +44,6 @@ private async void OpenLocalRepository(object _1, RoutedEventArgs e)
4544

4645
e.Handled = true;
4746
}
48-
49-
private void OpenOrInitRepository(string path, ViewModels.RepositoryNode parent = null)
50-
{
51-
if (!Directory.Exists(path))
52-
{
53-
if (File.Exists(path))
54-
path = Path.GetDirectoryName(path);
55-
else
56-
return;
57-
}
58-
59-
var test = new Commands.QueryRepositoryRootPath(path).ReadToEnd();
60-
if (!test.IsSuccess || string.IsNullOrEmpty(test.StdOut))
61-
{
62-
ViewModels.Welcome.Instance.InitRepository(path, parent, test.StdErr);
63-
return;
64-
}
65-
66-
var node = ViewModels.Preferences.Instance.FindOrAddNodeByRepositoryPath(test.StdOut.Trim(), parent, false);
67-
ViewModels.Welcome.Instance.Refresh();
68-
69-
var launcher = this.FindAncestorOfType<Launcher>()?.DataContext as ViewModels.Launcher;
70-
launcher?.OpenRepositoryInTab(node, launcher.ActivePage);
71-
}
7247
}
7348
}
7449

0 commit comments

Comments
 (0)