feature: supports toggle --force option for git fetch command (#721)

* Background auto fetch will always disable this option
* This option is not add to pull operation

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2024-11-22 09:39:50 +08:00
parent c1c743f2ff
commit 153a1f30b2
No known key found for this signature in database
9 changed files with 26 additions and 7 deletions

View file

@ -100,7 +100,7 @@ namespace SourceGit.ViewModels
{
SetProgressDescription("Fetching from added remote ...");
new Commands.Config(_repo.FullPath).Set($"remote.{_name}.sshkey", _useSSH ? SSHKey : null);
new Commands.Fetch(_repo.FullPath, _name, false, false, SetProgressDescription).Exec();
new Commands.Fetch(_repo.FullPath, _name, false, false, false, SetProgressDescription).Exec();
}
CallUIThread(() =>
{

View file

@ -28,10 +28,17 @@ namespace SourceGit.ViewModels
set => _repo.Settings.FetchWithoutTags = value;
}
public bool Force
{
get;
set;
}
public Fetch(Repository repo, Models.Remote preferedRemote = null)
{
_repo = repo;
_fetchAllRemotes = preferedRemote == null;
Force = false;
SelectedRemote = preferedRemote != null ? preferedRemote : _repo.Remotes[0];
View = new Views.Fetch() { DataContext = this };
}
@ -42,6 +49,7 @@ namespace SourceGit.ViewModels
var notags = _repo.Settings.FetchWithoutTags;
var prune = _repo.Settings.EnablePruneOnFetch;
var force = Force;
return Task.Run(() =>
{
if (FetchAllRemotes)
@ -49,13 +57,13 @@ namespace SourceGit.ViewModels
foreach (var remote in _repo.Remotes)
{
SetProgressDescription($"Fetching remote: {remote.Name}");
new Commands.Fetch(_repo.FullPath, remote.Name, notags, prune, SetProgressDescription).Exec();
new Commands.Fetch(_repo.FullPath, remote.Name, notags, prune, force, SetProgressDescription).Exec();
}
}
else
{
SetProgressDescription($"Fetching remote: {SelectedRemote.Name}");
new Commands.Fetch(_repo.FullPath, SelectedRemote.Name, notags, prune, SetProgressDescription).Exec();
new Commands.Fetch(_repo.FullPath, SelectedRemote.Name, notags, prune, force, SetProgressDescription).Exec();
}
CallUIThread(() =>

View file

@ -152,6 +152,7 @@ namespace SourceGit.ViewModels
_selectedRemote.Name,
NoTags,
_repo.Settings.EnablePruneOnFetch,
false,
SetProgressDescription).Exec();
if (!rs)

View file

@ -2194,7 +2194,7 @@ namespace SourceGit.ViewModels
IsAutoFetching = true;
Dispatcher.UIThread.Invoke(() => OnPropertyChanged(nameof(IsAutoFetching)));
new Commands.Fetch(_fullpath, "--all", false, _settings.EnablePruneOnFetch, null) { RaiseError = false }.Exec();
new Commands.Fetch(_fullpath, "--all", false, _settings.EnablePruneOnFetch, false, null) { RaiseError = false }.Exec();
_lastFetchTime = DateTime.Now;
IsAutoFetching = false;
Dispatcher.UIThread.Invoke(() => OnPropertyChanged(nameof(IsAutoFetching)));