mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-20 11:44:59 +00:00

* prevent moving node while opening repository directly from commandline * supports to set parent node while dropping folder to initialize repository
46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
using System.IO;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace SourceGit.ViewModels
|
|
{
|
|
public class Init : Popup
|
|
{
|
|
public string TargetPath
|
|
{
|
|
get => _targetPath;
|
|
set => SetProperty(ref _targetPath, value);
|
|
}
|
|
|
|
public Init(string path, RepositoryNode parent)
|
|
{
|
|
_targetPath = path;
|
|
_parentNode = parent;
|
|
|
|
View = new Views.Init() { DataContext = this };
|
|
}
|
|
|
|
public override Task<bool> Sure()
|
|
{
|
|
ProgressDescription = $"Initialize git repository at: '{_targetPath}'";
|
|
|
|
return Task.Run(() =>
|
|
{
|
|
var succ = new Commands.Init(HostPageId, _targetPath).Exec();
|
|
if (!succ)
|
|
return false;
|
|
|
|
var gitDir = Path.GetFullPath(Path.Combine(_targetPath, ".git"));
|
|
CallUIThread(() =>
|
|
{
|
|
var repo = Preference.AddRepository(_targetPath, gitDir);
|
|
Preference.FindOrAddNodeByRepositoryPath(repo.FullPath, _parentNode, true);
|
|
});
|
|
|
|
return true;
|
|
});
|
|
}
|
|
|
|
private string _targetPath = string.Empty;
|
|
private RepositoryNode _parentNode = null;
|
|
}
|
|
}
|