mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-24 05:35:00 +00:00
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:
parent
e430e847ff
commit
0e261cffd2
21 changed files with 63 additions and 260 deletions
|
@ -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 ...");
|
||||
|
|
|
@ -9,16 +9,17 @@ namespace SourceGit.ViewModels
|
|||
get;
|
||||
}
|
||||
|
||||
public bool AutoStash
|
||||
public bool DiscardLocalChanges
|
||||
{
|
||||
get => _autoStash;
|
||||
set => SetProperty(ref _autoStash, value);
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public CheckoutCommit(Repository repo, Models.Commit commit)
|
||||
{
|
||||
_repo = repo;
|
||||
Commit = commit;
|
||||
DiscardLocalChanges = false;
|
||||
View = new Views.CheckoutCommit() { DataContext = this };
|
||||
}
|
||||
|
||||
|
@ -33,7 +34,12 @@ namespace SourceGit.ViewModels
|
|||
var needPopStash = false;
|
||||
if (changes > 0)
|
||||
{
|
||||
if (AutoStash)
|
||||
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
|
||||
{
|
||||
SetProgressDescription("Discard local changes ...");
|
||||
Commands.Discard.All(_repo.FullPath, false);
|
||||
}
|
||||
}
|
||||
|
||||
SetProgressDescription("Checkout commit ...");
|
||||
|
@ -67,6 +68,5 @@ namespace SourceGit.ViewModels
|
|||
}
|
||||
|
||||
private readonly Repository _repo = null;
|
||||
private bool _autoStash = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,11 +19,11 @@ namespace SourceGit.ViewModels
|
|||
get;
|
||||
}
|
||||
|
||||
public Models.DealWithLocalChanges PreAction
|
||||
public bool DiscardLocalChanges
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = Models.DealWithLocalChanges.DoNothing;
|
||||
}
|
||||
|
||||
public bool CheckoutAfterCreated
|
||||
{
|
||||
|
@ -47,6 +47,7 @@ namespace SourceGit.ViewModels
|
|||
}
|
||||
|
||||
BasedOn = branch;
|
||||
DiscardLocalChanges = false;
|
||||
View = new Views.CreateBranch() { DataContext = this };
|
||||
}
|
||||
|
||||
|
@ -56,6 +57,7 @@ namespace SourceGit.ViewModels
|
|||
_baseOnRevision = commit.SHA;
|
||||
|
||||
BasedOn = commit;
|
||||
DiscardLocalChanges = false;
|
||||
View = new Views.CreateBranch() { DataContext = this };
|
||||
}
|
||||
|
||||
|
@ -65,6 +67,7 @@ namespace SourceGit.ViewModels
|
|||
_baseOnRevision = tag.SHA;
|
||||
|
||||
BasedOn = tag;
|
||||
DiscardLocalChanges = false;
|
||||
View = new Views.CreateBranch() { DataContext = this };
|
||||
}
|
||||
|
||||
|
@ -98,7 +101,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");
|
||||
succ = new Commands.Stash(_repo.FullPath).Push("CREATE_BRANCH_AUTO_STASH");
|
||||
|
@ -110,11 +118,6 @@ namespace SourceGit.ViewModels
|
|||
|
||||
needPopStash = true;
|
||||
}
|
||||
else if (PreAction == Models.DealWithLocalChanges.Discard)
|
||||
{
|
||||
SetProgressDescription("Discard local changes...");
|
||||
Commands.Discard.All(_repo.FullPath, false);
|
||||
}
|
||||
}
|
||||
|
||||
SetProgressDescription($"Create new branch '{fixedName}'");
|
||||
|
|
|
@ -38,11 +38,11 @@ namespace SourceGit.ViewModels
|
|||
set => SetProperty(ref _selectedBranch, value, true);
|
||||
}
|
||||
|
||||
public Models.DealWithLocalChanges PreAction
|
||||
public bool DiscardLocalChanges
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = Models.DealWithLocalChanges.DoNothing;
|
||||
}
|
||||
|
||||
public bool UseRebase
|
||||
{
|
||||
|
@ -124,7 +124,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("PULL_AUTO_STASH");
|
||||
|
@ -136,11 +141,6 @@ namespace SourceGit.ViewModels
|
|||
|
||||
needPopStash = true;
|
||||
}
|
||||
else if (PreAction == Models.DealWithLocalChanges.Discard)
|
||||
{
|
||||
SetProgressDescription("Discard local changes ...");
|
||||
Commands.Discard.All(_repo.FullPath, false);
|
||||
}
|
||||
}
|
||||
|
||||
bool rs;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue