enhance: update submodules individually (#1272)

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-05-09 17:12:12 +08:00
parent 6cf1b20ea6
commit 3e530de9cc
No known key found for this signature in database
4 changed files with 24 additions and 14 deletions

View file

@ -11,17 +11,15 @@ namespace SourceGit.Commands
Context = repo; Context = repo;
} }
public bool Branch(string branch, bool recurseSubmodules) public bool Branch(string branch)
{ {
var options = recurseSubmodules ? "--recurse-submodules" : string.Empty; Args = $"checkout --force --progress {branch}";
Args = $"checkout {options} --progress {branch}";
return Exec(); 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 --force --progress -b {branch} {basedOn}";
Args = $"checkout {options} --progress -b {branch} {basedOn}";
return Exec(); return Exec();
} }

View file

@ -68,8 +68,15 @@ namespace SourceGit.ViewModels
} }
} }
var rs = new Commands.Checkout(_repo.FullPath).Use(log).Branch(Branch, updateSubmodules); var rs = new Commands.Checkout(_repo.FullPath).Use(log).Branch(Branch);
if (needPopStash) 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}"); rs = new Commands.Stash(_repo.FullPath).Use(log).Pop("stash@{0}");
log.Complete(); log.Complete();

View file

@ -101,7 +101,6 @@ namespace SourceGit.ViewModels
{ {
ProgressDescription = "Clone ..."; ProgressDescription = "Clone ...";
// Create a temp log.
var log = new CommandLog("Clone"); var log = new CommandLog("Clone");
Use(log); Use(log);
@ -139,11 +138,10 @@ namespace SourceGit.ViewModels
config.Set("remote.origin.sshkey", _sshKey); config.Set("remote.origin.sshkey", _sshKey);
} }
// individually update submodule (if any)
if (InitAndUpdateSubmodules) if (InitAndUpdateSubmodules)
{ {
var submoduleList = new Commands.QuerySubmodules(path).Result(); var submodules = new Commands.QuerySubmodules(path).Result();
foreach (var submodule in submoduleList) foreach (var submodule in submodules)
new Commands.Submodule(path).Use(log).Update(submodule.Path, true, true, false); new Commands.Submodule(path).Use(log).Update(submodule.Path, true, true, false);
} }

View file

@ -142,8 +142,15 @@ namespace SourceGit.ViewModels
} }
} }
succ = new Commands.Checkout(_repo.FullPath).Use(log).Branch(fixedName, _baseOnRevision, updateSubmodules); succ = new Commands.Checkout(_repo.FullPath).Use(log).Branch(fixedName, _baseOnRevision);
if (needPopStash) 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}"); new Commands.Stash(_repo.FullPath).Use(log).Pop("stash@{0}");
} }
else else