Skip to content

Commit 566d36c

Browse files
committed
feature: add option to enable --keep-index option of git stash push command (#610)
Signed-off-by: leo <[email protected]>
1 parent 3e6e0be commit 566d36c

File tree

6 files changed

+22
-5
lines changed

6 files changed

+22
-5
lines changed

src/Commands/Stash.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,19 @@ public bool Push(string message)
1717
return Exec();
1818
}
1919

20-
public bool Push(List<Models.Change> changes, string message, bool onlyStaged)
20+
public bool Push(List<Models.Change> changes, string message, bool onlyStaged, bool keepIndex)
2121
{
2222
var pathsBuilder = new StringBuilder();
2323

24+
var indexOpts = keepIndex ? "--keep-index" : "";
25+
2426
if (onlyStaged)
2527
{
2628
foreach (var c in changes)
2729
pathsBuilder.Append($"\"{c.Path}\" ");
2830

2931
var paths = pathsBuilder.ToString();
30-
Args = $"stash push --staged -m \"{message}\" -- {paths}";
32+
Args = $"stash push {indexOpts} --staged -m \"{message}\" -- {paths}";
3133
}
3234
else
3335
{
@@ -53,7 +55,7 @@ public bool Push(List<Models.Change> changes, string message, bool onlyStaged)
5355
}
5456

5557
var paths = pathsBuilder.ToString();
56-
Args = $"stash push -m \"{message}\" -- {paths}";
58+
Args = $"stash push {indexOpts} -m \"{message}\" -- {paths}";
5759
}
5860

5961
return Exec();

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@
573573
<x:String x:Key="Text.Start" xml:space="preserve">START</x:String>
574574
<x:String x:Key="Text.Stash" xml:space="preserve">Stash</x:String>
575575
<x:String x:Key="Text.Stash.IncludeUntracked" xml:space="preserve">Include untracked files</x:String>
576+
<x:String x:Key="Text.Stash.KeepIndex" xml:space="preserve">Keep staged files</x:String>
576577
<x:String x:Key="Text.Stash.Message" xml:space="preserve">Message:</x:String>
577578
<x:String x:Key="Text.Stash.Message.Placeholder" xml:space="preserve">Optional. Name of this stash</x:String>
578579
<x:String x:Key="Text.Stash.OnlyStagedChanges" xml:space="preserve">Only staged changes</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@
576576
<x:String x:Key="Text.Start" xml:space="preserve">开 始</x:String>
577577
<x:String x:Key="Text.Stash" xml:space="preserve">贮藏(stash)</x:String>
578578
<x:String x:Key="Text.Stash.IncludeUntracked" xml:space="preserve">包含未跟踪的文件</x:String>
579+
<x:String x:Key="Text.Stash.KeepIndex" xml:space="preserve">保留暂存区文件</x:String>
579580
<x:String x:Key="Text.Stash.Message" xml:space="preserve">信息 :</x:String>
580581
<x:String x:Key="Text.Stash.Message.Placeholder" xml:space="preserve">选填,用于命名此贮藏</x:String>
581582
<x:String x:Key="Text.Stash.OnlyStagedChanges" xml:space="preserve">仅贮藏暂存区的变更</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@
576576
<x:String x:Key="Text.Start" xml:space="preserve">開 始</x:String>
577577
<x:String x:Key="Text.Stash" xml:space="preserve">擱置變更 (stash)</x:String>
578578
<x:String x:Key="Text.Stash.IncludeUntracked" xml:space="preserve">包含未追蹤的檔案</x:String>
579+
<x:String x:Key="Text.Stash.KeepIndex" xml:space="preserve">保留已暫存的變更</x:String>
579580
<x:String x:Key="Text.Stash.Message" xml:space="preserve">擱置變更訊息:</x:String>
580581
<x:String x:Key="Text.Stash.Message.Placeholder" xml:space="preserve">選填,用於命名此擱置變更</x:String>
581582
<x:String x:Key="Text.Stash.OnlyStagedChanges" xml:space="preserve">僅擱置已暫存的變更</x:String>

src/ViewModels/StashChanges.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ public bool OnlyStaged
2828
set;
2929
}
3030

31+
public bool KeepIndex
32+
{
33+
get;
34+
set;
35+
}
36+
3137
public StashChanges(Repository repo, List<Models.Change> changes, bool hasSelectedFiles)
3238
{
3339
_repo = repo;
@@ -36,6 +42,7 @@ public StashChanges(Repository repo, List<Models.Change> changes, bool hasSelect
3642
HasSelectedFiles = hasSelectedFiles;
3743
IncludeUntracked = true;
3844
OnlyStaged = false;
45+
KeepIndex = false;
3946

4047
View = new Views.StashChanges() { DataContext = this };
4148
}
@@ -63,7 +70,7 @@ public override Task<bool> Sure()
6370

6471
return Task.Run(() =>
6572
{
66-
var succ = new Commands.Stash(_repo.FullPath).Push(jobs, Message, !HasSelectedFiles && OnlyStaged);
73+
var succ = new Commands.Stash(_repo.FullPath).Push(jobs, Message, !HasSelectedFiles && OnlyStaged, KeepIndex);
6774
CallUIThread(() =>
6875
{
6976
_repo.MarkWorkingCopyDirtyManually();

src/Views/StashChanges.axaml

Lines changed: 6 additions & 1 deletion
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,Auto" ColumnDefinitions="120,*">
14+
<Grid Margin="8,16,0,0" RowDefinitions="32,Auto,Auto,32" ColumnDefinitions="120,*">
1515
<TextBlock Grid.Row="0" Grid.Column="0"
1616
HorizontalAlignment="Right"
1717
Margin="8,0"
@@ -41,6 +41,11 @@
4141
Content="{DynamicResource Text.Stash.OnlyStagedChanges}"
4242
IsChecked="{Binding OnlyStaged, Mode=TwoWay}"
4343
IsVisible="{Binding !HasSelectedFiles}"/>
44+
45+
<CheckBox Grid.Row="3" Grid.Column="1"
46+
Height="32"
47+
Content="{DynamicResource Text.Stash.KeepIndex}"
48+
IsChecked="{Binding KeepIndex, Mode=TwoWay}"/>
4449
</Grid>
4550
</StackPanel>
4651
</UserControl>

0 commit comments

Comments
 (0)