2024-02-05 23:08:37 -08:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
namespace SourceGit.ViewModels
|
|
|
|
|
{
|
|
|
|
|
public class Init : Popup
|
|
|
|
|
{
|
|
|
|
|
public string TargetPath
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _targetPath;
|
|
|
|
|
set => SetProperty(ref _targetPath, value);
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-20 02:36:43 -07:00
|
|
|
|
public Init(string path, RepositoryNode parent)
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-05-20 02:36:43 -07:00
|
|
|
|
_targetPath = path;
|
|
|
|
|
_parentNode = parent;
|
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
View = new Views.Init() { DataContext = this };
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public override Task<bool> Sure()
|
|
|
|
|
{
|
2024-02-25 19:29:57 -08:00
|
|
|
|
ProgressDescription = $"Initialize git repository at: '{_targetPath}'";
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
return Task.Run(() =>
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var succ = new Commands.Init(HostPageId, _targetPath).Exec();
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (!succ)
|
|
|
|
|
return false;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
|
|
|
|
var gitDir = Path.GetFullPath(Path.Combine(_targetPath, ".git"));
|
2024-03-17 18:37:06 -07:00
|
|
|
|
CallUIThread(() =>
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var repo = Preference.AddRepository(_targetPath, gitDir);
|
2024-05-20 02:36:43 -07:00
|
|
|
|
Preference.FindOrAddNodeByRepositoryPath(repo.FullPath, _parentNode, true);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-20 02:36:43 -07:00
|
|
|
|
private string _targetPath = string.Empty;
|
|
|
|
|
private RepositoryNode _parentNode = null;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|