Skip to content

feat: Add depth parameter to Fetch and Pull operations (#1605) #1609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Commands/Fetch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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;

}
Expand Down
5 changes: 4 additions & 1 deletion src/Commands/Pull.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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}";
}

Expand Down
24 changes: 24 additions & 0 deletions src/Models/RepositorySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, FilterMode> CollectHistoriesFilters()
{
var map = new Dictionary<string, FilterMode>();
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/Locales/en_US.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@
<x:String x:Key="Text.Configure.Git.AutoFetchIntervalSuffix" xml:space="preserve">Minute(s)</x:String>
<x:String x:Key="Text.Configure.Git.DefaultRemote" xml:space="preserve">Default Remote</x:String>
<x:String x:Key="Text.Configure.Git.PreferredMergeMode" xml:space="preserve">Preferred Merge Mode</x:String>
<x:String x:Key="Text.Configure.Git.FetchDepth" xml:space="preserve">Fetch depth</x:String>
<x:String x:Key="Text.Configure.Git.PullDepth" xml:space="preserve">Pull depth</x:String>
<x:String x:Key="Text.Configure.IssueTracker" xml:space="preserve">ISSUE TRACKER</x:String>
<x:String x:Key="Text.Configure.IssueTracker.AddSampleAzure" xml:space="preserve">Add Azure DevOps Rule</x:String>
<x:String x:Key="Text.Configure.IssueTracker.AddSampleGerritChangeIdCommit" xml:space="preserve">Add Gerrit Change-Id Commit Rule</x:String>
Expand Down
2 changes: 1 addition & 1 deletion src/ViewModels/AddRemote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public override async Task<bool> 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();
}
Expand Down
5 changes: 3 additions & 2 deletions src/ViewModels/Fetch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,20 @@ public override async Task<bool> 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();
}
Expand Down
3 changes: 2 additions & 1 deletion src/ViewModels/Pull.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ public override async Task<bool> 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)
Expand Down
2 changes: 1 addition & 1 deletion src/ViewModels/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
52 changes: 52 additions & 0 deletions src/ViewModels/RepositoryConfigure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Models.CommitTemplate> CommitTemplates
{
get => _repo.Settings.CommitTemplates;
Expand Down
36 changes: 35 additions & 1 deletion src/Views/RepositoryConfigure.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<TextBlock Classes="tab_header" Text="{DynamicResource Text.Configure.Git}"/>
</TabItem.Header>

<Grid Margin="16,4,16,8" RowDefinitions="32,32,32,32,32,32,32,32,32,32" ColumnDefinitions="Auto,*">
<Grid Margin="16,4,16,8" RowDefinitions="32,32,32,32,32,32,32,32,32,32,32,32" ColumnDefinitions="Auto,*">
<TextBlock Grid.Row="0" Grid.Column="0"
HorizontalAlignment="Right" VerticalAlignment="Center"
Margin="0,0,8,0"
Expand Down Expand Up @@ -178,6 +178,40 @@
Margin="5,0,0,0"
Text="{DynamicResource Text.Configure.Git.AutoFetchIntervalSuffix}" />
</StackPanel>

<Grid Grid.Row="10" Grid.Column="1">
<CheckBox x:Name="FetchDepthCheckBox"
Content="{DynamicResource Text.Configure.Git.FetchDepth}"
IsChecked="{Binding EnableFetchDepth, Mode=TwoWay}"/>

<NumericUpDown Minimum="1" Increment="1"
Height="26" Width="220"
Margin="8,0,0,0" Padding="4"
BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}"
CornerRadius="3"
ParsingNumberStyle="Integer"
FormatString="0"
Value="{Binding FetchDepthValue, Mode=TwoWay, FallbackValue=1}"
IsEnabled="{Binding #FetchDepthCheckBox.IsChecked}"
HorizontalAlignment="Right"/>
</Grid>

<Grid Grid.Row="11" Grid.Column="1">
<CheckBox x:Name="PullDepthCheckBox"
Content="{DynamicResource Text.Configure.Git.PullDepth}"
IsChecked="{Binding EnablePullDepth, Mode=TwoWay}"/>

<NumericUpDown Minimum="1" Increment="1"
Height="26" Width="220"
Margin="8,0,0,0" Padding="4"
BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}"
CornerRadius="3"
ParsingNumberStyle="Integer"
FormatString="0"
Value="{Binding PullDepthValue, Mode=TwoWay, FallbackValue=1}"
IsEnabled="{Binding #PullDepthCheckBox.IsChecked}"
HorizontalAlignment="Right"/>
</Grid>
</Grid>
</TabItem>

Expand Down
Loading