Skip to content

Commit 68519c7

Browse files
committed
refactor: stash local changes (sourcegit-scm#550)
* when try to stash all the local changes, add a option to only stash the staged changes * stash changes in selected files will prompt user - both staged and unstaged changes of selected file(s) will be stashed
1 parent ac74e4b commit 68519c7

File tree

6 files changed

+41
-17
lines changed

6 files changed

+41
-17
lines changed

src/Resources/Locales/en_US.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,8 @@
562562
<x:String x:Key="Text.Stash.IncludeUntracked" xml:space="preserve">Include untracked files</x:String>
563563
<x:String x:Key="Text.Stash.Message" xml:space="preserve">Message:</x:String>
564564
<x:String x:Key="Text.Stash.Message.Placeholder" xml:space="preserve">Optional. Name of this stash</x:String>
565+
<x:String x:Key="Text.Stash.OnlyStagedChanges" xml:space="preserve">Only staged changes</x:String>
566+
<x:String x:Key="Text.Stash.TipForSelectedFiles" xml:space="preserve">Both staged and unstaged changes of selected file(s) will be stashed!!!</x:String>
565567
<x:String x:Key="Text.Stash.Title" xml:space="preserve">Stash Local Changes</x:String>
566568
<x:String x:Key="Text.StashCM.Apply" xml:space="preserve">Apply</x:String>
567569
<x:String x:Key="Text.StashCM.Drop" xml:space="preserve">Drop</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,8 @@
560560
<x:String x:Key="Text.Stash.IncludeUntracked" xml:space="preserve">包含未跟踪的文件</x:String>
561561
<x:String x:Key="Text.Stash.Message" xml:space="preserve">信息 :</x:String>
562562
<x:String x:Key="Text.Stash.Message.Placeholder" xml:space="preserve">选填,用于命名此贮藏</x:String>
563+
<x:String x:Key="Text.Stash.OnlyStagedChanges" xml:space="preserve">仅贮藏暂存区的变更</x:String>
564+
<x:String x:Key="Text.Stash.TipForSelectedFiles" xml:space="preserve">选中文件的所有变更均会被贮藏!</x:String>
563565
<x:String x:Key="Text.Stash.Title" xml:space="preserve">贮藏本地变更</x:String>
564566
<x:String x:Key="Text.StashCM.Apply" xml:space="preserve">应用(apply)</x:String>
565567
<x:String x:Key="Text.StashCM.Drop" xml:space="preserve">删除(drop)</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,8 @@
565565
<x:String x:Key="Text.Stash.IncludeUntracked" xml:space="preserve">包含未追蹤的檔案</x:String>
566566
<x:String x:Key="Text.Stash.Message" xml:space="preserve">擱置變更訊息:</x:String>
567567
<x:String x:Key="Text.Stash.Message.Placeholder" xml:space="preserve">選填,用於命名此擱置變更</x:String>
568+
<x:String x:Key="Text.Stash.OnlyStagedChanges" xml:space="preserve">僅擱置已暫存的變更</x:String>
569+
<x:String x:Key="Text.Stash.TipForSelectedFiles" xml:space="preserve">選中檔案的所有變更均會被擱置!</x:String>
568570
<x:String x:Key="Text.Stash.Title" xml:space="preserve">擱置本機變更</x:String>
569571
<x:String x:Key="Text.StashCM.Apply" xml:space="preserve">套用 (apply)</x:String>
570572
<x:String x:Key="Text.StashCM.Drop" xml:space="preserve">刪除 (drop)</x:String>

src/ViewModels/StashChanges.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public string Message
1111
set;
1212
}
1313

14-
public bool CanIgnoreUntracked
14+
public bool HasSelectedFiles
1515
{
1616
get;
1717
}
@@ -22,21 +22,28 @@ public bool IncludeUntracked
2222
set;
2323
}
2424

25-
public StashChanges(Repository repo, List<Models.Change> changes, bool onlyStaged, bool canIgnoreUntracked)
25+
public bool OnlyStaged
26+
{
27+
get;
28+
set;
29+
}
30+
31+
public StashChanges(Repository repo, List<Models.Change> changes, bool hasSelectedFiles)
2632
{
2733
_repo = repo;
2834
_changes = changes;
29-
_onlyStaged = onlyStaged;
3035

31-
CanIgnoreUntracked = canIgnoreUntracked;
36+
HasSelectedFiles = hasSelectedFiles;
3237
IncludeUntracked = true;
38+
OnlyStaged = false;
39+
3340
View = new Views.StashChanges() { DataContext = this };
3441
}
3542

3643
public override Task<bool> Sure()
3744
{
3845
var jobs = _changes;
39-
if (CanIgnoreUntracked && !IncludeUntracked)
46+
if (!HasSelectedFiles && !IncludeUntracked)
4047
{
4148
jobs = new List<Models.Change>();
4249
foreach (var job in _changes)
@@ -56,7 +63,7 @@ public override Task<bool> Sure()
5663

5764
return Task.Run(() =>
5865
{
59-
var succ = new Commands.Stash(_repo.FullPath).Push(jobs, Message, _onlyStaged);
66+
var succ = new Commands.Stash(_repo.FullPath).Push(jobs, Message, !HasSelectedFiles && OnlyStaged);
6067
CallUIThread(() =>
6168
{
6269
_repo.MarkWorkingCopyDirtyManually();
@@ -68,6 +75,5 @@ public override Task<bool> Sure()
6875

6976
private readonly Repository _repo = null;
7077
private readonly List<Models.Change> _changes = null;
71-
private readonly bool _onlyStaged = false;
7278
}
7379
}

src/ViewModels/WorkingCopy.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,9 @@ public void StashAll(bool autoStart)
318318
return;
319319

320320
if (autoStart)
321-
PopupHost.ShowAndStartPopup(new StashChanges(_repo, _cached, false, true));
321+
PopupHost.ShowAndStartPopup(new StashChanges(_repo, _cached, false));
322322
else
323-
PopupHost.ShowPopup(new StashChanges(_repo, _cached, false, true));
323+
PopupHost.ShowPopup(new StashChanges(_repo, _cached, false));
324324
}
325325

326326
public void StageSelected(Models.Change next)
@@ -523,9 +523,8 @@ public ContextMenu CreateContextMenuForUnstagedChanges()
523523
stash.Click += (_, e) =>
524524
{
525525
if (PopupHost.CanCreatePopup())
526-
{
527-
PopupHost.ShowPopup(new StashChanges(_repo, _selectedUnstaged, false, false));
528-
}
526+
PopupHost.ShowPopup(new StashChanges(_repo, _selectedUnstaged, true));
527+
529528
e.Handled = true;
530529
};
531530

@@ -843,7 +842,7 @@ public ContextMenu CreateContextMenuForUnstagedChanges()
843842
stash.Click += (_, e) =>
844843
{
845844
if (PopupHost.CanCreatePopup())
846-
PopupHost.ShowPopup(new StashChanges(_repo, _selectedUnstaged, false, false));
845+
PopupHost.ShowPopup(new StashChanges(_repo, _selectedUnstaged, true));
847846

848847
e.Handled = true;
849848
};
@@ -928,7 +927,7 @@ public ContextMenu CreateContextMenuForStagedChanges()
928927
stash.Click += (_, e) =>
929928
{
930929
if (PopupHost.CanCreatePopup())
931-
PopupHost.ShowPopup(new StashChanges(_repo, _selectedStaged, true, false));
930+
PopupHost.ShowPopup(new StashChanges(_repo, _selectedStaged, true));
932931

933932
e.Handled = true;
934933
};
@@ -1097,7 +1096,7 @@ public ContextMenu CreateContextMenuForStagedChanges()
10971096
stash.Click += (_, e) =>
10981097
{
10991098
if (PopupHost.CanCreatePopup())
1100-
PopupHost.ShowPopup(new StashChanges(_repo, _selectedStaged, true, false));
1099+
PopupHost.ShowPopup(new StashChanges(_repo, _selectedStaged, true));
11011100

11021101
e.Handled = true;
11031102
};

src/Views/StashChanges.axaml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<TextBlock FontSize="18"
1212
Classes="bold"
1313
Text="{DynamicResource Text.Stash.Title}"/>
14-
<Grid Margin="8,16,0,0" RowDefinitions="32,Auto" ColumnDefinitions="120,*">
14+
<Grid Margin="8,16,0,0" RowDefinitions="32,Auto,Auto" ColumnDefinitions="120,*">
1515
<TextBlock Grid.Row="0" Grid.Column="0"
1616
HorizontalAlignment="Right"
1717
Margin="8,0"
@@ -23,11 +23,24 @@
2323
Watermark="{DynamicResource Text.Stash.Message.Placeholder}"
2424
v:AutoFocusBehaviour.IsEnabled="True"/>
2525

26+
<TextBlock Grid.Row="1" Grid.Column="1"
27+
Margin="0,4,0,0"
28+
Text="{DynamicResource Text.Stash.TipForSelectedFiles}"
29+
TextWrapping="Wrap"
30+
Foreground="{DynamicResource Brush.FG2}"
31+
IsVisible="{Binding HasSelectedFiles}"/>
32+
2633
<CheckBox Grid.Row="1" Grid.Column="1"
2734
Height="32"
2835
Content="{DynamicResource Text.Stash.IncludeUntracked}"
2936
IsChecked="{Binding IncludeUntracked, Mode=TwoWay}"
30-
IsVisible="{Binding CanIgnoreUntracked}"/>
37+
IsVisible="{Binding !HasSelectedFiles}"/>
38+
39+
<CheckBox Grid.Row="2" Grid.Column="1"
40+
Height="32"
41+
Content="{DynamicResource Text.Stash.OnlyStagedChanges}"
42+
IsChecked="{Binding OnlyStaged, Mode=TwoWay}"
43+
IsVisible="{Binding !HasSelectedFiles}"/>
3144
</Grid>
3245
</StackPanel>
3346
</UserControl>

0 commit comments

Comments
 (0)