2024-02-05 23:08:37 -08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
namespace SourceGit.ViewModels
|
|
|
|
|
{
|
|
|
|
|
public class Fetch : Popup
|
|
|
|
|
{
|
|
|
|
|
public List<Models.Remote> Remotes
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _repo.Remotes;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public bool FetchAllRemotes
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _fetchAllRemotes;
|
|
|
|
|
set => SetProperty(ref _fetchAllRemotes, value);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public Models.Remote SelectedRemote
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public bool Prune
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get;
|
|
|
|
|
set;
|
2024-07-01 01:19:08 -07:00
|
|
|
|
} = true;
|
|
|
|
|
|
|
|
|
|
public bool NoTags
|
|
|
|
|
{
|
2024-07-02 23:41:43 -07:00
|
|
|
|
get => _repo.Settings.FetchWithoutTags;
|
|
|
|
|
set => _repo.Settings.FetchWithoutTags = value;
|
|
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public Fetch(Repository repo, Models.Remote preferedRemote = null)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_repo = repo;
|
2024-02-25 17:38:25 -08:00
|
|
|
|
_fetchAllRemotes = preferedRemote == null;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
SelectedRemote = preferedRemote != null ? preferedRemote : _repo.Remotes[0];
|
|
|
|
|
View = new Views.Fetch() { DataContext = this };
|
|
|
|
|
}
|
|
|
|
|
|
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-07-02 23:41:43 -07:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
return Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
if (FetchAllRemotes)
|
|
|
|
|
{
|
|
|
|
|
foreach (var remote in _repo.Remotes)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
SetProgressDescription($"Fetching remote: {remote.Name}");
|
2024-07-01 01:19:08 -07:00
|
|
|
|
new Commands.Fetch(_repo.FullPath, remote.Name, Prune, NoTags, SetProgressDescription).Exec();
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
SetProgressDescription($"Fetching remote: {SelectedRemote.Name}");
|
2024-07-01 01:19:08 -07:00
|
|
|
|
new Commands.Fetch(_repo.FullPath, SelectedRemote.Name, Prune, NoTags, SetProgressDescription).Exec();
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CallUIThread(() => _repo.SetWatcherEnabled(true));
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
private readonly Repository _repo = null;
|
2024-07-14 09:30:31 -07:00
|
|
|
|
private bool _fetchAllRemotes;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|