Skip to content

Commit 3c9a792

Browse files
committed
feature: add a repository configuration - Ask before auto-updating submodules (default false) (#2045)
Signed-off-by: leo <[email protected]>
1 parent f72684b commit 3c9a792

File tree

14 files changed

+60
-30
lines changed

14 files changed

+60
-30
lines changed

src/Models/RepositorySettings.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ public bool OnlyStagedWhenStash
161161
set;
162162
} = false;
163163

164+
public bool AskBeforeAutoUpdatingSubmodules
165+
{
166+
get;
167+
set;
168+
} = false;
169+
164170
public int ChangesAfterStashing
165171
{
166172
get;

src/Resources/Locales/en_US.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
<x:String x:Key="Text.Checkout.LocalChanges.StashAndReapply" xml:space="preserve">Stash &amp; Reapply</x:String>
109109
<x:String x:Key="Text.Checkout.Target" xml:space="preserve">Branch:</x:String>
110110
<x:String x:Key="Text.Checkout.WarnLostCommits" xml:space="preserve">Your current HEAD contains commit(s) not connected to any branches/tags! Do you want to continue?</x:String>
111+
<x:String x:Key="Text.Checkout.WarnUpdatingSubmodules" xml:space="preserve">The following submodules need to be updated:{0}Do you want to update them?</x:String>
111112
<x:String x:Key="Text.Checkout.WithFastForward" xml:space="preserve">Checkout &amp; Fast-Forward</x:String>
112113
<x:String x:Key="Text.Checkout.WithFastForward.Upstream" xml:space="preserve">Fast-Forward to:</x:String>
113114
<x:String x:Key="Text.CherryPick" xml:space="preserve">Cherry Pick</x:String>
@@ -224,6 +225,7 @@
224225
<x:String x:Key="Text.Configure.Email" xml:space="preserve">Email Address</x:String>
225226
<x:String x:Key="Text.Configure.Email.Placeholder" xml:space="preserve">Email address</x:String>
226227
<x:String x:Key="Text.Configure.Git" xml:space="preserve">GIT</x:String>
228+
<x:String x:Key="Text.Configure.Git.AskBeforeAutoUpdatingSubmodules" xml:space="preserve">Ask before auto-updating submodules</x:String>
227229
<x:String x:Key="Text.Configure.Git.AutoFetch" xml:space="preserve">Fetch remotes automatically</x:String>
228230
<x:String x:Key="Text.Configure.Git.AutoFetchIntervalSuffix" xml:space="preserve">Minute(s)</x:String>
229231
<x:String x:Key="Text.Configure.Git.ConventionalTypesOverride" xml:space="preserve">Conventional Commit Types</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
<x:String x:Key="Text.Checkout.LocalChanges.StashAndReapply" xml:space="preserve">贮藏并自动恢复</x:String>
113113
<x:String x:Key="Text.Checkout.Target" xml:space="preserve">目标分支 :</x:String>
114114
<x:String x:Key="Text.Checkout.WarnLostCommits" xml:space="preserve">您当前游离的HEAD包含未被任何分支及标签引用的提交!是否继续?</x:String>
115+
<x:String x:Key="Text.Checkout.WarnUpdatingSubmodules" xml:space="preserve">以下子模块需要更新:{0}是否立即更新?</x:String>
115116
<x:String x:Key="Text.Checkout.WithFastForward" xml:space="preserve">检出分支并快进</x:String>
116117
<x:String x:Key="Text.Checkout.WithFastForward.Upstream" xml:space="preserve">上游分支 :</x:String>
117118
<x:String x:Key="Text.CherryPick" xml:space="preserve">挑选提交</x:String>
@@ -228,6 +229,7 @@
228229
<x:String x:Key="Text.Configure.Email" xml:space="preserve">电子邮箱</x:String>
229230
<x:String x:Key="Text.Configure.Email.Placeholder" xml:space="preserve">邮箱地址</x:String>
230231
<x:String x:Key="Text.Configure.Git" xml:space="preserve">GIT配置</x:String>
232+
<x:String x:Key="Text.Configure.Git.AskBeforeAutoUpdatingSubmodules" xml:space="preserve">在自动更新子模块前询问用户</x:String>
231233
<x:String x:Key="Text.Configure.Git.AutoFetch" xml:space="preserve">启用定时自动拉取远程更新</x:String>
232234
<x:String x:Key="Text.Configure.Git.AutoFetchIntervalSuffix" xml:space="preserve">分钟</x:String>
233235
<x:String x:Key="Text.Configure.Git.ConventionalTypesOverride" xml:space="preserve">自定义规范化提交类型</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
<x:String x:Key="Text.Checkout.LocalChanges.StashAndReapply" xml:space="preserve">擱置變更並自動復原</x:String>
113113
<x:String x:Key="Text.Checkout.Target" xml:space="preserve">目標分支:</x:String>
114114
<x:String x:Key="Text.Checkout.WarnLostCommits" xml:space="preserve">您目前的分離的 HEAD 包含與任何分支/標籤無關的提交! 您要繼續嗎?</x:String>
115+
<x:String x:Key="Text.Checkout.WarnUpdatingSubmodules" xml:space="preserve">以下子模組需要更新:{0}您想立即更新它們嗎?</x:String>
115116
<x:String x:Key="Text.Checkout.WithFastForward" xml:space="preserve">簽出分支並快轉</x:String>
116117
<x:String x:Key="Text.Checkout.WithFastForward.Upstream" xml:space="preserve">上游分支: </x:String>
117118
<x:String x:Key="Text.CherryPick" xml:space="preserve">揀選提交</x:String>
@@ -228,6 +229,7 @@
228229
<x:String x:Key="Text.Configure.Email" xml:space="preserve">電子郵件</x:String>
229230
<x:String x:Key="Text.Configure.Email.Placeholder" xml:space="preserve">電子郵件地址</x:String>
230231
<x:String x:Key="Text.Configure.Git" xml:space="preserve">Git 設定</x:String>
232+
<x:String x:Key="Text.Configure.Git.AskBeforeAutoUpdatingSubmodules" xml:space="preserve">在自動更新子模組之前詢問用戶</x:String>
231233
<x:String x:Key="Text.Configure.Git.AutoFetch" xml:space="preserve">啟用定時自動提取 (fetch) 遠端更新</x:String>
232234
<x:String x:Key="Text.Configure.Git.AutoFetchIntervalSuffix" xml:space="preserve">分鐘</x:String>
233235
<x:String x:Key="Text.Configure.Git.ConventionalTypesOverride" xml:space="preserve">自訂約定式提交類型</x:String>

src/ViewModels/Checkout.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,7 @@ public override async Task<bool> Sure()
6969

7070
if (succ)
7171
{
72-
var submodules = await new Commands.QueryUpdatableSubmodules(_repo.FullPath, false).GetResultAsync();
73-
if (submodules.Count > 0)
74-
await new Commands.Submodule(_repo.FullPath)
75-
.Use(log)
76-
.UpdateAsync(submodules);
72+
await _repo.TryAutoUpdateSubmodules(log);
7773

7874
if (needPopStash)
7975
await new Commands.Stash(_repo.FullPath)

src/ViewModels/CheckoutAndFastForward.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,7 @@ public override async Task<bool> Sure()
7474

7575
if (succ)
7676
{
77-
var submodules = await new Commands.QueryUpdatableSubmodules(_repo.FullPath, false).GetResultAsync();
78-
if (submodules.Count > 0)
79-
await new Commands.Submodule(_repo.FullPath)
80-
.Use(log)
81-
.UpdateAsync(submodules);
77+
await _repo.TryAutoUpdateSubmodules(log);
8278

8379
if (needPopStash)
8480
await new Commands.Stash(_repo.FullPath)

src/ViewModels/CheckoutCommit.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,7 @@ public override async Task<bool> Sure()
6969

7070
if (succ)
7171
{
72-
var submodules = await new Commands.QueryUpdatableSubmodules(_repo.FullPath, false).GetResultAsync();
73-
if (submodules.Count > 0)
74-
await new Commands.Submodule(_repo.FullPath)
75-
.Use(log)
76-
.UpdateAsync(submodules);
72+
await _repo.TryAutoUpdateSubmodules(log);
7773

7874
if (needPop)
7975
await new Commands.Stash(_repo.FullPath)

src/ViewModels/CreateBranch.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,7 @@ public override async Task<bool> Sure()
153153

154154
if (succ)
155155
{
156-
var submodules = await new Commands.QueryUpdatableSubmodules(_repo.FullPath, false).GetResultAsync();
157-
if (submodules.Count > 0)
158-
await new Commands.Submodule(_repo.FullPath)
159-
.Use(log)
160-
.UpdateAsync(submodules);
156+
await _repo.TryAutoUpdateSubmodules(log);
161157

162158
if (needPopStash)
163159
await new Commands.Stash(_repo.FullPath)

src/ViewModels/Merge.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,7 @@ public override async Task<bool> Sure()
9191
_repo.SetCommitMessage(msg);
9292
}
9393

94-
var submodules = await new Commands.QueryUpdatableSubmodules(_repo.FullPath, false).GetResultAsync();
95-
if (submodules.Count > 0)
96-
await new Commands.Submodule(_repo.FullPath)
97-
.Use(log)
98-
.UpdateAsync(submodules);
94+
await _repo.TryAutoUpdateSubmodules(log);
9995
}
10096

10197
log.Complete();

src/ViewModels/Pull.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,7 @@ public override async Task<bool> Sure()
135135
UseRebase).Use(log).RunAsync();
136136
if (rs)
137137
{
138-
var submodules = await new Commands.QueryUpdatableSubmodules(_repo.FullPath, false).GetResultAsync();
139-
if (submodules.Count > 0)
140-
await new Commands.Submodule(_repo.FullPath).Use(log).UpdateAsync(submodules);
138+
await _repo.TryAutoUpdateSubmodules(log);
141139

142140
if (needPopStash)
143141
await new Commands.Stash(_repo.FullPath).Use(log).PopAsync("stash@{0}");

0 commit comments

Comments
 (0)