diff --git a/src/Commands/Fetch.cs b/src/Commands/Fetch.cs index d25cc80c8..43cd18cbb 100644 --- a/src/Commands/Fetch.cs +++ b/src/Commands/Fetch.cs @@ -4,7 +4,7 @@ namespace SourceGit.Commands { public class Fetch : Command { - public Fetch(string repo, string remote, bool noTags, bool force) + public Fetch(string repo, string remote, bool noTags, bool force, int depth) { _remoteKey = $"remote.{remote}.sshkey"; @@ -20,6 +20,9 @@ public Fetch(string repo, string remote, bool noTags, bool force) if (force) Args += "--force "; + if (depth > 0) + Args += $"--depth={depth} "; + Args += remote; } diff --git a/src/Commands/Pull.cs b/src/Commands/Pull.cs index 93896c754..bdc3d41ea 100644 --- a/src/Commands/Pull.cs +++ b/src/Commands/Pull.cs @@ -4,7 +4,7 @@ namespace SourceGit.Commands { public class Pull : Command { - public Pull(string repo, string remote, string branch, bool useRebase) + public Pull(string repo, string remote, string branch, bool useRebase, int depth) { _remote = remote; @@ -15,6 +15,9 @@ public Pull(string repo, string remote, string branch, bool useRebase) if (useRebase) Args += "--rebase=true "; + if (depth > 0) + Args += $"--depth={depth} "; + Args += $"{remote} {branch}"; } diff --git a/src/Models/RepositorySettings.cs b/src/Models/RepositorySettings.cs index f287826c5..46c159453 100644 --- a/src/Models/RepositorySettings.cs +++ b/src/Models/RepositorySettings.cs @@ -230,6 +230,30 @@ public string LastCommitMessage set; } = string.Empty; + public bool EnableFetchDepth + { + get; + set; + } = false; + + public int FetchDepthValue + { + get; + set; + } = 1; + + public bool EnablePullDepth + { + get; + set; + } = false; + + public int PullDepthValue + { + get; + set; + } = 1; + public Dictionary CollectHistoriesFilters() { var map = new Dictionary(); diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 655f6e976..3e13fc059 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -193,6 +193,8 @@ Minute(s) Default Remote Preferred Merge Mode + Fetch depth + Pull depth ISSUE TRACKER Add Azure DevOps Rule Add Gerrit Change-Id Commit Rule diff --git a/src/ViewModels/AddRemote.cs b/src/ViewModels/AddRemote.cs index 5a6c019fc..6696ef60d 100644 --- a/src/ViewModels/AddRemote.cs +++ b/src/ViewModels/AddRemote.cs @@ -105,7 +105,7 @@ public override async Task Sure() .Use(log) .SetAsync($"remote.{_name}.sshkey", _useSSH ? SSHKey : null); - await new Commands.Fetch(_repo.FullPath, _name, false, false) + await new Commands.Fetch(_repo.FullPath, _name, false, false, _repo.Settings.EnableFetchDepth ? _repo.Settings.FetchDepthValue : 0) .Use(log) .RunAsync(); } diff --git a/src/ViewModels/Fetch.cs b/src/ViewModels/Fetch.cs index 0930e7773..9ee35bb97 100644 --- a/src/ViewModels/Fetch.cs +++ b/src/ViewModels/Fetch.cs @@ -60,19 +60,20 @@ public override async Task Sure() var notags = _repo.Settings.FetchWithoutTags; var force = _repo.Settings.EnableForceOnFetch; + var depth = _repo.Settings.EnableFetchDepth ? _repo.Settings.FetchDepthValue : 0; var log = _repo.CreateLog("Fetch"); Use(log); if (FetchAllRemotes) { foreach (var remote in _repo.Remotes) - await new Commands.Fetch(_repo.FullPath, remote.Name, notags, force) + await new Commands.Fetch(_repo.FullPath, remote.Name, notags, force, depth) .Use(log) .RunAsync(); } else { - await new Commands.Fetch(_repo.FullPath, SelectedRemote.Name, notags, force) + await new Commands.Fetch(_repo.FullPath, SelectedRemote.Name, notags, force, depth) .Use(log) .RunAsync(); } diff --git a/src/ViewModels/Pull.cs b/src/ViewModels/Pull.cs index c3156536a..50d92bd99 100644 --- a/src/ViewModels/Pull.cs +++ b/src/ViewModels/Pull.cs @@ -145,7 +145,8 @@ public override async Task Sure() _repo.FullPath, _selectedRemote.Name, !string.IsNullOrEmpty(Current.Upstream) && Current.Upstream.Equals(_selectedBranch.FullName) ? string.Empty : _selectedBranch.Name, - UseRebase).Use(log).RunAsync(); + UseRebase, + _repo.Settings.EnablePullDepth ? _repo.Settings.PullDepthValue : 0).Use(log).RunAsync(); if (rs) { if (updateSubmodules) diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 450c9e889..db145ab02 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -3138,7 +3138,7 @@ private async void AutoFetchImpl(object sender) Dispatcher.UIThread.Invoke(() => IsAutoFetching = true); foreach (var remote in remotes) - await new Commands.Fetch(_fullpath, remote, false, false) { RaiseError = false }.RunAsync(); + await new Commands.Fetch(_fullpath, remote, false, false, _settings.EnableFetchDepth ? _settings.FetchDepthValue : 0) { RaiseError = false }.RunAsync(); _lastFetchTime = DateTime.Now; Dispatcher.UIThread.Invoke(() => IsAutoFetching = false); } diff --git a/src/ViewModels/RepositoryConfigure.cs b/src/ViewModels/RepositoryConfigure.cs index 72f7c2e89..2e6d9eaf5 100644 --- a/src/ViewModels/RepositoryConfigure.cs +++ b/src/ViewModels/RepositoryConfigure.cs @@ -101,6 +101,58 @@ public int? AutoFetchInterval } } + public bool EnableFetchDepth + { + get => _repo.Settings.EnableFetchDepth; + set + { + if (_repo.Settings.EnableFetchDepth != value) + { + _repo.Settings.EnableFetchDepth = value; + OnPropertyChanged(); + } + } + } + + public int FetchDepthValue + { + get => _repo.Settings.FetchDepthValue; + set + { + if (_repo.Settings.FetchDepthValue != value) + { + _repo.Settings.FetchDepthValue = value; + OnPropertyChanged(); + } + } + } + + public bool EnablePullDepth + { + get => _repo.Settings.EnablePullDepth; + set + { + if (_repo.Settings.EnablePullDepth != value) + { + _repo.Settings.EnablePullDepth = value; + OnPropertyChanged(); + } + } + } + + public int PullDepthValue + { + get => _repo.Settings.PullDepthValue; + set + { + if (_repo.Settings.PullDepthValue != value) + { + _repo.Settings.PullDepthValue = value; + OnPropertyChanged(); + } + } + } + public AvaloniaList CommitTemplates { get => _repo.Settings.CommitTemplates; diff --git a/src/Views/RepositoryConfigure.axaml b/src/Views/RepositoryConfigure.axaml index f786a3d84..14590fa9a 100644 --- a/src/Views/RepositoryConfigure.axaml +++ b/src/Views/RepositoryConfigure.axaml @@ -44,7 +44,7 @@ - + + + + + + + + + + + + +