mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-07 03:45:00 +00:00
refactor: rewrite checkout/create branch with submodules
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
e446e97f28
commit
0f6c8976af
8 changed files with 136 additions and 65 deletions
|
@ -46,17 +46,19 @@ namespace SourceGit.ViewModels
|
|||
var updateSubmodules = IsRecurseSubmoduleVisible && RecurseSubmodules;
|
||||
return Task.Run(() =>
|
||||
{
|
||||
var changes = new Commands.CountLocalChangesWithoutUntracked(_repo.FullPath).Result();
|
||||
var succ = false;
|
||||
var needPopStash = false;
|
||||
if (changes > 0)
|
||||
|
||||
if (DiscardLocalChanges)
|
||||
{
|
||||
if (DiscardLocalChanges)
|
||||
succ = new Commands.Checkout(_repo.FullPath).Use(log).Branch(Branch, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
var changes = new Commands.CountLocalChangesWithoutUntracked(_repo.FullPath).Result();
|
||||
if (changes > 0)
|
||||
{
|
||||
Commands.Discard.All(_repo.FullPath, false, log);
|
||||
}
|
||||
else
|
||||
{
|
||||
var succ = new Commands.Stash(_repo.FullPath).Use(log).Push("CHECKOUT_AUTO_STASH");
|
||||
succ = new Commands.Stash(_repo.FullPath).Use(log).Push("CHECKOUT_AUTO_STASH");
|
||||
if (!succ)
|
||||
{
|
||||
log.Complete();
|
||||
|
@ -66,18 +68,22 @@ namespace SourceGit.ViewModels
|
|||
|
||||
needPopStash = true;
|
||||
}
|
||||
|
||||
succ = new Commands.Checkout(_repo.FullPath).Use(log).Branch(Branch, false);
|
||||
}
|
||||
|
||||
var rs = new Commands.Checkout(_repo.FullPath).Use(log).Branch(Branch);
|
||||
if (rs && updateSubmodules)
|
||||
if (succ)
|
||||
{
|
||||
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 (updateSubmodules)
|
||||
{
|
||||
var submodules = new Commands.QuerySubmodules(_repo.FullPath).Result();
|
||||
if (submodules.Count > 0)
|
||||
new Commands.Submodule(_repo.FullPath).Use(log).Update(submodules, true, true, false);
|
||||
}
|
||||
|
||||
if (rs && needPopStash)
|
||||
rs = new Commands.Stash(_repo.FullPath).Use(log).Pop("stash@{0}");
|
||||
if (needPopStash)
|
||||
new Commands.Stash(_repo.FullPath).Use(log).Pop("stash@{0}");
|
||||
}
|
||||
|
||||
log.Complete();
|
||||
|
||||
|
@ -94,7 +100,7 @@ namespace SourceGit.ViewModels
|
|||
});
|
||||
|
||||
Task.Delay(400).Wait();
|
||||
return rs;
|
||||
return succ;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue