Skip to content

Commit f4f4a26

Browse files
committed
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
1 parent 7e16058 commit f4f4a26

File tree

6 files changed

+68
-27
lines changed

6 files changed

+68
-27
lines changed

src/ViewModels/Checkout.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ public string Branch
1212

1313
public Models.DealWithLocalChanges PreAction
1414
{
15-
get => _preAction;
16-
set => SetProperty(ref _preAction, value);
15+
get => _repo.Settings.DealWithLocalChangesOnCheckoutBranch;
16+
set => _repo.Settings.DealWithLocalChangesOnCheckoutBranch = value;
1717
}
1818

1919
public Checkout(Repository repo, string branch)
@@ -34,7 +34,7 @@ public override Task<bool> Sure()
3434
var needPopStash = false;
3535
if (hasLocalChanges)
3636
{
37-
if (_preAction == Models.DealWithLocalChanges.StashAndReaply)
37+
if (PreAction == Models.DealWithLocalChanges.StashAndReaply)
3838
{
3939
SetProgressDescription("Adding untracked changes ...");
4040
var succ = new Commands.Add(_repo.FullPath).Exec();
@@ -52,7 +52,7 @@ public override Task<bool> Sure()
5252

5353
needPopStash = true;
5454
}
55-
else if (_preAction == Models.DealWithLocalChanges.Discard)
55+
else if (PreAction == Models.DealWithLocalChanges.Discard)
5656
{
5757
SetProgressDescription("Discard local changes ...");
5858
Commands.Discard.All(_repo.FullPath);
@@ -78,6 +78,5 @@ public override Task<bool> Sure()
7878
}
7979

8080
private readonly Repository _repo = null;
81-
private Models.DealWithLocalChanges _preAction = Models.DealWithLocalChanges.DoNothing;
8281
}
8382
}

src/ViewModels/CreateBranch.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ public object BasedOn
2222

2323
public Models.DealWithLocalChanges PreAction
2424
{
25-
get => _preAction;
26-
set => SetProperty(ref _preAction, value);
25+
get => _repo.Settings.DealWithLocalChangesOnCreateBranch;
26+
set => _repo.Settings.DealWithLocalChangesOnCreateBranch = value;
2727
}
2828

2929
public bool CheckoutAfterCreated
3030
{
31-
get;
32-
set;
33-
} = true;
31+
get => _repo.Settings.CheckoutBranchOnCreateBranch;
32+
set => _repo.Settings.CheckoutBranchOnCreateBranch = value;
33+
}
3434

3535
public CreateBranch(Repository repo, Models.Branch branch)
3636
{
@@ -89,7 +89,7 @@ public override Task<bool> Sure()
8989
bool needPopStash = false;
9090
if (_repo.WorkingCopyChangesCount > 0)
9191
{
92-
if (_preAction == Models.DealWithLocalChanges.StashAndReaply)
92+
if (PreAction == Models.DealWithLocalChanges.StashAndReaply)
9393
{
9494
SetProgressDescription("Adding untracked changes...");
9595
var succ = new Commands.Add(_repo.FullPath).Exec();
@@ -107,7 +107,7 @@ public override Task<bool> Sure()
107107

108108
needPopStash = true;
109109
}
110-
else if (_preAction == Models.DealWithLocalChanges.Discard)
110+
else if (PreAction == Models.DealWithLocalChanges.Discard)
111111
{
112112
SetProgressDescription("Discard local changes...");
113113
Commands.Discard.All(_repo.FullPath);
@@ -137,6 +137,5 @@ public override Task<bool> Sure()
137137
private readonly Repository _repo = null;
138138
private string _name = null;
139139
private readonly string _baseOnRevision = null;
140-
private Models.DealWithLocalChanges _preAction = Models.DealWithLocalChanges.DoNothing;
141140
}
142141
}

src/ViewModels/Fetch.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public bool Prune
3030

3131
public bool NoTags
3232
{
33-
get;
34-
set;
35-
} = false;
33+
get => _repo.Settings.FetchWithoutTags;
34+
set => _repo.Settings.FetchWithoutTags = value;
35+
}
3636

3737
public Fetch(Repository repo, Models.Remote preferedRemote = null)
3838
{
@@ -45,6 +45,7 @@ public Fetch(Repository repo, Models.Remote preferedRemote = null)
4545
public override Task<bool> Sure()
4646
{
4747
_repo.SetWatcherEnabled(false);
48+
4849
return Task.Run(() =>
4950
{
5051
if (FetchAllRemotes)

src/ViewModels/Pull.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ public Models.Branch SelectedBranch
4949

5050
public Models.DealWithLocalChanges PreAction
5151
{
52-
get => _preAction;
53-
set => SetProperty(ref _preAction, value);
52+
get => _repo.Settings.DealWithLocalChangesOnPull;
53+
set => _repo.Settings.DealWithLocalChangesOnPull = value;
5454
}
5555

5656
public bool UseRebase
@@ -61,9 +61,9 @@ public bool UseRebase
6161

6262
public bool NoTags
6363
{
64-
get;
65-
set;
66-
} = false;
64+
get => _repo.Settings.FetchWithoutTagsOnPull;
65+
set => _repo.Settings.FetchWithoutTagsOnPull = value;
66+
}
6767

6868
public Pull(Repository repo, Models.Branch specifiedRemoteBranch)
6969
{
@@ -120,12 +120,13 @@ public Pull(Repository repo, Models.Branch specifiedRemoteBranch)
120120
public override Task<bool> Sure()
121121
{
122122
_repo.SetWatcherEnabled(false);
123+
123124
return Task.Run(() =>
124125
{
125126
var needPopStash = false;
126127
if (_repo.WorkingCopyChangesCount > 0)
127128
{
128-
if (_preAction == Models.DealWithLocalChanges.StashAndReaply)
129+
if (PreAction == Models.DealWithLocalChanges.StashAndReaply)
129130
{
130131
SetProgressDescription("Adding untracked changes...");
131132
var succ = new Commands.Add(_repo.FullPath).Exec();
@@ -143,7 +144,7 @@ public override Task<bool> Sure()
143144

144145
needPopStash = true;
145146
}
146-
else if (_preAction == Models.DealWithLocalChanges.Discard)
147+
else if (PreAction == Models.DealWithLocalChanges.Discard)
147148
{
148149
SetProgressDescription("Discard local changes ...");
149150
Commands.Discard.All(_repo.FullPath);
@@ -168,6 +169,5 @@ public override Task<bool> Sure()
168169
private Models.Remote _selectedRemote = null;
169170
private List<Models.Branch> _remoteBranches = null;
170171
private Models.Branch _selectedBranch = null;
171-
private Models.DealWithLocalChanges _preAction = Models.DealWithLocalChanges.DoNothing;
172172
}
173173
}

src/ViewModels/Push.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ public Models.Branch SelectedRemoteBranch
6464

6565
public bool PushAllTags
6666
{
67-
get;
68-
set;
67+
get => _repo.Settings.PushAllTags;
68+
set => _repo.Settings.PushAllTags = value;
6969
}
7070

7171
public bool IsSetTrackOptionVisible

src/ViewModels/Repository.cs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,56 @@
1414

1515
namespace SourceGit.ViewModels
1616
{
17-
public class RepositorySettings : ObservableObject
17+
public class RepositorySettings
1818
{
19+
public Models.DealWithLocalChanges DealWithLocalChangesOnCheckoutBranch
20+
{
21+
get;
22+
set;
23+
} = Models.DealWithLocalChanges.DoNothing;
24+
25+
public bool FetchWithoutTags
26+
{
27+
get;
28+
set;
29+
} = false;
30+
31+
public Models.DealWithLocalChanges DealWithLocalChangesOnPull
32+
{
33+
get;
34+
set;
35+
} = Models.DealWithLocalChanges.DoNothing;
36+
1937
public bool PreferRebaseInsteadOfMerge
2038
{
2139
get;
2240
set;
2341
} = true;
2442

43+
public bool FetchWithoutTagsOnPull
44+
{
45+
get;
46+
set;
47+
} = false;
48+
49+
public bool PushAllTags
50+
{
51+
get;
52+
set;
53+
} = false;
54+
55+
public Models.DealWithLocalChanges DealWithLocalChangesOnCreateBranch
56+
{
57+
get;
58+
set;
59+
} = Models.DealWithLocalChanges.DoNothing;
60+
61+
public bool CheckoutBranchOnCreateBranch
62+
{
63+
get;
64+
set;
65+
} = true;
66+
2567
public AvaloniaList<string> Filters
2668
{
2769
get;

0 commit comments

Comments
 (0)