From 566d36ca59bc4ee132b8e70210b7886f4f04c957 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 28 Oct 2024 16:51:42 +0800 Subject: [PATCH] feature: add option to enable `--keep-index` option of `git stash push` command (#610) Signed-off-by: leo --- src/Commands/Stash.cs | 8 +++++--- src/Resources/Locales/en_US.axaml | 1 + src/Resources/Locales/zh_CN.axaml | 1 + src/Resources/Locales/zh_TW.axaml | 1 + src/ViewModels/StashChanges.cs | 9 ++++++++- src/Views/StashChanges.axaml | 7 ++++++- 6 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/Commands/Stash.cs b/src/Commands/Stash.cs index fbdb6bd4..8554adde 100644 --- a/src/Commands/Stash.cs +++ b/src/Commands/Stash.cs @@ -17,17 +17,19 @@ namespace SourceGit.Commands return Exec(); } - public bool Push(List changes, string message, bool onlyStaged) + public bool Push(List changes, string message, bool onlyStaged, bool keepIndex) { var pathsBuilder = new StringBuilder(); + var indexOpts = keepIndex ? "--keep-index" : ""; + if (onlyStaged) { foreach (var c in changes) pathsBuilder.Append($"\"{c.Path}\" "); var paths = pathsBuilder.ToString(); - Args = $"stash push --staged -m \"{message}\" -- {paths}"; + Args = $"stash push {indexOpts} --staged -m \"{message}\" -- {paths}"; } else { @@ -53,7 +55,7 @@ namespace SourceGit.Commands } var paths = pathsBuilder.ToString(); - Args = $"stash push -m \"{message}\" -- {paths}"; + Args = $"stash push {indexOpts} -m \"{message}\" -- {paths}"; } return Exec(); diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 46b5d4b9..847bbd1b 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -573,6 +573,7 @@ START Stash Include untracked files + Keep staged files Message: Optional. Name of this stash Only staged changes diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 941ec686..a9b25073 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -576,6 +576,7 @@ 开 始 贮藏(stash) 包含未跟踪的文件 + 保留暂存区文件 信息 : 选填,用于命名此贮藏 仅贮藏暂存区的变更 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index 562cd818..2ea43167 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -576,6 +576,7 @@ 開 始 擱置變更 (stash) 包含未追蹤的檔案 + 保留已暫存的變更 擱置變更訊息: 選填,用於命名此擱置變更 僅擱置已暫存的變更 diff --git a/src/ViewModels/StashChanges.cs b/src/ViewModels/StashChanges.cs index ed3d2bfd..82516880 100644 --- a/src/ViewModels/StashChanges.cs +++ b/src/ViewModels/StashChanges.cs @@ -28,6 +28,12 @@ namespace SourceGit.ViewModels set; } + public bool KeepIndex + { + get; + set; + } + public StashChanges(Repository repo, List changes, bool hasSelectedFiles) { _repo = repo; @@ -36,6 +42,7 @@ namespace SourceGit.ViewModels HasSelectedFiles = hasSelectedFiles; IncludeUntracked = true; OnlyStaged = false; + KeepIndex = false; View = new Views.StashChanges() { DataContext = this }; } @@ -63,7 +70,7 @@ namespace SourceGit.ViewModels return Task.Run(() => { - var succ = new Commands.Stash(_repo.FullPath).Push(jobs, Message, !HasSelectedFiles && OnlyStaged); + var succ = new Commands.Stash(_repo.FullPath).Push(jobs, Message, !HasSelectedFiles && OnlyStaged, KeepIndex); CallUIThread(() => { _repo.MarkWorkingCopyDirtyManually(); diff --git a/src/Views/StashChanges.axaml b/src/Views/StashChanges.axaml index 5396da4d..edbe59f0 100644 --- a/src/Views/StashChanges.axaml +++ b/src/Views/StashChanges.axaml @@ -11,7 +11,7 @@ - + + +