diff --git a/src/Commands/Checkout.cs b/src/Commands/Checkout.cs index c39c28ae..b0274e7d 100644 --- a/src/Commands/Checkout.cs +++ b/src/Commands/Checkout.cs @@ -11,15 +11,17 @@ namespace SourceGit.Commands Context = repo; } - public bool Branch(string branch) + public bool Branch(string branch, bool recurseSubmodules) { - Args = $"checkout --recurse-submodules --progress {branch}"; + var options = recurseSubmodules ? "--recurse-submodules" : string.Empty; + Args = $"checkout {options} --progress {branch}"; return Exec(); } - public bool Branch(string branch, string basedOn) + public bool Branch(string branch, string basedOn, bool recurseSubmodules) { - Args = $"checkout --recurse-submodules --progress -b {branch} {basedOn}"; + var options = recurseSubmodules ? "--recurse-submodules" : string.Empty; + Args = $"checkout {options} --progress -b {branch} {basedOn}"; return Exec(); } diff --git a/src/Models/RepositorySettings.cs b/src/Models/RepositorySettings.cs index 34a72033..3df463b3 100644 --- a/src/Models/RepositorySettings.cs +++ b/src/Models/RepositorySettings.cs @@ -110,6 +110,12 @@ namespace SourceGit.Models set; } = true; + public bool UpdateSubmodulesOnCheckoutBranch + { + get; + set; + } = true; + public AvaloniaList HistoriesFilters { get; diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index f4c62a90..640cb8f3 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -82,6 +82,7 @@ Local Changes: Discard Stash & Reapply + Update all submodules Branch: Cherry Pick Append source to commit message diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 8ee210e9..5db542b1 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -86,6 +86,7 @@ 未提交更改 : 丢弃更改 贮藏并自动恢复 + 同时更新所有子模块 目标分支 : 挑选提交 提交信息中追加来源信息 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index 7430d609..6fd380ec 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -86,6 +86,7 @@ 未提交變更: 捨棄變更 擱置變更並自動復原 + 同時更新所有子模組 目標分支: 揀選提交 提交資訊中追加來源資訊 diff --git a/src/ViewModels/Checkout.cs b/src/ViewModels/Checkout.cs index a96ac79a..67db08c9 100644 --- a/src/ViewModels/Checkout.cs +++ b/src/ViewModels/Checkout.cs @@ -15,11 +15,24 @@ namespace SourceGit.ViewModels set; } + public bool IsRecurseSubmoduleVisible + { + get; + private set; + } + + public bool RecurseSubmodules + { + get => _repo.Settings.UpdateSubmodulesOnCheckoutBranch; + set => _repo.Settings.UpdateSubmodulesOnCheckoutBranch = value; + } + public Checkout(Repository repo, string branch) { _repo = repo; Branch = branch; DiscardLocalChanges = false; + IsRecurseSubmoduleVisible = repo.Submodules.Count > 0; } public override Task Sure() @@ -30,6 +43,7 @@ namespace SourceGit.ViewModels var log = _repo.CreateLog($"Checkout '{Branch}'"); Use(log); + var updateSubmodules = IsRecurseSubmoduleVisible && RecurseSubmodules; return Task.Run(() => { var changes = new Commands.CountLocalChangesWithoutUntracked(_repo.FullPath).Result(); @@ -54,7 +68,7 @@ namespace SourceGit.ViewModels } } - var rs = new Commands.Checkout(_repo.FullPath).Use(log).Branch(Branch); + var rs = new Commands.Checkout(_repo.FullPath).Use(log).Branch(Branch, updateSubmodules); if (needPopStash) rs = new Commands.Stash(_repo.FullPath).Use(log).Pop("stash@{0}"); diff --git a/src/ViewModels/CreateBranch.cs b/src/ViewModels/CreateBranch.cs index dd190e18..3a99d88c 100644 --- a/src/ViewModels/CreateBranch.cs +++ b/src/ViewModels/CreateBranch.cs @@ -28,7 +28,14 @@ namespace SourceGit.ViewModels public bool CheckoutAfterCreated { get => _repo.Settings.CheckoutBranchOnCreateBranch; - set => _repo.Settings.CheckoutBranchOnCreateBranch = value; + set + { + if (_repo.Settings.CheckoutBranchOnCreateBranch != value) + { + _repo.Settings.CheckoutBranchOnCreateBranch = value; + OnPropertyChanged(); + } + } } public bool IsBareRepository @@ -36,6 +43,18 @@ namespace SourceGit.ViewModels get => _repo.IsBare; } + public bool IsRecurseSubmoduleVisible + { + get; + private set; + } + + public bool RecurseSubmodules + { + get => _repo.Settings.UpdateSubmodulesOnCheckoutBranch; + set => _repo.Settings.UpdateSubmodulesOnCheckoutBranch = value; + } + public CreateBranch(Repository repo, Models.Branch branch) { _repo = repo; @@ -48,6 +67,7 @@ namespace SourceGit.ViewModels BasedOn = branch; DiscardLocalChanges = false; + IsRecurseSubmoduleVisible = repo.Submodules.Count > 0; } public CreateBranch(Repository repo, Models.Commit commit) @@ -57,6 +77,7 @@ namespace SourceGit.ViewModels BasedOn = commit; DiscardLocalChanges = false; + IsRecurseSubmoduleVisible = repo.Submodules.Count > 0; } public CreateBranch(Repository repo, Models.Tag tag) @@ -66,6 +87,7 @@ namespace SourceGit.ViewModels BasedOn = tag; DiscardLocalChanges = false; + IsRecurseSubmoduleVisible = repo.Submodules.Count > 0; } public static ValidationResult ValidateBranchName(string name, ValidationContext ctx) @@ -92,6 +114,7 @@ namespace SourceGit.ViewModels var log = _repo.CreateLog($"Create Branch '{fixedName}'"); Use(log); + var updateSubmodules = IsRecurseSubmoduleVisible && RecurseSubmodules; return Task.Run(() => { bool succ; @@ -119,7 +142,7 @@ namespace SourceGit.ViewModels } } - succ = new Commands.Checkout(_repo.FullPath).Use(log).Branch(fixedName, _baseOnRevision); + succ = new Commands.Checkout(_repo.FullPath).Use(log).Branch(fixedName, _baseOnRevision, updateSubmodules); if (needPopStash) new Commands.Stash(_repo.FullPath).Use(log).Pop("stash@{0}"); } diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 289d890f..5e8bd40d 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -1154,7 +1154,7 @@ namespace SourceGit.ViewModels if (branch.IsLocal) { - if (_localChangesCount > 0) + if (_localChangesCount > 0 || _submodules.Count > 0) ShowPopup(new Checkout(this, branch.Name)); else ShowAndStartPopup(new Checkout(this, branch.Name)); diff --git a/src/Views/Checkout.axaml b/src/Views/Checkout.axaml index 3cdfd94e..42b9cec5 100644 --- a/src/Views/Checkout.axaml +++ b/src/Views/Checkout.axaml @@ -17,6 +17,7 @@ + + Content="{DynamicResource Text.Checkout.LocalChanges.Discard}"/> + + diff --git a/src/Views/CreateBranch.axaml b/src/Views/CreateBranch.axaml index a5f1f212..e77f8751 100644 --- a/src/Views/CreateBranch.axaml +++ b/src/Views/CreateBranch.axaml @@ -14,7 +14,7 @@ - + + + + + + + + + + +