Skip to content

Commit 936160e

Browse files
committed
feature: supports --recurse-submodules on pull (#1342)
Signed-off-by: leo <[email protected]>
1 parent d73ae83 commit 936160e

File tree

9 files changed

+46
-14
lines changed

9 files changed

+46
-14
lines changed

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@
537537
<x:String x:Key="Text.Pull.LocalChanges.Discard" xml:space="preserve">Discard</x:String>
538538
<x:String x:Key="Text.Pull.LocalChanges.StashAndReply" xml:space="preserve">Stash &amp; Reapply</x:String>
539539
<x:String x:Key="Text.Pull.NoTags" xml:space="preserve">Fetch without tags</x:String>
540+
<x:String x:Key="Text.Pull.RecurseSubmodules" xml:space="preserve">Update all submodules</x:String>
540541
<x:String x:Key="Text.Pull.Remote" xml:space="preserve">Remote:</x:String>
541542
<x:String x:Key="Text.Pull.Title" xml:space="preserve">Pull (Fetch &amp; Merge)</x:String>
542543
<x:String x:Key="Text.Pull.UseRebase" xml:space="preserve">Use rebase instead of merge</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@
541541
<x:String x:Key="Text.Pull.LocalChanges.Discard" xml:space="preserve">丢弃更改</x:String>
542542
<x:String x:Key="Text.Pull.LocalChanges.StashAndReply" xml:space="preserve">贮藏并自动恢复</x:String>
543543
<x:String x:Key="Text.Pull.NoTags" xml:space="preserve">不拉取远程标签</x:String>
544+
<x:String x:Key="Text.Pull.RecurseSubmodules" xml:space="preserve">同时更新所有子模块</x:String>
544545
<x:String x:Key="Text.Pull.Remote" xml:space="preserve">远程 :</x:String>
545546
<x:String x:Key="Text.Pull.Title" xml:space="preserve">拉回(拉取并合并)</x:String>
546547
<x:String x:Key="Text.Pull.UseRebase" xml:space="preserve">使用变基方式合并分支</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@
541541
<x:String x:Key="Text.Pull.LocalChanges.Discard" xml:space="preserve">捨棄變更</x:String>
542542
<x:String x:Key="Text.Pull.LocalChanges.StashAndReply" xml:space="preserve">擱置變更並自動復原</x:String>
543543
<x:String x:Key="Text.Pull.NoTags" xml:space="preserve">不拉取遠端標籤</x:String>
544+
<x:String x:Key="Text.Pull.RecurseSubmodules" xml:space="preserve">同時更新所有子模組</x:String>
544545
<x:String x:Key="Text.Pull.Remote" xml:space="preserve">遠端:</x:String>
545546
<x:String x:Key="Text.Pull.Title" xml:space="preserve">拉取 (提取並合併)</x:String>
546547
<x:String x:Key="Text.Pull.UseRebase" xml:space="preserve">使用重定基底 (rebase) 合併分支</x:String>

src/ViewModels/Checkout.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ public bool DiscardLocalChanges
1717

1818
public bool IsRecurseSubmoduleVisible
1919
{
20-
get;
21-
private set;
20+
get => _repo.Submodules.Count > 0;
2221
}
2322

2423
public bool RecurseSubmodules
@@ -32,7 +31,6 @@ public Checkout(Repository repo, string branch)
3231
_repo = repo;
3332
Branch = branch;
3433
DiscardLocalChanges = false;
35-
IsRecurseSubmoduleVisible = repo.Submodules.Count > 0;
3634
}
3735

3836
public override Task<bool> Sure()

src/ViewModels/CheckoutCommit.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ public bool DiscardLocalChanges
1717

1818
public bool IsRecurseSubmoduleVisible
1919
{
20-
get;
21-
private set;
20+
get => _repo.Submodules.Count > 0;
2221
}
2322

2423
public bool RecurseSubmodules
@@ -32,7 +31,6 @@ public CheckoutCommit(Repository repo, Models.Commit commit)
3231
_repo = repo;
3332
Commit = commit;
3433
DiscardLocalChanges = false;
35-
IsRecurseSubmoduleVisible = repo.Submodules.Count > 0;
3634
}
3735

3836
public override Task<bool> Sure()

src/ViewModels/CreateBranch.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ public bool IsBareRepository
4545

4646
public bool IsRecurseSubmoduleVisible
4747
{
48-
get;
49-
private set;
48+
get => _repo.Submodules.Count > 0;
5049
}
5150

5251
public bool RecurseSubmodules
@@ -67,7 +66,6 @@ public CreateBranch(Repository repo, Models.Branch branch)
6766

6867
BasedOn = branch;
6968
DiscardLocalChanges = false;
70-
IsRecurseSubmoduleVisible = repo.Submodules.Count > 0;
7169
}
7270

7371
public CreateBranch(Repository repo, Models.Commit commit)
@@ -77,7 +75,6 @@ public CreateBranch(Repository repo, Models.Commit commit)
7775

7876
BasedOn = commit;
7977
DiscardLocalChanges = false;
80-
IsRecurseSubmoduleVisible = repo.Submodules.Count > 0;
8178
}
8279

8380
public CreateBranch(Repository repo, Models.Tag tag)
@@ -87,7 +84,6 @@ public CreateBranch(Repository repo, Models.Tag tag)
8784

8885
BasedOn = tag;
8986
DiscardLocalChanges = false;
90-
IsRecurseSubmoduleVisible = repo.Submodules.Count > 0;
9187
}
9288

9389
public static ValidationResult ValidateBranchName(string name, ValidationContext ctx)

src/ViewModels/Popup.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,14 @@ protected void CallUIThread(Action action)
4848

4949
protected void Use(CommandLog log)
5050
{
51-
log.Register(newline => ProgressDescription = newline.Trim());
51+
log.Register(SetDescription);
52+
}
53+
54+
private void SetDescription(string data)
55+
{
56+
var desc = data.Trim();
57+
if (!string.IsNullOrEmpty(desc))
58+
ProgressDescription = desc;
5259
}
5360

5461
private bool _inProgress = false;

src/ViewModels/Pull.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ public bool NoTags
6262
set => _repo.Settings.FetchWithoutTagsOnPull = value;
6363
}
6464

65+
public bool IsRecurseSubmoduleVisible
66+
{
67+
get => _repo.Submodules.Count > 0;
68+
}
69+
70+
public bool RecurseSubmodules
71+
{
72+
get => _repo.Settings.UpdateSubmodulesOnCheckoutBranch;
73+
set => _repo.Settings.UpdateSubmodulesOnCheckoutBranch = value;
74+
}
75+
6576
public Pull(Repository repo, Models.Branch specifiedRemoteBranch)
6677
{
6778
_repo = repo;
@@ -119,6 +130,7 @@ public override Task<bool> Sure()
119130
var log = _repo.CreateLog("Pull");
120131
Use(log);
121132

133+
var updateSubmodules = IsRecurseSubmoduleVisible && RecurseSubmodules;
122134
return Task.Run(() =>
123135
{
124136
var changes = new Commands.CountLocalChangesWithoutUntracked(_repo.FullPath).Result();
@@ -176,8 +188,18 @@ public override Task<bool> Sure()
176188
NoTags).Use(log).Exec();
177189
}
178190

179-
if (rs && needPopStash)
180-
rs = new Commands.Stash(_repo.FullPath).Use(log).Pop("stash@{0}");
191+
if (rs)
192+
{
193+
if (updateSubmodules)
194+
{
195+
var submodules = new Commands.QuerySubmodules(_repo.FullPath).Result();
196+
if (submodules.Count > 0)
197+
new Commands.Submodule(_repo.FullPath).Use(log).Update(submodules, true, true, false);
198+
}
199+
200+
if (needPopStash)
201+
new Commands.Stash(_repo.FullPath).Use(log).Pop("stash@{0}");
202+
}
181203

182204
log.Complete();
183205

src/Views/Pull.axaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<RowDefinition Height="32"/>
2222
<RowDefinition Height="32"/>
2323
<RowDefinition Height="32"/>
24+
<RowDefinition Height="Auto"/>
2425
</Grid.RowDefinitions>
2526

2627
<TextBlock Grid.Row="0" Grid.Column="0"
@@ -105,6 +106,13 @@
105106
Content="{DynamicResource Text.Pull.UseRebase}"
106107
IsChecked="{Binding UseRebase, Mode=TwoWay}"
107108
ToolTip.Tip="--rebase"/>
109+
110+
<CheckBox Grid.Row="7" Grid.Column="1"
111+
Height="32"
112+
Content="{DynamicResource Text.Pull.RecurseSubmodules}"
113+
IsChecked="{Binding RecurseSubmodules, Mode=TwoWay}"
114+
IsVisible="{Binding IsRecurseSubmoduleVisible}"
115+
ToolTip.Tip="--recurse-submodules"/>
108116
</Grid>
109117
</StackPanel>
110118
</UserControl>

0 commit comments

Comments
 (0)