diff --git a/src/Models/DealWithChangesAfterStashing.cs b/src/Models/DealWithChangesAfterStashing.cs new file mode 100644 index 00000000..63889c96 --- /dev/null +++ b/src/Models/DealWithChangesAfterStashing.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; + +namespace SourceGit.Models +{ + public class DealWithChangesAfterStashing + { + public string Label { get; set; } + public string Desc { get; set; } + + public static readonly List Supported = [ + new ("Discard", "All (or selected) changes will be discarded"), + new ("Keep Index", "Staged changes are left intact"), + new ("Keep All", "All (or selected) changes are left intact"), + ]; + + public DealWithChangesAfterStashing(string label, string desc) + { + Label = label; + Desc = desc; + } + } +} diff --git a/src/Models/RepositorySettings.cs b/src/Models/RepositorySettings.cs index a54956d3..4e51b368 100644 --- a/src/Models/RepositorySettings.cs +++ b/src/Models/RepositorySettings.cs @@ -176,17 +176,11 @@ namespace SourceGit.Models set; } = false; - public bool KeepIndexWhenStash + public int ChangesAfterStashing { get; set; - } = false; - - public bool AutoRestoreAfterStash - { - get; - set; - } = false; + } = 0; public string PreferredOpenAIService { diff --git a/src/Resources/Locales/de_DE.axaml b/src/Resources/Locales/de_DE.axaml index 032e5ce7..fc596da5 100644 --- a/src/Resources/Locales/de_DE.axaml +++ b/src/Resources/Locales/de_DE.axaml @@ -669,10 +669,7 @@ Pfad zum privaten SSH Schlüssel START Stash - Automatisch wiederherstellen nach dem Stashen - Die Arbeitsdateien bleiben unverändert, aber ein Stash wird gespeichert. Inklusive nicht-verfolgter Dateien - Behalte gestagte Dateien Name: Optional. Name dieses Stashes Nur gestagte Änderungen diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index f0ad4b18..8c5d1118 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -689,10 +689,8 @@ Private SSH key store path START Stash - Auto-restore after stashing - Your working files remain unchanged, but a stash is saved. + Selected Changes: Include untracked files - Keep staged files Message: Optional. Name of this stash Only staged changes diff --git a/src/Resources/Locales/es_ES.axaml b/src/Resources/Locales/es_ES.axaml index 4f1a4452..616799a4 100644 --- a/src/Resources/Locales/es_ES.axaml +++ b/src/Resources/Locales/es_ES.axaml @@ -692,10 +692,7 @@ Ruta de almacenamiento de la clave privada SSH INICIAR Stash - Restaurar automáticamente después del stashing - Tus archivos de trabajo permanecen sin cambios, pero se guarda un stash. Incluir archivos no rastreados - Mantener archivos staged Mensaje: Opcional. Nombre de este stash Solo cambios staged diff --git a/src/Resources/Locales/fr_FR.axaml b/src/Resources/Locales/fr_FR.axaml index 635d74c2..f3ff7f25 100644 --- a/src/Resources/Locales/fr_FR.axaml +++ b/src/Resources/Locales/fr_FR.axaml @@ -645,10 +645,7 @@ Chemin du magasin de clés privées SSH START Stash - Auto-restauration après le stash - Vos fichiers de travail restent inchangés, mais une sauvegarde est enregistrée. Inclure les fichiers non-suivis - Garder les fichiers indexés Message : Optionnel. Nom de ce stash Seulement les changements indexés diff --git a/src/Resources/Locales/it_IT.axaml b/src/Resources/Locales/it_IT.axaml index 3aef0043..ea9c2c3f 100644 --- a/src/Resources/Locales/it_IT.axaml +++ b/src/Resources/Locales/it_IT.axaml @@ -673,10 +673,7 @@ Percorso per la chiave SSH privata AVVIA Stasha - Auto-ripristino dopo lo stash - I tuoi file di lavoro rimangono inalterati, ma viene salvato uno stash. Includi file non tracciati - Mantieni file in stage Messaggio: Opzionale. Nome di questo stash Solo modifiche in stage diff --git a/src/Resources/Locales/ja_JP.axaml b/src/Resources/Locales/ja_JP.axaml index 918a6b4d..635e5a1d 100644 --- a/src/Resources/Locales/ja_JP.axaml +++ b/src/Resources/Locales/ja_JP.axaml @@ -643,10 +643,7 @@ プライベートSSHキーストアのパス スタート スタッシュ - スタッシュ後に自動で復元 - 作業ファイルは変更されず、スタッシュが保存されます。 追跡されていないファイルを含める - ステージされたファイルを保持 メッセージ: オプション. このスタッシュの名前を入力 ステージされた変更のみ diff --git a/src/Resources/Locales/pt_BR.axaml b/src/Resources/Locales/pt_BR.axaml index f448a908..4e65a2b8 100644 --- a/src/Resources/Locales/pt_BR.axaml +++ b/src/Resources/Locales/pt_BR.axaml @@ -585,7 +585,6 @@ INICIAR Stash Incluir arquivos não rastreados - Manter arquivos em stage Mensagem: Opcional. Nome deste stash Apenas mudanças em stage diff --git a/src/Resources/Locales/ru_RU.axaml b/src/Resources/Locales/ru_RU.axaml index a625df98..b1656631 100644 --- a/src/Resources/Locales/ru_RU.axaml +++ b/src/Resources/Locales/ru_RU.axaml @@ -690,10 +690,7 @@ Путь хранения приватного ключа SSH ЗАПУСК Отложить - Автоматически восстанавливать после откладывания - Ваши рабочие файлы остаются неизменными, но отложенные сохранятся. Включить неотслеживаемые файлы - Хранить отложенные файлы Сообщение: Имя тайника (необязательно) Только сформированные изменения diff --git a/src/Resources/Locales/ta_IN.axaml b/src/Resources/Locales/ta_IN.axaml index abe53252..18f86d78 100644 --- a/src/Resources/Locales/ta_IN.axaml +++ b/src/Resources/Locales/ta_IN.axaml @@ -644,10 +644,7 @@ தனியார் பாஓடு திறவுகோல் கடை பாதை தொடங்கு பதுக்கிவை - பதுக்கிவைத்த பிறகு தானியங்கி மீட்டமை - உங்கள் செயல்படும் கோப்புகள் மாறாமல் இருக்கும், ஆனால் ஒரு பதுக்கிவைக்கப்படும். கண்காணிக்கப்படாத கோப்புகளைச் சேர் - நிலைப்படுத்தப்பட்ட கோப்புகளை வைத்திரு செய்தி: விருப்பத்தேர்வு. இந்த பதுக்கலின் பெயர் நிலைப்படுத்தப்பட்ட மாற்றங்கள் மட்டும் diff --git a/src/Resources/Locales/uk_UA.axaml b/src/Resources/Locales/uk_UA.axaml index 096b4398..169e8d68 100644 --- a/src/Resources/Locales/uk_UA.axaml +++ b/src/Resources/Locales/uk_UA.axaml @@ -649,10 +649,7 @@ Шлях до сховища приватного ключа SSH ПОЧАТИ Stash (Сховати) - Автоматично відновити після схову - Ваші робочі файли залишаться без змін, але буде збережено схованку. Включити невідстежувані файли - Зберегти проіндексовані файли Повідомлення: Необов'язково. Назва цієї схованки Лише проіндексовані зміни diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index f8fa8d90..ef984806 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -693,10 +693,8 @@ SSH密钥文件 开 始 贮藏(stash) - 贮藏后自动恢复工作区 - 工作区文件保持未修改状态,但贮藏内容已保存。 + 已选择变更 : 包含未跟踪的文件 - 保留暂存区文件 信息 : 选填,用于命名此贮藏 仅贮藏暂存区的变更 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index a76f4f3a..52ee5648 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -693,10 +693,8 @@ SSH 金鑰檔案 開 始 擱置變更 (stash) - 擱置變更後自動復原工作區 - 工作區檔案保持未修改,但擱置內容已儲存。 + 選定變更: 包含未追蹤的檔案 - 保留已暫存的變更 擱置變更訊息: 選填,用於命名此擱置變更 僅擱置已暫存的變更 diff --git a/src/ViewModels/StashChanges.cs b/src/ViewModels/StashChanges.cs index 11e449fb..639a0a7b 100644 --- a/src/ViewModels/StashChanges.cs +++ b/src/ViewModels/StashChanges.cs @@ -27,19 +27,20 @@ namespace SourceGit.ViewModels public bool OnlyStaged { get => _repo.Settings.OnlyStagedWhenStash; - set => _repo.Settings.OnlyStagedWhenStash = value; + set + { + if (_repo.Settings.OnlyStagedWhenStash != value) + { + _repo.Settings.OnlyStagedWhenStash = value; + OnPropertyChanged(); + } + } } - public bool KeepIndex + public int ChangesAfterStashing { - get => _repo.Settings.KeepIndexWhenStash; - set => _repo.Settings.KeepIndexWhenStash = value; - } - - public bool AutoRestore - { - get => _repo.Settings.AutoRestoreAfterStash; - set => _repo.Settings.AutoRestoreAfterStash = value; + get => _repo.Settings.ChangesAfterStashing; + set => _repo.Settings.ChangesAfterStashing = value; } public StashChanges(Repository repo, List changes, bool hasSelectedFiles) @@ -59,6 +60,8 @@ namespace SourceGit.ViewModels return Task.Run(() => { + var mode = (DealWithChangesAfterStashing)ChangesAfterStashing; + var keepIndex = mode == DealWithChangesAfterStashing.KeepIndex; var succ = false; if (!HasSelectedFiles) @@ -67,7 +70,7 @@ namespace SourceGit.ViewModels { if (Native.OS.GitVersion >= Models.GitVersions.STASH_PUSH_ONLY_STAGED) { - succ = new Commands.Stash(_repo.FullPath).Use(log).PushOnlyStaged(Message, KeepIndex); + succ = new Commands.Stash(_repo.FullPath).Use(log).PushOnlyStaged(Message, keepIndex); } else { @@ -78,20 +81,20 @@ namespace SourceGit.ViewModels staged.Add(c); } - succ = StashWithChanges(staged, log); + succ = StashWithChanges(staged, keepIndex, log); } } else { - succ = new Commands.Stash(_repo.FullPath).Use(log).Push(Message, IncludeUntracked, KeepIndex); + succ = new Commands.Stash(_repo.FullPath).Use(log).Push(Message, IncludeUntracked, keepIndex); } } else { - succ = StashWithChanges(_changes, log); + succ = StashWithChanges(_changes, keepIndex, log); } - if (AutoRestore && succ) + if (mode == DealWithChangesAfterStashing.KeepAll && succ) succ = new Commands.Stash(_repo.FullPath).Use(log).Apply("stash@{0}", true); log.Complete(); @@ -105,7 +108,7 @@ namespace SourceGit.ViewModels }); } - private bool StashWithChanges(List changes, CommandLog log) + private bool StashWithChanges(List changes, bool keepIndex, CommandLog log) { if (changes.Count == 0) return true; @@ -119,7 +122,7 @@ namespace SourceGit.ViewModels var pathSpecFile = Path.GetTempFileName(); File.WriteAllLines(pathSpecFile, paths); - succ = new Commands.Stash(_repo.FullPath).Use(log).Push(Message, pathSpecFile, KeepIndex); + succ = new Commands.Stash(_repo.FullPath).Use(log).Push(Message, pathSpecFile, keepIndex); File.Delete(pathSpecFile); } else @@ -128,7 +131,7 @@ namespace SourceGit.ViewModels { var count = Math.Min(32, changes.Count - i); var step = changes.GetRange(i, count); - succ = new Commands.Stash(_repo.FullPath).Use(log).Push(Message, step, KeepIndex); + succ = new Commands.Stash(_repo.FullPath).Use(log).Push(Message, step, keepIndex); if (!succ) break; } @@ -137,6 +140,13 @@ namespace SourceGit.ViewModels return succ; } + private enum DealWithChangesAfterStashing + { + Discard = 0, + KeepIndex, + KeepAll, + } + private readonly Repository _repo = null; private readonly List _changes = null; } diff --git a/src/Views/StashChanges.axaml b/src/Views/StashChanges.axaml index 51ed87ac..148fc489 100644 --- a/src/Views/StashChanges.axaml +++ b/src/Views/StashChanges.axaml @@ -2,6 +2,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:m="using:SourceGit.Models" xmlns:vm="using:SourceGit.ViewModels" xmlns:v="using:SourceGit.Views" mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="450" @@ -11,7 +12,7 @@ - + - + + + + + + + + + + + + + + + + + Content="{DynamicResource Text.Stash.IncludeUntracked}" + IsChecked="{Binding IncludeUntracked, Mode=TwoWay}" + ToolTip.Tip="--include-untracked"> + + + + + + + - - -