2024-02-05 23:08:37 -08:00
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
namespace SourceGit.ViewModels
|
|
|
|
|
{
|
|
|
|
|
public class AddSubmodule : Popup
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
[Required(ErrorMessage = "Url is required!!!")]
|
|
|
|
|
[CustomValidation(typeof(AddSubmodule), nameof(ValidateURL))]
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public string Url
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _url;
|
|
|
|
|
set => SetProperty(ref _url, value, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Required(ErrorMessage = "Reletive path is required!!!")]
|
|
|
|
|
[CustomValidation(typeof(AddSubmodule), nameof(ValidateRelativePath))]
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public string RelativePath
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _relativePath;
|
|
|
|
|
set => SetProperty(ref _relativePath, value, true);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public bool Recursive
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public AddSubmodule(Repository repo)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_repo = repo;
|
|
|
|
|
View = new Views.AddSubmodule() { DataContext = this };
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public static ValidationResult ValidateURL(string url, ValidationContext ctx)
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (!Models.Remote.IsValidURL(url))
|
|
|
|
|
return new ValidationResult("Invalid repository URL format");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return ValidationResult.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public static ValidationResult ValidateRelativePath(string path, ValidationContext ctx)
|
|
|
|
|
{
|
|
|
|
|
if (Path.Exists(path))
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return new ValidationResult("Give path is exists already!");
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (Path.IsPathRooted(path))
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return new ValidationResult("Path must be relative to this repository!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ValidationResult.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public override Task<bool> Sure()
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_repo.SetWatcherEnabled(false);
|
2024-02-25 19:29:57 -08:00
|
|
|
|
ProgressDescription = "Adding submodule...";
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
return Task.Run(() =>
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var succ = new Commands.Submodule(_repo.FullPath).Add(_url, _relativePath, Recursive, SetProgressDescription);
|
|
|
|
|
CallUIThread(() => _repo.SetWatcherEnabled(true));
|
|
|
|
|
return succ;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
private readonly Repository _repo = null;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
private string _url = string.Empty;
|
|
|
|
|
private string _relativePath = string.Empty;
|
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|