refactor: remove ViewModels.WorkingCopy.StashAllAsync method

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo
2025-09-02 10:21:42 +08:00
parent ac1239b8fc
commit e076cbf6a5
4 changed files with 21 additions and 23 deletions

View File

@@ -1112,8 +1112,14 @@ namespace SourceGit.ViewModels
public async Task StashAllAsync(bool autoStart)
{
if (_workingCopy != null)
await _workingCopy.StashAllAsync(autoStart);
if (!CanCreatePopup())
return;
var popup = new StashChanges(this, null);
if (autoStart)
await ShowAndStartPopupAsync(popup);
else
ShowPopup(popup);
}
public async Task SkipMergeAsync()

View File

@@ -15,7 +15,7 @@ namespace SourceGit.ViewModels
public bool HasSelectedFiles
{
get;
get => _changes != null;
}
public bool IncludeUntracked
@@ -43,11 +43,10 @@ namespace SourceGit.ViewModels
set => _repo.Settings.ChangesAfterStashing = value;
}
public StashChanges(Repository repo, List<Models.Change> changes, bool hasSelectedFiles)
public StashChanges(Repository repo, List<Models.Change> selectedChanges)
{
_repo = repo;
_changes = changes;
HasSelectedFiles = hasSelectedFiles;
_changes = selectedChanges;
}
public override async Task<bool> Sure()
@@ -62,7 +61,7 @@ namespace SourceGit.ViewModels
var keepIndex = mode == DealWithChangesAfterStashing.KeepIndex;
bool succ;
if (!HasSelectedFiles)
if (_changes == null)
{
if (OnlyStaged)
{
@@ -74,8 +73,12 @@ namespace SourceGit.ViewModels
}
else
{
var all = await new Commands.QueryLocalChanges(_repo.FullPath, false)
.Use(log)
.GetResultAsync();
var staged = new List<Models.Change>();
foreach (var c in _changes)
foreach (var c in all)
{
if (c.Index != Models.ChangeState.None && c.Index != Models.ChangeState.Untracked)
staged.Add(c);

View File

@@ -342,17 +342,6 @@ namespace SourceGit.ViewModels
Native.OS.OpenWithDefaultEditor(absPath);
}
public async Task StashAllAsync(bool autoStart)
{
if (!_repo.CanCreatePopup())
return;
if (autoStart)
await _repo.ShowAndStartPopupAsync(new StashChanges(_repo, _cached, false));
else
_repo.ShowPopup(new StashChanges(_repo, _cached, false));
}
public async Task StageChangesAsync(List<Models.Change> changes, Models.Change next)
{
var canStaged = await GetCanStageChangesAsync(changes);

View File

@@ -372,7 +372,7 @@ namespace SourceGit.Views
stash.Click += (_, e) =>
{
if (repo.CanCreatePopup())
repo.ShowPopup(new ViewModels.StashChanges(repo, selectedUnstaged, true));
repo.ShowPopup(new ViewModels.StashChanges(repo, selectedUnstaged));
e.Handled = true;
};
@@ -769,7 +769,7 @@ namespace SourceGit.Views
stash.Click += (_, e) =>
{
if (repo.CanCreatePopup())
repo.ShowPopup(new ViewModels.StashChanges(repo, selectedUnstaged, true));
repo.ShowPopup(new ViewModels.StashChanges(repo, selectedUnstaged));
e.Handled = true;
};
@@ -956,7 +956,7 @@ namespace SourceGit.Views
stash.Click += (_, e) =>
{
if (repo.CanCreatePopup())
repo.ShowPopup(new ViewModels.StashChanges(repo, selectedStaged, true));
repo.ShowPopup(new ViewModels.StashChanges(repo, selectedStaged));
e.Handled = true;
};
@@ -1164,7 +1164,7 @@ namespace SourceGit.Views
stash.Click += (_, e) =>
{
if (repo.CanCreatePopup())
repo.ShowPopup(new ViewModels.StashChanges(repo, selectedStaged, true));
repo.ShowPopup(new ViewModels.StashChanges(repo, selectedStaged));
e.Handled = true;
};