refactor: rewrite the way to deal with uncommitted local changes when checkout/pull/create branch (#1085)

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-03-13 10:21:54 +08:00
parent e430e847ff
commit 0e261cffd2
No known key found for this signature in database
21 changed files with 63 additions and 260 deletions

View file

@ -9,16 +9,17 @@ namespace SourceGit.ViewModels
get;
}
public Models.DealWithLocalChanges PreAction
public bool DiscardLocalChanges
{
get;
set;
} = Models.DealWithLocalChanges.DoNothing;
}
public Checkout(Repository repo, string branch)
{
_repo = repo;
Branch = branch;
DiscardLocalChanges = false;
View = new Views.Checkout() { DataContext = this };
}
@ -33,7 +34,12 @@ namespace SourceGit.ViewModels
var needPopStash = false;
if (changes > 0)
{
if (PreAction == Models.DealWithLocalChanges.StashAndReaply)
if (DiscardLocalChanges)
{
SetProgressDescription("Discard local changes ...");
Commands.Discard.All(_repo.FullPath, false);
}
else
{
SetProgressDescription("Stash local changes ...");
var succ = new Commands.Stash(_repo.FullPath).Push("CHECKOUT_AUTO_STASH");
@ -45,11 +51,6 @@ namespace SourceGit.ViewModels
needPopStash = true;
}
else if (PreAction == Models.DealWithLocalChanges.Discard)
{
SetProgressDescription("Discard local changes ...");
Commands.Discard.All(_repo.FullPath, false);
}
}
SetProgressDescription("Checkout branch ...");