From e63034acd570eb3269f0266075e511da02d786c4 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 9 Sep 2024 19:14:44 +0800 Subject: [PATCH] enhance: when open repository from commandline, create a new workspace `Unnamed` for it, and never add it to preference (#445) --- src/ViewModels/Launcher.cs | 44 ++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/src/ViewModels/Launcher.cs b/src/ViewModels/Launcher.cs index c734e726..00080bcc 100644 --- a/src/ViewModels/Launcher.cs +++ b/src/ViewModels/Launcher.cs @@ -35,36 +35,38 @@ namespace SourceGit.ViewModels public Launcher(string startupRepo) { - var pref = Preference.Instance; - Pages = new AvaloniaList(); - ActiveWorkspace = pref.GetActiveWorkspace(); AddNewTab(); - var repos = _activeWorkspace.Repositories.ToArray(); - foreach (var repo in repos) - { - var node = pref.FindNode(repo); - if (node == null) - { - node = new RepositoryNode() - { - Id = repo, - Name = Path.GetFileName(repo), - Bookmark = 0, - IsRepository = true, - }; - } - - OpenRepositoryInTab(node, null); - } - + var pref = Preference.Instance; if (string.IsNullOrEmpty(startupRepo)) { + ActiveWorkspace = pref.GetActiveWorkspace(); + + var repos = ActiveWorkspace.Repositories.ToArray(); + foreach (var repo in repos) + { + var node = pref.FindNode(repo); + if (node == null) + { + node = new RepositoryNode() + { + Id = repo, + Name = Path.GetFileName(repo), + Bookmark = 0, + IsRepository = true, + }; + } + + OpenRepositoryInTab(node, null); + } + ActivePage = Pages[0]; } else { + ActiveWorkspace = new Workspace() { Name = "Unnamed", Color = 4278221015 }; + var test = new Commands.QueryRepositoryRootPath(startupRepo).ReadToEnd(); if (!test.IsSuccess || string.IsNullOrEmpty(test.StdOut)) {