feature: supports --recurse-submodules on pull (#1342)

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-05-21 16:54:23 +08:00
parent d73ae83b01
commit 936160ea5c
No known key found for this signature in database
9 changed files with 46 additions and 14 deletions

View file

@ -537,6 +537,7 @@
<x:String x:Key="Text.Pull.LocalChanges.Discard" xml:space="preserve">Discard</x:String>
<x:String x:Key="Text.Pull.LocalChanges.StashAndReply" xml:space="preserve">Stash &amp; Reapply</x:String>
<x:String x:Key="Text.Pull.NoTags" xml:space="preserve">Fetch without tags</x:String>
<x:String x:Key="Text.Pull.RecurseSubmodules" xml:space="preserve">Update all submodules</x:String>
<x:String x:Key="Text.Pull.Remote" xml:space="preserve">Remote:</x:String>
<x:String x:Key="Text.Pull.Title" xml:space="preserve">Pull (Fetch &amp; Merge)</x:String>
<x:String x:Key="Text.Pull.UseRebase" xml:space="preserve">Use rebase instead of merge</x:String>

View file

@ -541,6 +541,7 @@
<x:String x:Key="Text.Pull.LocalChanges.Discard" xml:space="preserve">丢弃更改</x:String>
<x:String x:Key="Text.Pull.LocalChanges.StashAndReply" xml:space="preserve">贮藏并自动恢复</x:String>
<x:String x:Key="Text.Pull.NoTags" xml:space="preserve">不拉取远程标签</x:String>
<x:String x:Key="Text.Pull.RecurseSubmodules" xml:space="preserve">同时更新所有子模块</x:String>
<x:String x:Key="Text.Pull.Remote" xml:space="preserve">远程 </x:String>
<x:String x:Key="Text.Pull.Title" xml:space="preserve">拉回(拉取并合并)</x:String>
<x:String x:Key="Text.Pull.UseRebase" xml:space="preserve">使用变基方式合并分支</x:String>

View file

@ -541,6 +541,7 @@
<x:String x:Key="Text.Pull.LocalChanges.Discard" xml:space="preserve">捨棄變更</x:String>
<x:String x:Key="Text.Pull.LocalChanges.StashAndReply" xml:space="preserve">擱置變更並自動復原</x:String>
<x:String x:Key="Text.Pull.NoTags" xml:space="preserve">不拉取遠端標籤</x:String>
<x:String x:Key="Text.Pull.RecurseSubmodules" xml:space="preserve">同時更新所有子模組</x:String>
<x:String x:Key="Text.Pull.Remote" xml:space="preserve">遠端:</x:String>
<x:String x:Key="Text.Pull.Title" xml:space="preserve">拉取 (提取並合併)</x:String>
<x:String x:Key="Text.Pull.UseRebase" xml:space="preserve">使用重定基底 (rebase) 合併分支</x:String>

View file

@ -17,8 +17,7 @@ namespace SourceGit.ViewModels
public bool IsRecurseSubmoduleVisible
{
get;
private set;
get => _repo.Submodules.Count > 0;
}
public bool RecurseSubmodules
@ -32,7 +31,6 @@ namespace SourceGit.ViewModels
_repo = repo;
Branch = branch;
DiscardLocalChanges = false;
IsRecurseSubmoduleVisible = repo.Submodules.Count > 0;
}
public override Task<bool> Sure()

View file

@ -17,8 +17,7 @@ namespace SourceGit.ViewModels
public bool IsRecurseSubmoduleVisible
{
get;
private set;
get => _repo.Submodules.Count > 0;
}
public bool RecurseSubmodules
@ -32,7 +31,6 @@ namespace SourceGit.ViewModels
_repo = repo;
Commit = commit;
DiscardLocalChanges = false;
IsRecurseSubmoduleVisible = repo.Submodules.Count > 0;
}
public override Task<bool> Sure()

View file

@ -45,8 +45,7 @@ namespace SourceGit.ViewModels
public bool IsRecurseSubmoduleVisible
{
get;
private set;
get => _repo.Submodules.Count > 0;
}
public bool RecurseSubmodules
@ -67,7 +66,6 @@ namespace SourceGit.ViewModels
BasedOn = branch;
DiscardLocalChanges = false;
IsRecurseSubmoduleVisible = repo.Submodules.Count > 0;
}
public CreateBranch(Repository repo, Models.Commit commit)
@ -77,7 +75,6 @@ namespace SourceGit.ViewModels
BasedOn = commit;
DiscardLocalChanges = false;
IsRecurseSubmoduleVisible = repo.Submodules.Count > 0;
}
public CreateBranch(Repository repo, Models.Tag tag)
@ -87,7 +84,6 @@ namespace SourceGit.ViewModels
BasedOn = tag;
DiscardLocalChanges = false;
IsRecurseSubmoduleVisible = repo.Submodules.Count > 0;
}
public static ValidationResult ValidateBranchName(string name, ValidationContext ctx)

View file

@ -48,7 +48,14 @@ namespace SourceGit.ViewModels
protected void Use(CommandLog log)
{
log.Register(newline => ProgressDescription = newline.Trim());
log.Register(SetDescription);
}
private void SetDescription(string data)
{
var desc = data.Trim();
if (!string.IsNullOrEmpty(desc))
ProgressDescription = desc;
}
private bool _inProgress = false;

View file

@ -62,6 +62,17 @@ namespace SourceGit.ViewModels
set => _repo.Settings.FetchWithoutTagsOnPull = value;
}
public bool IsRecurseSubmoduleVisible
{
get => _repo.Submodules.Count > 0;
}
public bool RecurseSubmodules
{
get => _repo.Settings.UpdateSubmodulesOnCheckoutBranch;
set => _repo.Settings.UpdateSubmodulesOnCheckoutBranch = value;
}
public Pull(Repository repo, Models.Branch specifiedRemoteBranch)
{
_repo = repo;
@ -119,6 +130,7 @@ namespace SourceGit.ViewModels
var log = _repo.CreateLog("Pull");
Use(log);
var updateSubmodules = IsRecurseSubmoduleVisible && RecurseSubmodules;
return Task.Run(() =>
{
var changes = new Commands.CountLocalChangesWithoutUntracked(_repo.FullPath).Result();
@ -176,8 +188,18 @@ namespace SourceGit.ViewModels
NoTags).Use(log).Exec();
}
if (rs && needPopStash)
rs = new Commands.Stash(_repo.FullPath).Use(log).Pop("stash@{0}");
if (rs)
{
if (updateSubmodules)
{
var submodules = new Commands.QuerySubmodules(_repo.FullPath).Result();
if (submodules.Count > 0)
new Commands.Submodule(_repo.FullPath).Use(log).Update(submodules, true, true, false);
}
if (needPopStash)
new Commands.Stash(_repo.FullPath).Use(log).Pop("stash@{0}");
}
log.Complete();

View file

@ -21,6 +21,7 @@
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0"
@ -105,6 +106,13 @@
Content="{DynamicResource Text.Pull.UseRebase}"
IsChecked="{Binding UseRebase, Mode=TwoWay}"
ToolTip.Tip="--rebase"/>
<CheckBox Grid.Row="7" Grid.Column="1"
Height="32"
Content="{DynamicResource Text.Pull.RecurseSubmodules}"
IsChecked="{Binding RecurseSubmodules, Mode=TwoWay}"
IsVisible="{Binding IsRecurseSubmoduleVisible}"
ToolTip.Tip="--recurse-submodules"/>
</Grid>
</StackPanel>
</UserControl>