Skip to content

Commit b16d267

Browse files
committed
enhance: show git errors when failed to get the repository root dir of given path (sourcegit-scm#397)
1 parent 9639162 commit b16d267

14 files changed

Lines changed: 40 additions & 39 deletions

File tree

‎src/Commands/Command.cs‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ public class CancelToken
1717

1818
public class ReadToEndResult
1919
{
20-
public bool IsSuccess { get; set; }
21-
public string StdOut { get; set; }
20+
public bool IsSuccess { get; set; } = false;
21+
public string StdOut { get; set; } = "";
22+
public string StdErr { get; set; } = "";
2223
}
2324

2425
public enum EditorType
@@ -198,18 +199,20 @@ public ReadToEndResult ReadToEnd()
198199
{
199200
proc.Start();
200201
}
201-
catch
202+
catch (Exception e)
202203
{
203204
return new ReadToEndResult()
204205
{
205206
IsSuccess = false,
206207
StdOut = string.Empty,
208+
StdErr = e.Message,
207209
};
208210
}
209211

210212
var rs = new ReadToEndResult()
211213
{
212214
StdOut = proc.StandardOutput.ReadToEnd(),
215+
StdErr = proc.StandardError.ReadToEnd(),
213216
};
214217

215218
proc.WaitForExit();

‎src/Commands/QueryRepositoryRootPath.cs‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,6 @@ public QueryRepositoryRootPath(string path)
66
{
77
WorkingDirectory = path;
88
Args = "rev-parse --show-toplevel";
9-
RaiseError = false;
10-
}
11-
12-
public string Result()
13-
{
14-
var rs = ReadToEnd().StdOut;
15-
if (string.IsNullOrEmpty(rs))
16-
return null;
17-
return rs.Trim();
189
}
1910
}
2011
}

‎src/Resources/Locales/de_DE.axaml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,6 @@
334334
<x:String x:Key="Text.Hunk.Discard" xml:space="preserve">Verwerfen</x:String>
335335
<x:String x:Key="Text.Init" xml:space="preserve">Initialisiere Repository</x:String>
336336
<x:String x:Key="Text.Init.Path" xml:space="preserve">Pfad:</x:String>
337-
<x:String x:Key="Text.Init.Tip" xml:space="preserve">Ungültiges Repository erkannt. `git init` auf diesem Pfad ausführen?</x:String>
338337
<x:String x:Key="Text.InProgress.CherryPick" xml:space="preserve">Cherry-Pick wird durchgeführt. Drücke 'Abbrechen' um den originalen HEAD wiederherzustellen.</x:String>
339338
<x:String x:Key="Text.InProgress.Merge" xml:space="preserve">Merge request wird durchgeführt. Drücke 'Abbrechen' um den originalen HEAD wiederherzustellen.</x:String>
340339
<x:String x:Key="Text.InProgress.Rebase" xml:space="preserve">Rebase wird durchgeführt. Drücke 'Abbrechen' um den originalen HEAD wiederherzustellen.</x:String>

‎src/Resources/Locales/en_US.axaml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,6 @@
336336
<x:String x:Key="Text.Hunk.Discard" xml:space="preserve">Discard</x:String>
337337
<x:String x:Key="Text.Init" xml:space="preserve">Initialize Repository</x:String>
338338
<x:String x:Key="Text.Init.Path" xml:space="preserve">Path:</x:String>
339-
<x:String x:Key="Text.Init.Tip" xml:space="preserve">Invalid repository detected. Run `git init` under this path?</x:String>
340339
<x:String x:Key="Text.InProgress.CherryPick" xml:space="preserve">Cherry-Pick in progress. Press 'Abort' to restore original HEAD.</x:String>
341340
<x:String x:Key="Text.InProgress.Merge" xml:space="preserve">Merge request in progress. Press 'Abort' to restore original HEAD.</x:String>
342341
<x:String x:Key="Text.InProgress.Rebase" xml:space="preserve">Rebase in progress. Press 'Abort' to restore original HEAD.</x:String>

‎src/Resources/Locales/fr_FR.axaml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@
337337
<x:String x:Key="Text.Hunk.Discard" xml:space="preserve">Rejeter</x:String>
338338
<x:String x:Key="Text.Init" xml:space="preserve">Initialize Repository</x:String>
339339
<x:String x:Key="Text.Init.Path" xml:space="preserve">Path:</x:String>
340-
<x:String x:Key="Text.Init.Tip" xml:space="preserve">Invalid repository detected. Run `git init` under this path?</x:String>
341340
<x:String x:Key="Text.InProgress.CherryPick" xml:space="preserve">Cherry-Pick in progress. Press 'Abort' to restore original HEAD.</x:String>
342341
<x:String x:Key="Text.InProgress.Merge" xml:space="preserve">Merge request in progress. Press 'Abort' to restore original HEAD.</x:String>
343342
<x:String x:Key="Text.InProgress.Rebase" xml:space="preserve">Rebase in progress. Press 'Abort' to restore original HEAD.</x:String>

‎src/Resources/Locales/pt_BR.axaml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@
332332
<x:String x:Key="Text.Hunk.Discard" xml:space="preserve">Descartar</x:String>
333333
<x:String x:Key="Text.Init" xml:space="preserve">Inicializar Repositório</x:String>
334334
<x:String x:Key="Text.Init.Path" xml:space="preserve">Caminho:</x:String>
335-
<x:String x:Key="Text.Init.Tip" xml:space="preserve">Repositório inválido detectado. Executar `git init` neste caminho?</x:String>
336335
<x:String x:Key="Text.InProgress.CherryPick" xml:space="preserve">Cherry-Pick em andamento. Pressione 'Abort' para restaurar o HEAD original.</x:String>
337336
<x:String x:Key="Text.InProgress.Merge" xml:space="preserve">Merge em andamento. Pressione 'Abort' para restaurar o HEAD original.</x:String>
338337
<x:String x:Key="Text.InProgress.Rebase" xml:space="preserve">Rebase em andamento. Pressione 'Abort' para restaurar o HEAD original.</x:String>

‎src/Resources/Locales/zh_CN.axaml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@
339339
<x:String x:Key="Text.Hunk.Discard" xml:space="preserve">丢弃</x:String>
340340
<x:String x:Key="Text.Init" xml:space="preserve">初始化新仓库</x:String>
341341
<x:String x:Key="Text.Init.Path" xml:space="preserve">路径 :</x:String>
342-
<x:String x:Key="Text.Init.Tip" xml:space="preserve">选择目录不是有效的Git仓库。是否需要在此目录执行`git init`操作?</x:String>
343342
<x:String x:Key="Text.InProgress.CherryPick" xml:space="preserve">挑选(Cherry-Pick)操作进行中。点击【终止】回滚到操作前的状态。</x:String>
344343
<x:String x:Key="Text.InProgress.Merge" xml:space="preserve">合并操作进行中。点击【终止】回滚到操作前的状态。</x:String>
345344
<x:String x:Key="Text.InProgress.Rebase" xml:space="preserve">变基(Rebase)操作进行中。点击【终止】回滚到操作前的状态。</x:String>

‎src/Resources/Locales/zh_TW.axaml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@
339339
<x:String x:Key="Text.Hunk.Discard" xml:space="preserve">捨棄</x:String>
340340
<x:String x:Key="Text.Init" xml:space="preserve">初始化存放庫</x:String>
341341
<x:String x:Key="Text.Init.Path" xml:space="preserve">路徑:</x:String>
342-
<x:String x:Key="Text.Init.Tip" xml:space="preserve">選擇目錄並非有效的 Git 存放庫。是否要在此目錄執行 `git init` 以進行初始化?</x:String>
343342
<x:String x:Key="Text.InProgress.CherryPick" xml:space="preserve">揀選 (cherry-pick) 操作進行中。點選 [中止] 復原到操作前的狀態。</x:String>
344343
<x:String x:Key="Text.InProgress.Merge" xml:space="preserve">合併操作進行中。點選 [中止] 復原到操作前的狀態。</x:String>
345344
<x:String x:Key="Text.InProgress.Rebase" xml:space="preserve">重定基底 (rebase) 操作進行中。點選 [中止] 復原到操作前的狀態。</x:String>

‎src/ViewModels/Init.cs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,18 @@ public string TargetPath
1010
set => SetProperty(ref _targetPath, value);
1111
}
1212

13-
public Init(string path, RepositoryNode parent)
13+
public string Reason
14+
{
15+
get;
16+
private set;
17+
}
18+
19+
public Init(string path, RepositoryNode parent, string reason)
1420
{
1521
_targetPath = path;
1622
_parentNode = parent;
1723

24+
Reason = string.IsNullOrEmpty(reason) ? "Invalid repository detected!" : reason;
1825
View = new Views.Init() { DataContext = this };
1926
}
2027

‎src/ViewModels/Launcher.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public Launcher(string startupRepo)
3535
var pref = Preference.Instance;
3636
if (!string.IsNullOrEmpty(startupRepo))
3737
{
38-
var root = new Commands.QueryRepositoryRootPath(startupRepo).Result();
39-
if (string.IsNullOrEmpty(root))
38+
var test = new Commands.QueryRepositoryRootPath(startupRepo).ReadToEnd();
39+
if (!test.IsSuccess || string.IsNullOrEmpty(test.StdOut))
4040
{
4141
Pages[0].Notifications.Add(new Models.Notification
4242
{
@@ -46,7 +46,7 @@ public Launcher(string startupRepo)
4646
return;
4747
}
4848

49-
var normalized = root.Replace("\\", "/");
49+
var normalized = test.StdOut.Trim().Replace("\\", "/");
5050
var node = pref.FindOrAddNodeByRepositoryPath(normalized, null, false);
5151
Welcome.Instance.Refresh();
5252
OpenRepositoryInTab(node, null);

0 commit comments

Comments
 (0)