feature: supports to open a repository directly from commandline (#134)

This commit is contained in:
leo 2024-05-20 14:39:05 +08:00
parent 67e8f35b47
commit 8d6481c694

View file

@ -32,7 +32,27 @@ namespace SourceGit.ViewModels
Pages = new AvaloniaList<LauncherPage>(); Pages = new AvaloniaList<LauncherPage>();
AddNewTab(); 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) foreach (var id in Preference.Instance.OpenedTabs)
{ {