2021-08-04 04:11:22 -07:00
|
|
|
using System.IO;
|
2021-04-29 05:05:55 -07:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
|
|
|
namespace SourceGit.Views.Popups {
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 克隆
|
|
|
|
/// </summary>
|
|
|
|
public partial class Clone : Controls.PopupWidget {
|
|
|
|
|
|
|
|
public string Uri { get; set; }
|
|
|
|
public string Folder { get; set; }
|
|
|
|
public string LocalName { get; set; }
|
|
|
|
public string RemoteName { get; set; }
|
|
|
|
public string ExtraArgs { get; set; }
|
|
|
|
|
|
|
|
public Clone() {
|
|
|
|
Folder = Models.Preference.Instance.Git.DefaultCloneDir;
|
|
|
|
InitializeComponent();
|
|
|
|
ruleRemote.IsOptional = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string GetTitle() {
|
|
|
|
return App.Text("Clone");
|
|
|
|
}
|
|
|
|
|
|
|
|
public override Task<bool> Start() {
|
|
|
|
var checks = new Controls.TextEdit[] { txtUrl, txtFolder, txtLocal, txtRemote };
|
|
|
|
foreach (var edit in checks) {
|
|
|
|
edit.GetBindingExpression(TextBox.TextProperty).UpdateSource();
|
|
|
|
if (Validation.GetHasError(edit)) return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Task.Run(() => {
|
|
|
|
var extras = string.IsNullOrEmpty(ExtraArgs) ? "" : ExtraArgs;
|
|
|
|
if (!string.IsNullOrEmpty(RemoteName)) extras += $" --origin {RemoteName}";
|
|
|
|
|
|
|
|
var succ = new Commands.Clone(Folder, Uri, LocalName, extras, UpdateProgress).Exec();
|
|
|
|
if (!succ) return false;
|
|
|
|
|
|
|
|
var path = Folder;
|
|
|
|
if (!string.IsNullOrEmpty(LocalName)) {
|
2021-08-04 04:11:22 -07:00
|
|
|
path = Path.GetFullPath(Path.Combine(path, LocalName));
|
2021-04-29 05:05:55 -07:00
|
|
|
} else {
|
2021-08-04 04:11:22 -07:00
|
|
|
var name = Path.GetFileName(Uri);
|
|
|
|
if (name.EndsWith(".git")) name = name.Substring(0, name.Length - 4);
|
|
|
|
path = Path.GetFullPath(Path.Combine(path, name));
|
2021-04-29 05:05:55 -07:00
|
|
|
}
|
|
|
|
|
2021-08-04 04:11:22 -07:00
|
|
|
if (!Directory.Exists(path)) {
|
|
|
|
Models.Exception.Raise($"Folder {path} not found!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var gitDir = new Commands.QueryGitDir(path).Result();
|
|
|
|
var repo = Models.Preference.Instance.AddRepository(path, gitDir, "");
|
2021-04-29 05:05:55 -07:00
|
|
|
if (repo != null) Dispatcher.Invoke(() => Models.Watcher.Open(repo));
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnFolderSelectorClick(object sender, System.Windows.RoutedEventArgs e) {
|
2021-07-19 18:13:07 -07:00
|
|
|
var dialog = new Controls.FolderDialog();
|
2021-05-25 20:08:31 -07:00
|
|
|
if (dialog.ShowDialog() == true) {
|
|
|
|
Folder = dialog.SelectedPath;
|
2021-04-29 05:05:55 -07:00
|
|
|
txtFolder.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
|
2021-05-25 20:08:31 -07:00
|
|
|
}
|
2021-04-29 05:05:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|