From 8d6481c69484ae22e40269e2f514273516277ece Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 20 May 2024 14:39:05 +0800 Subject: [PATCH] feature: supports to open a repository directly from commandline (#134) --- src/ViewModels/Launcher.cs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/ViewModels/Launcher.cs b/src/ViewModels/Launcher.cs index 7d0c9197..c2e57b49 100644 --- a/src/ViewModels/Launcher.cs +++ b/src/ViewModels/Launcher.cs @@ -32,7 +32,27 @@ namespace SourceGit.ViewModels Pages = new AvaloniaList(); AddNewTab(); - if (Preference.Instance.RestoreTabs) + var commandlines = Environment.GetCommandLineArgs(); + if (commandlines.Length == 2) + { + var path = commandlines[1].Replace('\\', '/'); + var root = new Commands.QueryRepositoryRootPath(path).Result(); + if (string.IsNullOrEmpty(root)) + { + Pages[0].Notifications.Add(new Models.Notification + { + IsError = true, + Message = $"Given path: '{commandlines[1]}' is NOT a valid repository!" + }); + return; + } + + var gitDir = new Commands.QueryGitDir(root).Result(); + var repo = Preference.AddRepository(root, gitDir); + var node = Preference.FindOrAddNodeByRepositoryPath(repo.FullPath, null); + OpenRepositoryInTab(node, null); + } + else if (Preference.Instance.RestoreTabs) { foreach (var id in Preference.Instance.OpenedTabs) {