From 5f2fe64e8097cdfe3990b9d714e95770cdc0fc80 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 1 Feb 2021 09:39:14 +0800 Subject: [PATCH] feature: supports to open repository from commandline directly --- src/App.xaml.cs | 7 ++++++- src/Git/Repository.cs | 2 ++ src/UI/Launcher.xaml.cs | 10 ++++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/App.xaml.cs b/src/App.xaml.cs index a577fc6f..b98da657 100644 --- a/src/App.xaml.cs +++ b/src/App.xaml.cs @@ -139,9 +139,14 @@ namespace SourceGit { } // Show main window - MainWindow = new UI.Launcher(); + if (e.Args.Length == 1) { + MainWindow = new UI.Launcher(e.Args[0]); + } else { + MainWindow = new UI.Launcher(null); + } MainWindow.Show(); + // Check for update. if (Setting.CheckUpdate && Setting.LastCheckUpdate != DateTime.Now.DayOfYear) { Setting.LastCheckUpdate = DateTime.Now.DayOfYear; diff --git a/src/Git/Repository.cs b/src/Git/Repository.cs index 39a30766..3280185f 100644 --- a/src/Git/Repository.cs +++ b/src/Git/Repository.cs @@ -212,6 +212,8 @@ namespace SourceGit.Git { /// Local path. /// public static bool IsValid(string path) { + if (!Directory.Exists(path)) return false; + var startInfo = new ProcessStartInfo(); startInfo.FileName = App.Setting.Tools.GitExecutable; startInfo.Arguments = "rev-parse --git-dir"; diff --git a/src/UI/Launcher.xaml.cs b/src/UI/Launcher.xaml.cs index e3a4e633..609b0f1c 100644 --- a/src/UI/Launcher.xaml.cs +++ b/src/UI/Launcher.xaml.cs @@ -95,9 +95,15 @@ namespace SourceGit.UI { /// /// Constructor /// - public Launcher() { + public Launcher(string path) { InitializeComponent(); - NewTab(null, null); + if (path != null && App.IsGitConfigured && Git.Repository.IsValid(path)) { + var repo = App.Setting.FindRepository(path); + if (repo == null) repo = App.Setting.AddRepository(path, ""); + Open(repo); + } else { + NewTab(null, null); + } } ///