diff --git a/src/Commands/Command.cs b/src/Commands/Command.cs index 26083ef9..b347dc37 100644 --- a/src/Commands/Command.cs +++ b/src/Commands/Command.cs @@ -17,8 +17,9 @@ namespace SourceGit.Commands public class ReadToEndResult { - public bool IsSuccess { get; set; } - public string StdOut { get; set; } + public bool IsSuccess { get; set; } = false; + public string StdOut { get; set; } = ""; + public string StdErr { get; set; } = ""; } public enum EditorType @@ -198,18 +199,20 @@ namespace SourceGit.Commands { proc.Start(); } - catch + catch (Exception e) { return new ReadToEndResult() { IsSuccess = false, StdOut = string.Empty, + StdErr = e.Message, }; } var rs = new ReadToEndResult() { StdOut = proc.StandardOutput.ReadToEnd(), + StdErr = proc.StandardError.ReadToEnd(), }; proc.WaitForExit(); diff --git a/src/Commands/QueryRepositoryRootPath.cs b/src/Commands/QueryRepositoryRootPath.cs index 1eef5af8..016621c8 100644 --- a/src/Commands/QueryRepositoryRootPath.cs +++ b/src/Commands/QueryRepositoryRootPath.cs @@ -6,15 +6,6 @@ { WorkingDirectory = path; Args = "rev-parse --show-toplevel"; - RaiseError = false; - } - - public string Result() - { - var rs = ReadToEnd().StdOut; - if (string.IsNullOrEmpty(rs)) - return null; - return rs.Trim(); } } } diff --git a/src/Resources/Locales/de_DE.axaml b/src/Resources/Locales/de_DE.axaml index 3752841a..fccc64cc 100644 --- a/src/Resources/Locales/de_DE.axaml +++ b/src/Resources/Locales/de_DE.axaml @@ -334,7 +334,6 @@ Verwerfen Initialisiere Repository Pfad: - Ungültiges Repository erkannt. `git init` auf diesem Pfad ausführen? Cherry-Pick wird durchgeführt. Drücke 'Abbrechen' um den originalen HEAD wiederherzustellen. Merge request wird durchgeführt. Drücke 'Abbrechen' um den originalen HEAD wiederherzustellen. Rebase wird durchgeführt. Drücke 'Abbrechen' um den originalen HEAD wiederherzustellen. diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index ae155fc8..7b89ddce 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -336,7 +336,6 @@ Discard Initialize Repository Path: - Invalid repository detected. Run `git init` under this path? Cherry-Pick in progress. Press 'Abort' to restore original HEAD. Merge request in progress. Press 'Abort' to restore original HEAD. Rebase in progress. Press 'Abort' to restore original HEAD. diff --git a/src/Resources/Locales/fr_FR.axaml b/src/Resources/Locales/fr_FR.axaml index ac7265c5..1aa3f472 100644 --- a/src/Resources/Locales/fr_FR.axaml +++ b/src/Resources/Locales/fr_FR.axaml @@ -337,7 +337,6 @@ Rejeter Initialize Repository Path: - Invalid repository detected. Run `git init` under this path? Cherry-Pick in progress. Press 'Abort' to restore original HEAD. Merge request in progress. Press 'Abort' to restore original HEAD. Rebase in progress. Press 'Abort' to restore original HEAD. diff --git a/src/Resources/Locales/pt_BR.axaml b/src/Resources/Locales/pt_BR.axaml index 7d6f8cee..5a746781 100644 --- a/src/Resources/Locales/pt_BR.axaml +++ b/src/Resources/Locales/pt_BR.axaml @@ -332,7 +332,6 @@ Descartar Inicializar Repositório Caminho: - Repositório inválido detectado. Executar `git init` neste caminho? Cherry-Pick em andamento. Pressione 'Abort' para restaurar o HEAD original. Merge em andamento. Pressione 'Abort' para restaurar o HEAD original. Rebase em andamento. Pressione 'Abort' para restaurar o HEAD original. diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 0c3e22d8..aab30260 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -339,7 +339,6 @@ 丢弃 初始化新仓库 路径 : - 选择目录不是有效的Git仓库。是否需要在此目录执行`git init`操作? 挑选(Cherry-Pick)操作进行中。点击【终止】回滚到操作前的状态。 合并操作进行中。点击【终止】回滚到操作前的状态。 变基(Rebase)操作进行中。点击【终止】回滚到操作前的状态。 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index 1d58104c..b44618ce 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -339,7 +339,6 @@ 捨棄 初始化存放庫 路徑: - 選擇目錄並非有效的 Git 存放庫。是否要在此目錄執行 `git init` 以進行初始化? 揀選 (cherry-pick) 操作進行中。點選 [中止] 復原到操作前的狀態。 合併操作進行中。點選 [中止] 復原到操作前的狀態。 重定基底 (rebase) 操作進行中。點選 [中止] 復原到操作前的狀態。 diff --git a/src/ViewModels/Init.cs b/src/ViewModels/Init.cs index 78b85e8d..913127a1 100644 --- a/src/ViewModels/Init.cs +++ b/src/ViewModels/Init.cs @@ -10,11 +10,18 @@ namespace SourceGit.ViewModels set => SetProperty(ref _targetPath, value); } - public Init(string path, RepositoryNode parent) + public string Reason + { + get; + private set; + } + + public Init(string path, RepositoryNode parent, string reason) { _targetPath = path; _parentNode = parent; + Reason = string.IsNullOrEmpty(reason) ? "Invalid repository detected!" : reason; View = new Views.Init() { DataContext = this }; } diff --git a/src/ViewModels/Launcher.cs b/src/ViewModels/Launcher.cs index 7e5fdad0..525e7ee9 100644 --- a/src/ViewModels/Launcher.cs +++ b/src/ViewModels/Launcher.cs @@ -35,8 +35,8 @@ namespace SourceGit.ViewModels var pref = Preference.Instance; if (!string.IsNullOrEmpty(startupRepo)) { - var root = new Commands.QueryRepositoryRootPath(startupRepo).Result(); - if (string.IsNullOrEmpty(root)) + var test = new Commands.QueryRepositoryRootPath(startupRepo).ReadToEnd(); + if (!test.IsSuccess || string.IsNullOrEmpty(test.StdOut)) { Pages[0].Notifications.Add(new Models.Notification { @@ -46,7 +46,7 @@ namespace SourceGit.ViewModels return; } - var normalized = root.Replace("\\", "/"); + var normalized = test.StdOut.Trim().Replace("\\", "/"); var node = pref.FindOrAddNodeByRepositoryPath(normalized, null, false); Welcome.Instance.Refresh(); OpenRepositoryInTab(node, null); diff --git a/src/ViewModels/Welcome.cs b/src/ViewModels/Welcome.cs index c5ade9ff..c6919d7b 100644 --- a/src/ViewModels/Welcome.cs +++ b/src/ViewModels/Welcome.cs @@ -82,7 +82,7 @@ namespace SourceGit.ViewModels } } - public void InitRepository(string path, RepositoryNode parent) + public void InitRepository(string path, RepositoryNode parent, string reason) { if (!Preference.Instance.IsGitConfigured()) { @@ -91,7 +91,7 @@ namespace SourceGit.ViewModels } if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new Init(path, parent)); + PopupHost.ShowPopup(new Init(path, parent, reason)); } public void Clone() diff --git a/src/Views/Init.axaml b/src/Views/Init.axaml index 6b35bc82..0c2f70dc 100644 --- a/src/Views/Init.axaml +++ b/src/Views/Init.axaml @@ -10,16 +10,22 @@ - + + + + + + + Text="{DynamicResource Text.Init.Path}" + HorizontalAlignment="Right" VerticalAlignment="Center" + Margin="0,0,8,0"/> + Text="{Binding TargetPath}"/> + Foreground="{DynamicResource Brush.FG2}" + Text="{Binding Reason}" + TextWrapping="Wrap"/> diff --git a/src/Views/Welcome.axaml.cs b/src/Views/Welcome.axaml.cs index 9e887ab0..586b76f3 100644 --- a/src/Views/Welcome.axaml.cs +++ b/src/Views/Welcome.axaml.cs @@ -279,14 +279,14 @@ namespace SourceGit.Views return; } - var root = new Commands.QueryRepositoryRootPath(path).Result(); - if (string.IsNullOrEmpty(root)) + var test = new Commands.QueryRepositoryRootPath(path).ReadToEnd(); + if (!test.IsSuccess || string.IsNullOrEmpty(test.StdOut)) { - ViewModels.Welcome.Instance.InitRepository(path, parent); + ViewModels.Welcome.Instance.InitRepository(path, parent, test.StdErr); return; } - var normalizedPath = root.Replace("\\", "/"); + var normalizedPath = test.StdOut.Trim().Replace("\\", "/"); var node = ViewModels.Preference.Instance.FindOrAddNodeByRepositoryPath(normalizedPath, parent, true); ViewModels.Welcome.Instance.Refresh(); diff --git a/src/Views/WelcomeToolbar.axaml.cs b/src/Views/WelcomeToolbar.axaml.cs index b38b5b9d..fc36e050 100644 --- a/src/Views/WelcomeToolbar.axaml.cs +++ b/src/Views/WelcomeToolbar.axaml.cs @@ -55,14 +55,14 @@ namespace SourceGit.Views return; } - var root = new Commands.QueryRepositoryRootPath(path).Result(); - if (string.IsNullOrEmpty(root)) + var test = new Commands.QueryRepositoryRootPath(path).ReadToEnd(); + if (!test.IsSuccess || string.IsNullOrEmpty(test.StdOut)) { - ViewModels.Welcome.Instance.InitRepository(path, parent); + ViewModels.Welcome.Instance.InitRepository(path, parent, test.StdErr); return; } - var normalizedPath = root.Replace("\\", "/"); + var normalizedPath = test.StdOut.Trim().Replace("\\", "/"); var node = ViewModels.Preference.Instance.FindOrAddNodeByRepositoryPath(normalizedPath, parent, false); ViewModels.Welcome.Instance.Refresh();