Skip to content

Commit 3e530de

Browse files
committed
enhance: update submodules individually (#1272)
Signed-off-by: leo <[email protected]>
1 parent 6cf1b20 commit 3e530de

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

src/Commands/Checkout.cs

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

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

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

src/ViewModels/Checkout.cs

+9-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,15 @@ public override Task<bool> Sure()
6868
}
6969
}
7070

71-
var rs = new Commands.Checkout(_repo.FullPath).Use(log).Branch(Branch, updateSubmodules);
72-
if (needPopStash)
71+
var rs = new Commands.Checkout(_repo.FullPath).Use(log).Branch(Branch);
72+
if (rs && updateSubmodules)
73+
{
74+
var submodules = new Commands.QuerySubmodules(_repo.FullPath).Result();
75+
foreach (var submodule in submodules)
76+
new Commands.Submodule(_repo.FullPath).Use(log).Update(submodule.Path, true, true, false);
77+
}
78+
79+
if (rs && needPopStash)
7380
rs = new Commands.Stash(_repo.FullPath).Use(log).Pop("stash@{0}");
7481

7582
log.Complete();

src/ViewModels/Clone.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ public override Task<bool> Sure()
101101
{
102102
ProgressDescription = "Clone ...";
103103

104-
// Create a temp log.
105104
var log = new CommandLog("Clone");
106105
Use(log);
107106

@@ -139,11 +138,10 @@ public override Task<bool> Sure()
139138
config.Set("remote.origin.sshkey", _sshKey);
140139
}
141140

142-
// individually update submodule (if any)
143141
if (InitAndUpdateSubmodules)
144142
{
145-
var submoduleList = new Commands.QuerySubmodules(path).Result();
146-
foreach (var submodule in submoduleList)
143+
var submodules = new Commands.QuerySubmodules(path).Result();
144+
foreach (var submodule in submodules)
147145
new Commands.Submodule(path).Use(log).Update(submodule.Path, true, true, false);
148146
}
149147

src/ViewModels/CreateBranch.cs

+9-2
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,15 @@ public override Task<bool> Sure()
142142
}
143143
}
144144

145-
succ = new Commands.Checkout(_repo.FullPath).Use(log).Branch(fixedName, _baseOnRevision, updateSubmodules);
146-
if (needPopStash)
145+
succ = new Commands.Checkout(_repo.FullPath).Use(log).Branch(fixedName, _baseOnRevision);
146+
if (succ && updateSubmodules)
147+
{
148+
var submodules = new Commands.QuerySubmodules(_repo.FullPath).Result();
149+
foreach (var submodule in submodules)
150+
new Commands.Submodule(_repo.FullPath).Use(log).Update(submodule.Path, true, true, false);
151+
}
152+
153+
if (succ && needPopStash)
147154
new Commands.Stash(_repo.FullPath).Use(log).Pop("stash@{0}");
148155
}
149156
else

0 commit comments

Comments
 (0)