diff --git a/src/Commands/Clone.cs b/src/Commands/Clone.cs index 28587dab..1f845cc8 100644 --- a/src/Commands/Clone.cs +++ b/src/Commands/Clone.cs @@ -7,11 +7,13 @@ namespace SourceGit.Commands { /// public class Clone : Command { private Action handler = null; + private Action onError = null; - public Clone(string path, string url, string localName, string sshKey, string extraArgs, Action outputHandler) { + public Clone(string path, string url, string localName, string sshKey, string extraArgs, Action outputHandler, Action errHandler) { Cwd = path; TraitErrorAsOutput = true; handler = outputHandler; + onError = errHandler; if (!string.IsNullOrEmpty(sshKey)) { Envs.Add("GIT_SSH_COMMAND", $"ssh -i '{sshKey}'"); @@ -30,5 +32,9 @@ namespace SourceGit.Commands { public override void OnReadline(string line) { handler?.Invoke(line); } + + public override void OnException(string message) { + onError?.Invoke(message); + } } } diff --git a/src/Commands/Command.cs b/src/Commands/Command.cs index 90eff69a..4cf248fa 100644 --- a/src/Commands/Command.cs +++ b/src/Commands/Command.cs @@ -112,7 +112,7 @@ namespace SourceGit.Commands { try { proc.Start(); } catch (Exception e) { - if (!DontRaiseError) Models.Exception.Raise(e.Message); + if (!DontRaiseError) OnException(e.Message); return false; } @@ -124,7 +124,7 @@ namespace SourceGit.Commands { proc.Close(); if (!isCancelled && exitCode != 0 && errs.Count > 0) { - if (!DontRaiseError) Models.Exception.Raise(string.Join("\n", errs)); + if (!DontRaiseError) OnException(string.Join("\n", errs)); return false; } else { return true; @@ -173,6 +173,15 @@ namespace SourceGit.Commands { /// 调用Exec时的读取函数 /// /// - public virtual void OnReadline(string line) { } + public virtual void OnReadline(string line) { + } + + /// + /// 默认异常处理函数 + /// + /// + public virtual void OnException(string message) { + Models.Exception.Raise(message); + } } } diff --git a/src/Views/Clone.xaml b/src/Views/Clone.xaml new file mode 100644 index 00000000..db73fe64 --- /dev/null +++ b/src/Views/Clone.xaml @@ -0,0 +1,256 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +