enhance: remember last selected on common actions (#231)

* the way to deal with local changes on checkout branch page
* the way to deal with local changes and should checkout after created on new branch page
* should fetch without tags on fetch page
* the way to deal with local changes and should fetch without tags on pull page
* should push all tags on push
This commit is contained in:
leo 2024-07-03 14:41:43 +08:00
parent 7e16058148
commit f4f4a26a64
No known key found for this signature in database
6 changed files with 68 additions and 27 deletions

View file

@ -12,8 +12,8 @@ namespace SourceGit.ViewModels
public Models.DealWithLocalChanges PreAction public Models.DealWithLocalChanges PreAction
{ {
get => _preAction; get => _repo.Settings.DealWithLocalChangesOnCheckoutBranch;
set => SetProperty(ref _preAction, value); set => _repo.Settings.DealWithLocalChangesOnCheckoutBranch = value;
} }
public Checkout(Repository repo, string branch) public Checkout(Repository repo, string branch)
@ -34,7 +34,7 @@ namespace SourceGit.ViewModels
var needPopStash = false; var needPopStash = false;
if (hasLocalChanges) if (hasLocalChanges)
{ {
if (_preAction == Models.DealWithLocalChanges.StashAndReaply) if (PreAction == Models.DealWithLocalChanges.StashAndReaply)
{ {
SetProgressDescription("Adding untracked changes ..."); SetProgressDescription("Adding untracked changes ...");
var succ = new Commands.Add(_repo.FullPath).Exec(); var succ = new Commands.Add(_repo.FullPath).Exec();
@ -52,7 +52,7 @@ namespace SourceGit.ViewModels
needPopStash = true; needPopStash = true;
} }
else if (_preAction == Models.DealWithLocalChanges.Discard) else if (PreAction == Models.DealWithLocalChanges.Discard)
{ {
SetProgressDescription("Discard local changes ..."); SetProgressDescription("Discard local changes ...");
Commands.Discard.All(_repo.FullPath); Commands.Discard.All(_repo.FullPath);
@ -78,6 +78,5 @@ namespace SourceGit.ViewModels
} }
private readonly Repository _repo = null; private readonly Repository _repo = null;
private Models.DealWithLocalChanges _preAction = Models.DealWithLocalChanges.DoNothing;
} }
} }

View file

@ -22,15 +22,15 @@ namespace SourceGit.ViewModels
public Models.DealWithLocalChanges PreAction public Models.DealWithLocalChanges PreAction
{ {
get => _preAction; get => _repo.Settings.DealWithLocalChangesOnCreateBranch;
set => SetProperty(ref _preAction, value); set => _repo.Settings.DealWithLocalChangesOnCreateBranch = value;
} }
public bool CheckoutAfterCreated public bool CheckoutAfterCreated
{ {
get; get => _repo.Settings.CheckoutBranchOnCreateBranch;
set; set => _repo.Settings.CheckoutBranchOnCreateBranch = value;
} = true; }
public CreateBranch(Repository repo, Models.Branch branch) public CreateBranch(Repository repo, Models.Branch branch)
{ {
@ -89,7 +89,7 @@ namespace SourceGit.ViewModels
bool needPopStash = false; bool needPopStash = false;
if (_repo.WorkingCopyChangesCount > 0) if (_repo.WorkingCopyChangesCount > 0)
{ {
if (_preAction == Models.DealWithLocalChanges.StashAndReaply) if (PreAction == Models.DealWithLocalChanges.StashAndReaply)
{ {
SetProgressDescription("Adding untracked changes..."); SetProgressDescription("Adding untracked changes...");
var succ = new Commands.Add(_repo.FullPath).Exec(); var succ = new Commands.Add(_repo.FullPath).Exec();
@ -107,7 +107,7 @@ namespace SourceGit.ViewModels
needPopStash = true; needPopStash = true;
} }
else if (_preAction == Models.DealWithLocalChanges.Discard) else if (PreAction == Models.DealWithLocalChanges.Discard)
{ {
SetProgressDescription("Discard local changes..."); SetProgressDescription("Discard local changes...");
Commands.Discard.All(_repo.FullPath); Commands.Discard.All(_repo.FullPath);
@ -137,6 +137,5 @@ namespace SourceGit.ViewModels
private readonly Repository _repo = null; private readonly Repository _repo = null;
private string _name = null; private string _name = null;
private readonly string _baseOnRevision = null; private readonly string _baseOnRevision = null;
private Models.DealWithLocalChanges _preAction = Models.DealWithLocalChanges.DoNothing;
} }
} }

View file

@ -30,9 +30,9 @@ namespace SourceGit.ViewModels
public bool NoTags public bool NoTags
{ {
get; get => _repo.Settings.FetchWithoutTags;
set; set => _repo.Settings.FetchWithoutTags = value;
} = false; }
public Fetch(Repository repo, Models.Remote preferedRemote = null) public Fetch(Repository repo, Models.Remote preferedRemote = null)
{ {
@ -45,6 +45,7 @@ namespace SourceGit.ViewModels
public override Task<bool> Sure() public override Task<bool> Sure()
{ {
_repo.SetWatcherEnabled(false); _repo.SetWatcherEnabled(false);
return Task.Run(() => return Task.Run(() =>
{ {
if (FetchAllRemotes) if (FetchAllRemotes)

View file

@ -49,8 +49,8 @@ namespace SourceGit.ViewModels
public Models.DealWithLocalChanges PreAction public Models.DealWithLocalChanges PreAction
{ {
get => _preAction; get => _repo.Settings.DealWithLocalChangesOnPull;
set => SetProperty(ref _preAction, value); set => _repo.Settings.DealWithLocalChangesOnPull = value;
} }
public bool UseRebase public bool UseRebase
@ -61,9 +61,9 @@ namespace SourceGit.ViewModels
public bool NoTags public bool NoTags
{ {
get; get => _repo.Settings.FetchWithoutTagsOnPull;
set; set => _repo.Settings.FetchWithoutTagsOnPull = value;
} = false; }
public Pull(Repository repo, Models.Branch specifiedRemoteBranch) public Pull(Repository repo, Models.Branch specifiedRemoteBranch)
{ {
@ -120,12 +120,13 @@ namespace SourceGit.ViewModels
public override Task<bool> Sure() public override Task<bool> Sure()
{ {
_repo.SetWatcherEnabled(false); _repo.SetWatcherEnabled(false);
return Task.Run(() => return Task.Run(() =>
{ {
var needPopStash = false; var needPopStash = false;
if (_repo.WorkingCopyChangesCount > 0) if (_repo.WorkingCopyChangesCount > 0)
{ {
if (_preAction == Models.DealWithLocalChanges.StashAndReaply) if (PreAction == Models.DealWithLocalChanges.StashAndReaply)
{ {
SetProgressDescription("Adding untracked changes..."); SetProgressDescription("Adding untracked changes...");
var succ = new Commands.Add(_repo.FullPath).Exec(); var succ = new Commands.Add(_repo.FullPath).Exec();
@ -143,7 +144,7 @@ namespace SourceGit.ViewModels
needPopStash = true; needPopStash = true;
} }
else if (_preAction == Models.DealWithLocalChanges.Discard) else if (PreAction == Models.DealWithLocalChanges.Discard)
{ {
SetProgressDescription("Discard local changes ..."); SetProgressDescription("Discard local changes ...");
Commands.Discard.All(_repo.FullPath); Commands.Discard.All(_repo.FullPath);
@ -168,6 +169,5 @@ namespace SourceGit.ViewModels
private Models.Remote _selectedRemote = null; private Models.Remote _selectedRemote = null;
private List<Models.Branch> _remoteBranches = null; private List<Models.Branch> _remoteBranches = null;
private Models.Branch _selectedBranch = null; private Models.Branch _selectedBranch = null;
private Models.DealWithLocalChanges _preAction = Models.DealWithLocalChanges.DoNothing;
} }
} }

View file

@ -64,8 +64,8 @@ namespace SourceGit.ViewModels
public bool PushAllTags public bool PushAllTags
{ {
get; get => _repo.Settings.PushAllTags;
set; set => _repo.Settings.PushAllTags = value;
} }
public bool IsSetTrackOptionVisible public bool IsSetTrackOptionVisible

View file

@ -14,14 +14,56 @@ using CommunityToolkit.Mvvm.ComponentModel;
namespace SourceGit.ViewModels namespace SourceGit.ViewModels
{ {
public class RepositorySettings : ObservableObject public class RepositorySettings
{ {
public Models.DealWithLocalChanges DealWithLocalChangesOnCheckoutBranch
{
get;
set;
} = Models.DealWithLocalChanges.DoNothing;
public bool FetchWithoutTags
{
get;
set;
} = false;
public Models.DealWithLocalChanges DealWithLocalChangesOnPull
{
get;
set;
} = Models.DealWithLocalChanges.DoNothing;
public bool PreferRebaseInsteadOfMerge public bool PreferRebaseInsteadOfMerge
{ {
get; get;
set; set;
} = true; } = true;
public bool FetchWithoutTagsOnPull
{
get;
set;
} = false;
public bool PushAllTags
{
get;
set;
} = false;
public Models.DealWithLocalChanges DealWithLocalChangesOnCreateBranch
{
get;
set;
} = Models.DealWithLocalChanges.DoNothing;
public bool CheckoutBranchOnCreateBranch
{
get;
set;
} = true;
public AvaloniaList<string> Filters public AvaloniaList<string> Filters
{ {
get; get;