From 3e530de9cc60eca5b74ae73251f82a27c98ff6f1 Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 9 May 2025 17:12:12 +0800 Subject: [PATCH] enhance: update submodules individually (#1272) Signed-off-by: leo --- src/Commands/Checkout.cs | 10 ++++------ src/ViewModels/Checkout.cs | 11 +++++++++-- src/ViewModels/Clone.cs | 6 ++---- src/ViewModels/CreateBranch.cs | 11 +++++++++-- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/Commands/Checkout.cs b/src/Commands/Checkout.cs index b0274e7d..62c16bcf 100644 --- a/src/Commands/Checkout.cs +++ b/src/Commands/Checkout.cs @@ -11,17 +11,15 @@ namespace SourceGit.Commands Context = repo; } - public bool Branch(string branch, bool recurseSubmodules) + public bool Branch(string branch) { - var options = recurseSubmodules ? "--recurse-submodules" : string.Empty; - Args = $"checkout {options} --progress {branch}"; + Args = $"checkout --force --progress {branch}"; return Exec(); } - public bool Branch(string branch, string basedOn, bool recurseSubmodules) + public bool Branch(string branch, string basedOn) { - var options = recurseSubmodules ? "--recurse-submodules" : string.Empty; - Args = $"checkout {options} --progress -b {branch} {basedOn}"; + Args = $"checkout --force --progress -b {branch} {basedOn}"; return Exec(); } diff --git a/src/ViewModels/Checkout.cs b/src/ViewModels/Checkout.cs index 67db08c9..b1d6dffc 100644 --- a/src/ViewModels/Checkout.cs +++ b/src/ViewModels/Checkout.cs @@ -68,8 +68,15 @@ namespace SourceGit.ViewModels } } - var rs = new Commands.Checkout(_repo.FullPath).Use(log).Branch(Branch, updateSubmodules); - if (needPopStash) + var rs = new Commands.Checkout(_repo.FullPath).Use(log).Branch(Branch); + if (rs && updateSubmodules) + { + var submodules = new Commands.QuerySubmodules(_repo.FullPath).Result(); + foreach (var submodule in submodules) + new Commands.Submodule(_repo.FullPath).Use(log).Update(submodule.Path, true, true, false); + } + + if (rs && needPopStash) rs = new Commands.Stash(_repo.FullPath).Use(log).Pop("stash@{0}"); log.Complete(); diff --git a/src/ViewModels/Clone.cs b/src/ViewModels/Clone.cs index ee5da69e..431cfb23 100644 --- a/src/ViewModels/Clone.cs +++ b/src/ViewModels/Clone.cs @@ -101,7 +101,6 @@ namespace SourceGit.ViewModels { ProgressDescription = "Clone ..."; - // Create a temp log. var log = new CommandLog("Clone"); Use(log); @@ -139,11 +138,10 @@ namespace SourceGit.ViewModels config.Set("remote.origin.sshkey", _sshKey); } - // individually update submodule (if any) if (InitAndUpdateSubmodules) { - var submoduleList = new Commands.QuerySubmodules(path).Result(); - foreach (var submodule in submoduleList) + var submodules = new Commands.QuerySubmodules(path).Result(); + foreach (var submodule in submodules) new Commands.Submodule(path).Use(log).Update(submodule.Path, true, true, false); } diff --git a/src/ViewModels/CreateBranch.cs b/src/ViewModels/CreateBranch.cs index 3a99d88c..6e27d0e2 100644 --- a/src/ViewModels/CreateBranch.cs +++ b/src/ViewModels/CreateBranch.cs @@ -142,8 +142,15 @@ namespace SourceGit.ViewModels } } - succ = new Commands.Checkout(_repo.FullPath).Use(log).Branch(fixedName, _baseOnRevision, updateSubmodules); - if (needPopStash) + succ = new Commands.Checkout(_repo.FullPath).Use(log).Branch(fixedName, _baseOnRevision); + if (succ && updateSubmodules) + { + var submodules = new Commands.QuerySubmodules(_repo.FullPath).Result(); + foreach (var submodule in submodules) + new Commands.Submodule(_repo.FullPath).Use(log).Update(submodule.Path, true, true, false); + } + + if (succ && needPopStash) new Commands.Stash(_repo.FullPath).Use(log).Pop("stash@{0}"); } else