mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-22 04:34:59 +00:00
feature: make --recurse-submdoules
an option while trying to checkout branch with submodules (#1272)
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
054bbf7e0c
commit
df29edd8f0
10 changed files with 80 additions and 11 deletions
|
@ -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<bool> 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}");
|
||||
|
||||
|
|
|
@ -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}");
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue