Skip to content

Commit 43e0cdc

Browse files
committed
feature: make --recurse-submdoules an option while trying to checkout branch with submodules (#1272)
Signed-off-by: leo <[email protected]>
1 parent d7e707b commit 43e0cdc

File tree

10 files changed

+80
-11
lines changed

10 files changed

+80
-11
lines changed

src/Commands/Checkout.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ public Checkout(string repo)
1111
Context = repo;
1212
}
1313

14-
public bool Branch(string branch)
14+
public bool Branch(string branch, bool recurseSubmodules)
1515
{
16-
Args = $"checkout --recurse-submodules --progress {branch}";
16+
var options = recurseSubmodules ? "--recurse-submodules" : string.Empty;
17+
Args = $"checkout {options} --progress {branch}";
1718
return Exec();
1819
}
1920

20-
public bool Branch(string branch, string basedOn)
21+
public bool Branch(string branch, string basedOn, bool recurseSubmodules)
2122
{
22-
Args = $"checkout --recurse-submodules --progress -b {branch} {basedOn}";
23+
var options = recurseSubmodules ? "--recurse-submodules" : string.Empty;
24+
Args = $"checkout {options} --progress -b {branch} {basedOn}";
2325
return Exec();
2426
}
2527

src/Models/RepositorySettings.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ public bool CheckoutBranchOnCreateBranch
110110
set;
111111
} = true;
112112

113+
public bool UpdateSubmodulesOnCheckoutBranch
114+
{
115+
get;
116+
set;
117+
} = true;
118+
113119
public AvaloniaList<Filter> HistoriesFilters
114120
{
115121
get;

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
<x:String x:Key="Text.Checkout.LocalChanges" xml:space="preserve">Local Changes:</x:String>
8383
<x:String x:Key="Text.Checkout.LocalChanges.Discard" xml:space="preserve">Discard</x:String>
8484
<x:String x:Key="Text.Checkout.LocalChanges.StashAndReply" xml:space="preserve">Stash &amp; Reapply</x:String>
85+
<x:String x:Key="Text.Checkout.RecurseSubmodules" xml:space="preserve">Update all submodules</x:String>
8586
<x:String x:Key="Text.Checkout.Target" xml:space="preserve">Branch:</x:String>
8687
<x:String x:Key="Text.CherryPick" xml:space="preserve">Cherry Pick</x:String>
8788
<x:String x:Key="Text.CherryPick.AppendSourceToMessage" xml:space="preserve">Append source to commit message</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
<x:String x:Key="Text.Checkout.LocalChanges" xml:space="preserve">未提交更改 :</x:String>
8787
<x:String x:Key="Text.Checkout.LocalChanges.Discard" xml:space="preserve">丢弃更改</x:String>
8888
<x:String x:Key="Text.Checkout.LocalChanges.StashAndReply" xml:space="preserve">贮藏并自动恢复</x:String>
89+
<x:String x:Key="Text.Checkout.RecurseSubmodules" xml:space="preserve">同时更新所有子模块</x:String>
8990
<x:String x:Key="Text.Checkout.Target" xml:space="preserve">目标分支 :</x:String>
9091
<x:String x:Key="Text.CherryPick" xml:space="preserve">挑选提交</x:String>
9192
<x:String x:Key="Text.CherryPick.AppendSourceToMessage" 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
@@ -86,6 +86,7 @@
8686
<x:String x:Key="Text.Checkout.LocalChanges" xml:space="preserve">未提交變更:</x:String>
8787
<x:String x:Key="Text.Checkout.LocalChanges.Discard" xml:space="preserve">捨棄變更</x:String>
8888
<x:String x:Key="Text.Checkout.LocalChanges.StashAndReply" xml:space="preserve">擱置變更並自動復原</x:String>
89+
<x:String x:Key="Text.Checkout.RecurseSubmodules" xml:space="preserve">同時更新所有子模組</x:String>
8990
<x:String x:Key="Text.Checkout.Target" xml:space="preserve">目標分支:</x:String>
9091
<x:String x:Key="Text.CherryPick" xml:space="preserve">揀選提交</x:String>
9192
<x:String x:Key="Text.CherryPick.AppendSourceToMessage" xml:space="preserve">提交資訊中追加來源資訊</x:String>

src/ViewModels/Checkout.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,24 @@ public bool DiscardLocalChanges
1515
set;
1616
}
1717

18+
public bool IsRecurseSubmoduleVisible
19+
{
20+
get;
21+
private set;
22+
}
23+
24+
public bool RecurseSubmodules
25+
{
26+
get => _repo.Settings.UpdateSubmodulesOnCheckoutBranch;
27+
set => _repo.Settings.UpdateSubmodulesOnCheckoutBranch = value;
28+
}
29+
1830
public Checkout(Repository repo, string branch)
1931
{
2032
_repo = repo;
2133
Branch = branch;
2234
DiscardLocalChanges = false;
35+
IsRecurseSubmoduleVisible = repo.Submodules.Count > 0;
2336
}
2437

2538
public override Task<bool> Sure()
@@ -30,6 +43,7 @@ public override Task<bool> Sure()
3043
var log = _repo.CreateLog($"Checkout '{Branch}'");
3144
Use(log);
3245

46+
var updateSubmodules = IsRecurseSubmoduleVisible && RecurseSubmodules;
3347
return Task.Run(() =>
3448
{
3549
var changes = new Commands.CountLocalChangesWithoutUntracked(_repo.FullPath).Result();
@@ -54,7 +68,7 @@ public override Task<bool> Sure()
5468
}
5569
}
5670

57-
var rs = new Commands.Checkout(_repo.FullPath).Use(log).Branch(Branch);
71+
var rs = new Commands.Checkout(_repo.FullPath).Use(log).Branch(Branch, updateSubmodules);
5872
if (needPopStash)
5973
rs = new Commands.Stash(_repo.FullPath).Use(log).Pop("stash@{0}");
6074

src/ViewModels/CreateBranch.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,33 @@ public bool DiscardLocalChanges
2828
public bool CheckoutAfterCreated
2929
{
3030
get => _repo.Settings.CheckoutBranchOnCreateBranch;
31-
set => _repo.Settings.CheckoutBranchOnCreateBranch = value;
31+
set
32+
{
33+
if (_repo.Settings.CheckoutBranchOnCreateBranch != value)
34+
{
35+
_repo.Settings.CheckoutBranchOnCreateBranch = value;
36+
OnPropertyChanged();
37+
}
38+
}
3239
}
3340

3441
public bool IsBareRepository
3542
{
3643
get => _repo.IsBare;
3744
}
3845

46+
public bool IsRecurseSubmoduleVisible
47+
{
48+
get;
49+
private set;
50+
}
51+
52+
public bool RecurseSubmodules
53+
{
54+
get => _repo.Settings.UpdateSubmodulesOnCheckoutBranch;
55+
set => _repo.Settings.UpdateSubmodulesOnCheckoutBranch = value;
56+
}
57+
3958
public CreateBranch(Repository repo, Models.Branch branch)
4059
{
4160
_repo = repo;
@@ -48,6 +67,7 @@ public CreateBranch(Repository repo, Models.Branch branch)
4867

4968
BasedOn = branch;
5069
DiscardLocalChanges = false;
70+
IsRecurseSubmoduleVisible = repo.Submodules.Count > 0;
5171
}
5272

5373
public CreateBranch(Repository repo, Models.Commit commit)
@@ -57,6 +77,7 @@ public CreateBranch(Repository repo, Models.Commit commit)
5777

5878
BasedOn = commit;
5979
DiscardLocalChanges = false;
80+
IsRecurseSubmoduleVisible = repo.Submodules.Count > 0;
6081
}
6182

6283
public CreateBranch(Repository repo, Models.Tag tag)
@@ -66,6 +87,7 @@ public CreateBranch(Repository repo, Models.Tag tag)
6687

6788
BasedOn = tag;
6889
DiscardLocalChanges = false;
90+
IsRecurseSubmoduleVisible = repo.Submodules.Count > 0;
6991
}
7092

7193
public static ValidationResult ValidateBranchName(string name, ValidationContext ctx)
@@ -92,6 +114,7 @@ public override Task<bool> Sure()
92114
var log = _repo.CreateLog($"Create Branch '{fixedName}'");
93115
Use(log);
94116

117+
var updateSubmodules = IsRecurseSubmoduleVisible && RecurseSubmodules;
95118
return Task.Run(() =>
96119
{
97120
bool succ;
@@ -119,7 +142,7 @@ public override Task<bool> Sure()
119142
}
120143
}
121144

122-
succ = new Commands.Checkout(_repo.FullPath).Use(log).Branch(fixedName, _baseOnRevision);
145+
succ = new Commands.Checkout(_repo.FullPath).Use(log).Branch(fixedName, _baseOnRevision, updateSubmodules);
123146
if (needPopStash)
124147
new Commands.Stash(_repo.FullPath).Use(log).Pop("stash@{0}");
125148
}

src/ViewModels/Repository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,7 @@ public void CheckoutBranch(Models.Branch branch)
11541154

11551155
if (branch.IsLocal)
11561156
{
1157-
if (_localChangesCount > 0)
1157+
if (_localChangesCount > 0 || _submodules.Count > 0)
11581158
ShowPopup(new Checkout(this, branch.Name));
11591159
else
11601160
ShowAndStartPopup(new Checkout(this, branch.Name));

src/Views/Checkout.axaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<Grid.RowDefinitions>
1818
<RowDefinition Height="32"/>
1919
<RowDefinition Height="Auto" MinHeight="32"/>
20+
<RowDefinition Height="Auto"/>
2021
</Grid.RowDefinitions>
2122

2223
<TextBlock Grid.Row="0" Grid.Column="0"
@@ -35,11 +36,18 @@
3536
<WrapPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center">
3637
<RadioButton GroupName="LocalChanges"
3738
Margin="0,0,8,0"
38-
Content="{DynamicResource Text.CreateBranch.LocalChanges.StashAndReply}"
39+
Content="{DynamicResource Text.Checkout.LocalChanges.StashAndReply}"
3940
IsChecked="{Binding !DiscardLocalChanges, Mode=TwoWay}"/>
4041
<RadioButton GroupName="LocalChanges"
41-
Content="{DynamicResource Text.CreateBranch.LocalChanges.Discard}"/>
42+
Content="{DynamicResource Text.Checkout.LocalChanges.Discard}"/>
4243
</WrapPanel>
44+
45+
<CheckBox Grid.Row="2" Grid.Column="1"
46+
Height="32"
47+
Content="{DynamicResource Text.Checkout.RecurseSubmodules}"
48+
IsChecked="{Binding RecurseSubmodules, Mode=TwoWay}"
49+
IsVisible="{Binding IsRecurseSubmoduleVisible}"
50+
ToolTip.Tip="--recurse-submodules"/>
4351
</Grid>
4452
</StackPanel>
4553
</UserControl>

src/Views/CreateBranch.axaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<TextBlock FontSize="18"
1515
Classes="bold"
1616
Text="{DynamicResource Text.CreateBranch.Title}"/>
17-
<Grid Margin="0,16,0,0" RowDefinitions="32,32,Auto,Auto,Auto" ColumnDefinitions="140,*">
17+
<Grid Margin="0,16,0,0" RowDefinitions="32,32,Auto,Auto,Auto,Auto" ColumnDefinitions="140,*">
1818
<TextBlock Grid.Row="0" Grid.Column="0"
1919
HorizontalAlignment="Right" VerticalAlignment="Center"
2020
Margin="0,0,8,0"
@@ -83,6 +83,19 @@
8383
Content="{DynamicResource Text.CreateBranch.Checkout}"
8484
IsChecked="{Binding CheckoutAfterCreated, Mode=TwoWay}"
8585
IsVisible="{Binding !IsBareRepository}"/>
86+
87+
<CheckBox Grid.Row="5" Grid.Column="1"
88+
Content="{DynamicResource Text.Checkout.RecurseSubmodules}"
89+
IsChecked="{Binding RecurseSubmodules, Mode=TwoWay}"
90+
ToolTip.Tip="--recurse-submodules">
91+
<CheckBox.IsVisible>
92+
<MultiBinding Converter="{x:Static BoolConverters.And}">
93+
<Binding Path="IsBareRepository" Converter="{x:Static BoolConverters.Not}"/>
94+
<Binding Path="CheckoutAfterCreated"/>
95+
<Binding Path="IsRecurseSubmoduleVisible"/>
96+
</MultiBinding>
97+
</CheckBox.IsVisible>
98+
</CheckBox>
8699
</Grid>
87100
</StackPanel>
88101
</UserControl>

0 commit comments

Comments
 (0)