feature: add Do Nothing option back to all git checkout command (#2204)

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo
2026-03-23 12:17:24 +08:00
parent d357bc4286
commit 0b15451916
27 changed files with 304 additions and 104 deletions

View File

@@ -0,0 +1,9 @@
namespace SourceGit.Models
{
public enum DealWithLocalChanges
{
DoNothing = 0,
StashAndReapply,
Discard,
}
}

View File

@@ -318,6 +318,9 @@ $1, $2, … Werte der Eingabe-Steuerelemente</x:String>
<x:String x:Key="Text.CreateTag.Type.Lightweight" xml:space="preserve">Ohne Anmerkung</x:String>
<x:String x:Key="Text.CtrlClickTip" xml:space="preserve">Halte Strg gedrückt, um direkt auszuführen</x:String>
<x:String x:Key="Text.Cut" xml:space="preserve">Ausschneiden</x:String>
<x:String x:Key="Text.DealWithLocalChanges.Discard" xml:space="preserve">Verwerfen</x:String>
<x:String x:Key="Text.DealWithLocalChanges.DoNothing" xml:space="preserve">Nichts tun</x:String>
<x:String x:Key="Text.DealWithLocalChanges.StashAndReapply" xml:space="preserve">Stashen &amp; wieder anwenden</x:String>
<x:String x:Key="Text.DeinitSubmodule" xml:space="preserve">Deinitialisiere Submodul</x:String>
<x:String x:Key="Text.DeinitSubmodule.Force" xml:space="preserve">Erzwinge Deinitialisierung, selbst wenn lokale Änderungen enthalten sind.</x:String>
<x:String x:Key="Text.DeinitSubmodule.Path" xml:space="preserve">Submodul:</x:String>

View File

@@ -110,8 +110,6 @@
<x:String x:Key="Text.Checkout.Commit.Target" xml:space="preserve">Commit:</x:String>
<x:String x:Key="Text.Checkout.Commit.Warning" xml:space="preserve">Warning: By doing a commit checkout, your Head will be detached</x:String>
<x:String x:Key="Text.Checkout.LocalChanges" xml:space="preserve">Local Changes:</x:String>
<x:String x:Key="Text.Checkout.LocalChanges.Discard" xml:space="preserve">Discard</x:String>
<x:String x:Key="Text.Checkout.LocalChanges.StashAndReapply" xml:space="preserve">Stash &amp; Reapply</x:String>
<x:String x:Key="Text.Checkout.Target" xml:space="preserve">Branch:</x:String>
<x:String x:Key="Text.Checkout.WarnLostCommits" xml:space="preserve">Your current HEAD contains commit(s) not connected to any branches/tags! Do you want to continue?</x:String>
<x:String x:Key="Text.Checkout.WarnUpdatingSubmodules" xml:space="preserve">The following submodules need to be updated:{0}Do you want to update them?</x:String>
@@ -301,8 +299,6 @@
<x:String x:Key="Text.CreateBranch.BasedOn" xml:space="preserve">Based On:</x:String>
<x:String x:Key="Text.CreateBranch.Checkout" xml:space="preserve">Check out the created branch</x:String>
<x:String x:Key="Text.CreateBranch.LocalChanges" xml:space="preserve">Local Changes:</x:String>
<x:String x:Key="Text.CreateBranch.LocalChanges.Discard" xml:space="preserve">Discard</x:String>
<x:String x:Key="Text.CreateBranch.LocalChanges.StashAndReapply" xml:space="preserve">Stash &amp; Reapply</x:String>
<x:String x:Key="Text.CreateBranch.Name" xml:space="preserve">New Branch Name:</x:String>
<x:String x:Key="Text.CreateBranch.Name.Placeholder" xml:space="preserve">Enter branch name.</x:String>
<x:String x:Key="Text.CreateBranch.Title" xml:space="preserve">Create Local Branch</x:String>
@@ -321,6 +317,9 @@
<x:String x:Key="Text.CreateTag.Type.Lightweight" xml:space="preserve">lightweight</x:String>
<x:String x:Key="Text.CtrlClickTip" xml:space="preserve">Hold Ctrl to start directly</x:String>
<x:String x:Key="Text.Cut" xml:space="preserve">Cut</x:String>
<x:String x:Key="Text.DealWithLocalChanges.Discard" xml:space="preserve">Discard</x:String>
<x:String x:Key="Text.DealWithLocalChanges.DoNothing" xml:space="preserve">Do Nothing</x:String>
<x:String x:Key="Text.DealWithLocalChanges.StashAndReapply" xml:space="preserve">Stash &amp; Reapply</x:String>
<x:String x:Key="Text.DeinitSubmodule" xml:space="preserve">De-initialize Submodule</x:String>
<x:String x:Key="Text.DeinitSubmodule.Force" xml:space="preserve">Force de-init even if it contains local changes.</x:String>
<x:String x:Key="Text.DeinitSubmodule.Path" xml:space="preserve">Submodule:</x:String>
@@ -689,8 +688,6 @@
<x:String x:Key="Text.Pull.Branch" xml:space="preserve">Remote Branch:</x:String>
<x:String x:Key="Text.Pull.Into" xml:space="preserve">Into:</x:String>
<x:String x:Key="Text.Pull.LocalChanges" xml:space="preserve">Local Changes:</x:String>
<x:String x:Key="Text.Pull.LocalChanges.Discard" xml:space="preserve">Discard</x:String>
<x:String x:Key="Text.Pull.LocalChanges.StashAndReapply" xml:space="preserve">Stash &amp; Reapply</x:String>
<x:String x:Key="Text.Pull.Remote" xml:space="preserve">Remote:</x:String>
<x:String x:Key="Text.Pull.Title" xml:space="preserve">Pull (Fetch &amp; Merge)</x:String>
<x:String x:Key="Text.Pull.UseRebase" xml:space="preserve">Use rebase instead of merge</x:String>

View File

@@ -324,6 +324,9 @@
<x:String x:Key="Text.CreateTag.Type.Lightweight" xml:space="preserve">ligera</x:String>
<x:String x:Key="Text.CtrlClickTip" xml:space="preserve">Mantenga Ctrl para iniciar directamente</x:String>
<x:String x:Key="Text.Cut" xml:space="preserve">Cortar</x:String>
<x:String x:Key="Text.DealWithLocalChanges.Discard" xml:space="preserve">Descartar</x:String>
<x:String x:Key="Text.DealWithLocalChanges.DoNothing" xml:space="preserve">No Hacer Nada</x:String>
<x:String x:Key="Text.DealWithLocalChanges.StashAndReapply" xml:space="preserve">Stash &amp; Reaplicar</x:String>
<x:String x:Key="Text.DeinitSubmodule" xml:space="preserve">Desinicializar Submódulo</x:String>
<x:String x:Key="Text.DeinitSubmodule.Force" xml:space="preserve">Forzar desinicialización incluso si contiene cambios locales.</x:String>
<x:String x:Key="Text.DeinitSubmodule.Path" xml:space="preserve">Submódulo:</x:String>

View File

@@ -305,6 +305,9 @@
<x:String x:Key="Text.CreateTag.Type.Lightweight" xml:space="preserve">léger</x:String>
<x:String x:Key="Text.CtrlClickTip" xml:space="preserve">Maintenir Ctrl pour commencer directement</x:String>
<x:String x:Key="Text.Cut" xml:space="preserve">Couper</x:String>
<x:String x:Key="Text.DealWithLocalChanges.Discard" xml:space="preserve">Annuler</x:String>
<x:String x:Key="Text.DealWithLocalChanges.DoNothing" xml:space="preserve">Ne rien faire</x:String>
<x:String x:Key="Text.DealWithLocalChanges.StashAndReapply" xml:space="preserve">Mettre en stash et réappliquer</x:String>
<x:String x:Key="Text.DeinitSubmodule" xml:space="preserve">Désinitialiser le sous-module</x:String>
<x:String x:Key="Text.DeinitSubmodule.Force" xml:space="preserve">Forcer la désinitialisation même s'il contient des modifications locales.</x:String>
<x:String x:Key="Text.DeinitSubmodule.Path" xml:space="preserve">Sous-module :</x:String>

View File

@@ -290,6 +290,8 @@
<x:String x:Key="Text.CreateTag.Type.Lightweight" xml:space="preserve">lightweight</x:String>
<x:String x:Key="Text.CtrlClickTip" xml:space="preserve">Tahan Ctrl untuk memulai langsung</x:String>
<x:String x:Key="Text.Cut" xml:space="preserve">Potong</x:String>
<x:String x:Key="Text.DealWithLocalChanges.Discard" xml:space="preserve">Buang</x:String>
<x:String x:Key="Text.DealWithLocalChanges.StashAndReapply" xml:space="preserve">Stash &amp; Terapkan Ulang</x:String>
<x:String x:Key="Text.DeinitSubmodule" xml:space="preserve">De-initialize Submodule</x:String>
<x:String x:Key="Text.DeinitSubmodule.Force" xml:space="preserve">Paksa de-init meski mengandung perubahan lokal.</x:String>
<x:String x:Key="Text.DeinitSubmodule.Path" xml:space="preserve">Submodule:</x:String>

View File

@@ -317,6 +317,9 @@ ${pure_files:N} Come ${files:N}, ma senza cartelle</x:String>
<x:String x:Key="Text.CreateTag.Type.Lightweight" xml:space="preserve">leggero</x:String>
<x:String x:Key="Text.CtrlClickTip" xml:space="preserve">Tieni premuto Ctrl per avviare direttamente</x:String>
<x:String x:Key="Text.Cut" xml:space="preserve">Taglia</x:String>
<x:String x:Key="Text.DealWithLocalChanges.Discard" xml:space="preserve">Scarta</x:String>
<x:String x:Key="Text.DealWithLocalChanges.DoNothing" xml:space="preserve">Non fare nulla</x:String>
<x:String x:Key="Text.DealWithLocalChanges.StashAndReapply" xml:space="preserve">Stash e Ripristina</x:String>
<x:String x:Key="Text.DeinitSubmodule" xml:space="preserve">Deinizializza Sottomodulo</x:String>
<x:String x:Key="Text.DeinitSubmodule.Force" xml:space="preserve">Forza deinizializzazione anche se contiene modifiche locali.</x:String>
<x:String x:Key="Text.DeinitSubmodule.Path" xml:space="preserve">Sottomodulo:</x:String>

View File

@@ -319,6 +319,8 @@
<x:String x:Key="Text.CreateTag.Type.Lightweight" xml:space="preserve">軽量</x:String>
<x:String x:Key="Text.CtrlClickTip" xml:space="preserve">Ctrl キーを押しながらで直接実行できます</x:String>
<x:String x:Key="Text.Cut" xml:space="preserve">切り取り</x:String>
<x:String x:Key="Text.DealWithLocalChanges.Discard" xml:space="preserve">破棄</x:String>
<x:String x:Key="Text.DealWithLocalChanges.StashAndReapply" xml:space="preserve">スタッシュして再適用</x:String>
<x:String x:Key="Text.DeinitSubmodule" xml:space="preserve">サブモジュールの初期化を解除</x:String>
<x:String x:Key="Text.DeinitSubmodule.Force" xml:space="preserve">ローカルの変更の有無に関わらず、強制的に解除</x:String>
<x:String x:Key="Text.DeinitSubmodule.Path" xml:space="preserve">サブモジュール:</x:String>

View File

@@ -289,6 +289,8 @@
<x:String x:Key="Text.CreateTag.Type.Lightweight" xml:space="preserve">경량 태그</x:String>
<x:String x:Key="Text.CtrlClickTip" xml:space="preserve">Ctrl을 누른 채 클릭하면 바로 시작합니다</x:String>
<x:String x:Key="Text.Cut" xml:space="preserve">잘라내기</x:String>
<x:String x:Key="Text.DealWithLocalChanges.Discard" xml:space="preserve">폐기</x:String>
<x:String x:Key="Text.DealWithLocalChanges.StashAndReapply" xml:space="preserve">스태시 &amp; 재적용</x:String>
<x:String x:Key="Text.DeinitSubmodule" xml:space="preserve">서브모듈 초기화 해제</x:String>
<x:String x:Key="Text.DeinitSubmodule.Force" xml:space="preserve">로컬 변경 사항이 있어도 강제로 초기화 해제합니다.</x:String>
<x:String x:Key="Text.DeinitSubmodule.Path" xml:space="preserve">서브모듈:</x:String>

View File

@@ -220,6 +220,9 @@
<x:String x:Key="Text.CreateTag.Type.Lightweight" xml:space="preserve">leve</x:String>
<x:String x:Key="Text.CtrlClickTip" xml:space="preserve">Pressione Ctrl para iniciar diretamente</x:String>
<x:String x:Key="Text.Cut" xml:space="preserve">Recortar</x:String>
<x:String x:Key="Text.DealWithLocalChanges.Discard" xml:space="preserve">Descartar</x:String>
<x:String x:Key="Text.DealWithLocalChanges.DoNothing" xml:space="preserve">Nada</x:String>
<x:String x:Key="Text.DealWithLocalChanges.StashAndReapply" xml:space="preserve">Stash &amp; Reaplicar</x:String>
<x:String x:Key="Text.DeleteBranch" xml:space="preserve">Excluir Branch</x:String>
<x:String x:Key="Text.DeleteBranch.Branch" xml:space="preserve">Branch:</x:String>
<x:String x:Key="Text.DeleteBranch.IsRemoteTip" xml:space="preserve">Você está prestes a excluir uma branch remota!!!</x:String>

View File

@@ -325,6 +325,9 @@
<x:String x:Key="Text.CreateTag.Type.Lightweight" xml:space="preserve">Простой</x:String>
<x:String x:Key="Text.CtrlClickTip" xml:space="preserve">Удерживайте Ctrl, чтобы сразу начать</x:String>
<x:String x:Key="Text.Cut" xml:space="preserve">Вырезать</x:String>
<x:String x:Key="Text.DealWithLocalChanges.Discard" xml:space="preserve">Отклонить</x:String>
<x:String x:Key="Text.DealWithLocalChanges.DoNothing" xml:space="preserve">Ничего не делать</x:String>
<x:String x:Key="Text.DealWithLocalChanges.StashAndReapply" xml:space="preserve">Отложить и примненить повторно</x:String>
<x:String x:Key="Text.DeinitSubmodule" xml:space="preserve">Удалить подмодуль</x:String>
<x:String x:Key="Text.DeinitSubmodule.Force" xml:space="preserve">Принудительно удалить даже если содержит локальные изменения.</x:String>
<x:String x:Key="Text.DeinitSubmodule.Path" xml:space="preserve">Подмодуль:</x:String>

View File

@@ -201,6 +201,8 @@
<x:String x:Key="Text.CreateTag.Type.Lightweight" xml:space="preserve">குறைந்தஎடை</x:String>
<x:String x:Key="Text.CtrlClickTip" xml:space="preserve">நேரடியாகத் தொடங்க கட்டுப்பாட்டை அழுத்திப் பிடி</x:String>
<x:String x:Key="Text.Cut" xml:space="preserve">வெட்டு</x:String>
<x:String x:Key="Text.DealWithLocalChanges.Discard" xml:space="preserve">நிராகரி</x:String>
<x:String x:Key="Text.DealWithLocalChanges.StashAndReapply" xml:space="preserve">பதுக்கிவை &amp; மீண்டும் இடு</x:String>
<x:String x:Key="Text.DeleteBranch" xml:space="preserve">கிளையை நீக்கு</x:String>
<x:String x:Key="Text.DeleteBranch.Branch" xml:space="preserve">கிளை:</x:String>
<x:String x:Key="Text.DeleteBranch.IsRemoteTip" xml:space="preserve">நீங்கள் ஒரு தொலை கிளையை நீக்கப் போகிறீர்கள்!!!</x:String>

View File

@@ -205,6 +205,8 @@
<x:String x:Key="Text.CreateTag.Type.Lightweight" xml:space="preserve">легкий</x:String>
<x:String x:Key="Text.CtrlClickTip" xml:space="preserve">Утримуйте Ctrl для запуску без діалогу</x:String>
<x:String x:Key="Text.Cut" xml:space="preserve">Вирізати</x:String>
<x:String x:Key="Text.DealWithLocalChanges.Discard" xml:space="preserve">Скасувати</x:String>
<x:String x:Key="Text.DealWithLocalChanges.StashAndReapply" xml:space="preserve">Сховати та Застосувати</x:String>
<x:String x:Key="Text.DeleteBranch" xml:space="preserve">Видалити гілку</x:String>
<x:String x:Key="Text.DeleteBranch.Branch" xml:space="preserve">Гілка:</x:String>
<x:String x:Key="Text.DeleteBranch.IsRemoteTip" xml:space="preserve">Ви збираєтеся видалити віддалену гілку!!!</x:String>

View File

@@ -325,6 +325,9 @@
<x:String x:Key="Text.CreateTag.Type.Lightweight" xml:space="preserve">轻量标签</x:String>
<x:String x:Key="Text.CtrlClickTip" xml:space="preserve">按住Ctrl键点击将以默认参数运行</x:String>
<x:String x:Key="Text.Cut" xml:space="preserve">剪切</x:String>
<x:String x:Key="Text.DealWithLocalChanges.Discard" xml:space="preserve">丢弃更改</x:String>
<x:String x:Key="Text.DealWithLocalChanges.DoNothing" xml:space="preserve">不做处理</x:String>
<x:String x:Key="Text.DealWithLocalChanges.StashAndReapply" xml:space="preserve">贮藏并自动恢复</x:String>
<x:String x:Key="Text.DeinitSubmodule" xml:space="preserve">取消初始化子模块</x:String>
<x:String x:Key="Text.DeinitSubmodule.Force" xml:space="preserve">强制取消,即使包含本地变更</x:String>
<x:String x:Key="Text.DeinitSubmodule.Path" xml:space="preserve">子模块 </x:String>

View File

@@ -325,6 +325,9 @@
<x:String x:Key="Text.CreateTag.Type.Lightweight" xml:space="preserve">輕量標籤</x:String>
<x:String x:Key="Text.CtrlClickTip" xml:space="preserve">按住 Ctrl 鍵將直接以預設參數執行</x:String>
<x:String x:Key="Text.Cut" xml:space="preserve">剪下</x:String>
<x:String x:Key="Text.DealWithLocalChanges.Discard" xml:space="preserve">捨棄變更</x:String>
<x:String x:Key="Text.DealWithLocalChanges.DoNothing" xml:space="preserve">不做處理</x:String>
<x:String x:Key="Text.DealWithLocalChanges.StashAndReapply" xml:space="preserve">擱置變更並自動復原</x:String>
<x:String x:Key="Text.DeinitSubmodule" xml:space="preserve">取消初始化子模組</x:String>
<x:String x:Key="Text.DeinitSubmodule.Force" xml:space="preserve">強制取消,即使包含本機變更</x:String>
<x:String x:Key="Text.DeinitSubmodule.Path" xml:space="preserve">子模組: </x:String>

View File

@@ -9,7 +9,7 @@ namespace SourceGit.ViewModels
get => _branch.Name;
}
public bool DiscardLocalChanges
public Models.DealWithLocalChanges DealWithLocalChanges
{
get;
set;
@@ -19,7 +19,7 @@ namespace SourceGit.ViewModels
{
_repo = repo;
_branch = branch;
DiscardLocalChanges = false;
DealWithLocalChanges = Models.DealWithLocalChanges.DoNothing;
}
public override async Task<bool> Sure()
@@ -46,7 +46,13 @@ namespace SourceGit.ViewModels
var succ = false;
var needPopStash = false;
if (!DiscardLocalChanges)
if (DealWithLocalChanges == Models.DealWithLocalChanges.DoNothing)
{
succ = await new Commands.Checkout(_repo.FullPath)
.Use(log)
.BranchAsync(branchName, false);
}
else if (DealWithLocalChanges == Models.DealWithLocalChanges.StashAndReapply)
{
var changes = await new Commands.CountLocalChanges(_repo.FullPath, false).GetResultAsync();
if (changes > 0)
@@ -57,16 +63,23 @@ namespace SourceGit.ViewModels
if (!succ)
{
log.Complete();
_repo.MarkWorkingCopyDirtyManually();
return false;
}
needPopStash = true;
}
}
succ = await new Commands.Checkout(_repo.FullPath)
.Use(log)
.BranchAsync(branchName, DiscardLocalChanges);
succ = await new Commands.Checkout(_repo.FullPath)
.Use(log)
.BranchAsync(branchName, false);
}
else
{
succ = await new Commands.Checkout(_repo.FullPath)
.Use(log)
.BranchAsync(branchName, true);
}
if (succ)
{

View File

@@ -14,7 +14,7 @@ namespace SourceGit.ViewModels
get;
}
public bool DiscardLocalChanges
public Models.DealWithLocalChanges DealWithLocalChanges
{
get;
set;
@@ -25,6 +25,7 @@ namespace SourceGit.ViewModels
_repo = repo;
LocalBranch = localBranch;
RemoteBranch = remoteBranch;
DealWithLocalChanges = Models.DealWithLocalChanges.DoNothing;
}
public override async Task<bool> Sure()
@@ -50,7 +51,13 @@ namespace SourceGit.ViewModels
var succ = false;
var needPopStash = false;
if (!DiscardLocalChanges)
if (DealWithLocalChanges == Models.DealWithLocalChanges.DoNothing)
{
succ = await new Commands.Checkout(_repo.FullPath)
.Use(log)
.BranchAsync(LocalBranch.Name, RemoteBranch.Head, false, true);
}
else if (DealWithLocalChanges == Models.DealWithLocalChanges.StashAndReapply)
{
var changes = await new Commands.CountLocalChanges(_repo.FullPath, false).GetResultAsync();
if (changes > 0)
@@ -61,16 +68,23 @@ namespace SourceGit.ViewModels
if (!succ)
{
log.Complete();
_repo.MarkWorkingCopyDirtyManually();
return false;
}
needPopStash = true;
}
}
succ = await new Commands.Checkout(_repo.FullPath)
.Use(log)
.BranchAsync(LocalBranch.Name, RemoteBranch.Head, DiscardLocalChanges, true);
succ = await new Commands.Checkout(_repo.FullPath)
.Use(log)
.BranchAsync(LocalBranch.Name, RemoteBranch.Head, false, true);
}
else
{
succ = await new Commands.Checkout(_repo.FullPath)
.Use(log)
.BranchAsync(LocalBranch.Name, RemoteBranch.Head, true, true);
}
if (succ)
{

View File

@@ -9,7 +9,7 @@ namespace SourceGit.ViewModels
get;
}
public bool DiscardLocalChanges
public Models.DealWithLocalChanges DealWithLocalChanges
{
get;
set;
@@ -19,7 +19,7 @@ namespace SourceGit.ViewModels
{
_repo = repo;
Commit = commit;
DiscardLocalChanges = false;
DealWithLocalChanges = Models.DealWithLocalChanges.DoNothing;
}
public override async Task<bool> Sure()
@@ -45,7 +45,13 @@ namespace SourceGit.ViewModels
var succ = false;
var needPop = false;
if (!DiscardLocalChanges)
if (DealWithLocalChanges == Models.DealWithLocalChanges.DoNothing)
{
succ = await new Commands.Checkout(_repo.FullPath)
.Use(log)
.CommitAsync(Commit.SHA, false);
}
else if (DealWithLocalChanges == Models.DealWithLocalChanges.StashAndReapply)
{
var changes = await new Commands.CountLocalChanges(_repo.FullPath, false).GetResultAsync();
if (changes > 0)
@@ -56,16 +62,23 @@ namespace SourceGit.ViewModels
if (!succ)
{
log.Complete();
_repo.MarkWorkingCopyDirtyManually();
return false;
}
needPop = true;
}
}
succ = await new Commands.Checkout(_repo.FullPath)
.Use(log)
.CommitAsync(Commit.SHA, DiscardLocalChanges);
succ = await new Commands.Checkout(_repo.FullPath)
.Use(log)
.CommitAsync(Commit.SHA, false);
}
else
{
succ = await new Commands.Checkout(_repo.FullPath)
.Use(log)
.CommitAsync(Commit.SHA, true);
}
if (succ)
{

View File

@@ -20,7 +20,12 @@ namespace SourceGit.ViewModels
get;
}
public bool DiscardLocalChanges
public bool HasLocalChanges
{
get => _repo.LocalChangesCount > 0;
}
public Models.DealWithLocalChanges DealWithLocalChanges
{
get;
set;
@@ -35,6 +40,7 @@ namespace SourceGit.ViewModels
{
_repo.UIStates.CheckoutBranchOnCreateBranch = value;
OnPropertyChanged();
UpdateOverrideTip();
}
}
}
@@ -44,6 +50,12 @@ namespace SourceGit.ViewModels
get => _repo.IsBare;
}
public string OverrideTip
{
get => _overrideTip;
private set => SetProperty(ref _overrideTip, value);
}
public bool AllowOverwrite
{
get => _allowOverwrite;
@@ -65,7 +77,8 @@ namespace SourceGit.ViewModels
Name = branch.Name;
BasedOn = branch;
DiscardLocalChanges = false;
DealWithLocalChanges = Models.DealWithLocalChanges.DoNothing;
UpdateOverrideTip();
}
public CreateBranch(Repository repo, Models.Commit commit)
@@ -76,7 +89,8 @@ namespace SourceGit.ViewModels
_head = commit.SHA;
BasedOn = commit;
DiscardLocalChanges = false;
DealWithLocalChanges = Models.DealWithLocalChanges.DoNothing;
UpdateOverrideTip();
}
public CreateBranch(Repository repo, Models.Tag tag)
@@ -87,7 +101,8 @@ namespace SourceGit.ViewModels
_head = tag.SHA;
BasedOn = tag;
DiscardLocalChanges = false;
DealWithLocalChanges = Models.DealWithLocalChanges.DoNothing;
UpdateOverrideTip();
}
public static ValidationResult ValidateBranchName(string name, ValidationContext ctx)
@@ -144,7 +159,13 @@ namespace SourceGit.ViewModels
if (CheckoutAfterCreated && !_repo.IsBare)
{
var needPopStash = false;
if (!DiscardLocalChanges)
if (DealWithLocalChanges == Models.DealWithLocalChanges.DoNothing)
{
succ = await new Commands.Checkout(_repo.FullPath)
.Use(log)
.BranchAsync(_name, _baseOnRevision, false, _allowOverwrite);
}
else if (DealWithLocalChanges == Models.DealWithLocalChanges.StashAndReapply)
{
var changes = await new Commands.CountLocalChanges(_repo.FullPath, false).GetResultAsync();
if (changes > 0)
@@ -155,16 +176,23 @@ namespace SourceGit.ViewModels
if (!succ)
{
log.Complete();
_repo.MarkWorkingCopyDirtyManually();
return false;
}
needPopStash = true;
}
}
succ = await new Commands.Checkout(_repo.FullPath)
.Use(log)
.BranchAsync(_name, _baseOnRevision, DiscardLocalChanges, _allowOverwrite);
succ = await new Commands.Checkout(_repo.FullPath)
.Use(log)
.BranchAsync(_name, _baseOnRevision, false, _allowOverwrite);
}
else
{
succ = await new Commands.Checkout(_repo.FullPath)
.Use(log)
.BranchAsync(_name, _baseOnRevision, true, _allowOverwrite);
}
if (succ)
{
@@ -205,11 +233,17 @@ namespace SourceGit.ViewModels
return true;
}
private void UpdateOverrideTip()
{
OverrideTip = CheckoutAfterCreated ? "-B in `git checkout`" : "-f in `git branch`";
}
private readonly Repository _repo = null;
private readonly string _baseOnRevision = null;
private readonly ulong _committerDate = 0;
private readonly string _head = string.Empty;
private string _name = null;
private string _overrideTip = "-B";
private bool _allowOverwrite = false;
}
}

View File

@@ -38,11 +38,11 @@ namespace SourceGit.ViewModels
set => SetProperty(ref _selectedBranch, value, true);
}
public bool DiscardLocalChanges
public Models.DealWithLocalChanges DealWithLocalChanges
{
get;
set;
} = false;
} = Models.DealWithLocalChanges.DoNothing;
public bool UseRebase
{
@@ -111,21 +111,26 @@ namespace SourceGit.ViewModels
var needPopStash = false;
if (changes > 0)
{
if (DiscardLocalChanges)
if (DealWithLocalChanges == Models.DealWithLocalChanges.DoNothing)
{
await Commands.Discard.AllAsync(_repo.FullPath, false, false, log);
// Do nothing, just let the pull command fail and show the error to user
}
else
else if (DealWithLocalChanges == Models.DealWithLocalChanges.StashAndReapply)
{
var succ = await new Commands.Stash(_repo.FullPath).Use(log).PushAsync("PULL_AUTO_STASH", false);
if (!succ)
{
log.Complete();
_repo.MarkWorkingCopyDirtyManually();
return false;
}
needPopStash = true;
}
else
{
await Commands.Discard.AllAsync(_repo.FullPath, false, false, log);
}
}
bool rs = await new Commands.Pull(

View File

@@ -3,6 +3,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:SourceGit.ViewModels"
xmlns:v="using:SourceGit.Views"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SourceGit.Views.Checkout"
x:DataType="vm:Checkout">
@@ -33,18 +34,15 @@
<TextBlock Text="{Binding BranchName}"/>
</StackPanel>
<TextBlock Grid.Row="1" Grid.Column="0"
HorizontalAlignment="Right" VerticalAlignment="Center"
Margin="0,0,8,0"
Text="{DynamicResource Text.Checkout.LocalChanges}"/>
<WrapPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center">
<RadioButton GroupName="LocalChanges"
Margin="0,0,8,0"
Content="{DynamicResource Text.Checkout.LocalChanges.StashAndReapply}"
IsChecked="{Binding !DiscardLocalChanges, Mode=TwoWay}"/>
<RadioButton GroupName="LocalChanges"
Content="{DynamicResource Text.Checkout.LocalChanges.Discard}"/>
</WrapPanel>
<Border Grid.Row="1" Grid.Column="0"
Height="32"
VerticalAlignment="Top">
<TextBlock HorizontalAlignment="Right" VerticalAlignment="Center"
Margin="0,0,8,0"
Text="{DynamicResource Text.Checkout.LocalChanges}"/>
</Border>
<v:DealWithLocalChangesMethod Grid.Row="1" Grid.Column="1"
Method="{Binding DealWithLocalChanges, Mode=TwoWay}"/>
</Grid>
</StackPanel>
</UserControl>

View File

@@ -3,6 +3,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:SourceGit.ViewModels"
xmlns:v="using:SourceGit.Views"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SourceGit.Views.CheckoutAndFastForward"
x:DataType="vm:CheckoutAndFastForward">
@@ -55,18 +56,15 @@
<TextBlock Text="{Binding RemoteBranch.FriendlyName}"/>
</StackPanel>
<TextBlock Grid.Row="2" Grid.Column="0"
HorizontalAlignment="Right" VerticalAlignment="Center"
Margin="0,0,8,0"
Text="{DynamicResource Text.Checkout.LocalChanges}"/>
<WrapPanel Grid.Row="2" Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center">
<RadioButton GroupName="LocalChanges"
Margin="0,0,8,0"
Content="{DynamicResource Text.Checkout.LocalChanges.StashAndReapply}"
IsChecked="{Binding !DiscardLocalChanges, Mode=TwoWay}"/>
<RadioButton GroupName="LocalChanges"
Content="{DynamicResource Text.Checkout.LocalChanges.Discard}"/>
</WrapPanel>
<Border Grid.Row="2" Grid.Column="0"
Height="32"
VerticalAlignment="Top">
<TextBlock HorizontalAlignment="Right" VerticalAlignment="Center"
Margin="0,0,8,0"
Text="{DynamicResource Text.Checkout.LocalChanges}"/>
</Border>
<v:DealWithLocalChangesMethod Grid.Row="2" Grid.Column="1"
Method="{Binding DealWithLocalChanges, Mode=TwoWay}"/>
</Grid>
</StackPanel>
</UserControl>

View File

@@ -3,7 +3,8 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:SourceGit.ViewModels"
xmlns:c="clr-namespace:SourceGit.Converters"
xmlns:v="using:SourceGit.Views"
xmlns:c="using:SourceGit.Converters"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SourceGit.Views.CheckoutCommit"
x:DataType="vm:CheckoutCommit">
@@ -35,18 +36,15 @@
<TextBlock Grid.Column="2" Text="{Binding Commit.Subject}" TextTrimming="CharacterEllipsis"/>
</Grid>
<TextBlock Grid.Row="1" Grid.Column="0"
HorizontalAlignment="Right" VerticalAlignment="Center"
Margin="0,0,8,0"
Text="{DynamicResource Text.Checkout.LocalChanges}"/>
<WrapPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center">
<RadioButton Content="{DynamicResource Text.Checkout.LocalChanges.StashAndReapply}"
GroupName="LocalChanges"
Margin="0,0,8,0"
IsChecked="{Binding !DiscardLocalChanges, Mode=TwoWay}"/>
<RadioButton Content="{DynamicResource Text.Checkout.LocalChanges.Discard}"
GroupName="LocalChanges"/>
</WrapPanel>
<Border Grid.Row="1" Grid.Column="0"
Height="32"
VerticalAlignment="Top">
<TextBlock HorizontalAlignment="Right" VerticalAlignment="Center"
Margin="0,0,8,0"
Text="{DynamicResource Text.Checkout.LocalChanges}"/>
</Border>
<v:DealWithLocalChangesMethod Grid.Row="1" Grid.Column="1"
Method="{Binding DealWithLocalChanges, Mode=TwoWay}"/>
<Grid Grid.Row="2" Grid.Column="1" ColumnDefinitions="Auto,*" Margin="0,6,0,0">
<Path Grid.Column="0"

View File

@@ -67,26 +67,33 @@
Text="{Binding Name, Mode=TwoWay}"
Watermark="{DynamicResource Text.CreateBranch.Name.Placeholder}"/>
<TextBlock Grid.Row="2" Grid.Column="0"
HorizontalAlignment="Right" VerticalAlignment="Center"
Margin="0,0,8,0"
Text="{DynamicResource Text.CreateBranch.LocalChanges}"
IsVisible="{Binding !IsBareRepository}"/>
<Border Grid.Row="2" Grid.Column="1" MinHeight="32" IsVisible="{Binding !IsBareRepository}">
<WrapPanel Orientation="Horizontal" VerticalAlignment="Center">
<RadioButton GroupName="LocalChanges"
Margin="0,0,8,0"
Content="{DynamicResource Text.CreateBranch.LocalChanges.StashAndReapply}"
IsChecked="{Binding !DiscardLocalChanges, Mode=TwoWay}"/>
<RadioButton GroupName="LocalChanges"
Content="{DynamicResource Text.CreateBranch.LocalChanges.Discard}"/>
</WrapPanel>
<Border Grid.Row="2" Grid.Column="0"
Height="32"
VerticalAlignment="Top">
<Border.IsVisible>
<MultiBinding Converter="{x:Static BoolConverters.And}">
<Binding Path="HasLocalChanges" Mode="OneWay"/>
<Binding Path="CheckoutAfterCreated" Mode="OneWay"/>
</MultiBinding>
</Border.IsVisible>
<TextBlock HorizontalAlignment="Right" VerticalAlignment="Center"
Margin="0,0,8,0"
Text="{DynamicResource Text.CreateBranch.LocalChanges}"/>
</Border>
<v:DealWithLocalChangesMethod Grid.Row="2" Grid.Column="1"
Method="{Binding DealWithLocalChanges, Mode=TwoWay}">
<v:DealWithLocalChangesMethod.IsVisible>
<MultiBinding Converter="{x:Static BoolConverters.And}">
<Binding Path="HasLocalChanges" Mode="OneWay"/>
<Binding Path="CheckoutAfterCreated" Mode="OneWay"/>
</MultiBinding>
</v:DealWithLocalChangesMethod.IsVisible>
</v:DealWithLocalChangesMethod>
<CheckBox Grid.Row="3" Grid.Column="1"
Content="{DynamicResource Text.CreateBranch.OverwriteExisting}"
IsChecked="{Binding AllowOverwrite, Mode=TwoWay}"
ToolTip.Tip="checkout -B or branch -f"/>
ToolTip.Tip="{Binding OverrideTip, Mode=OneWay}"/>
<CheckBox Grid.Row="4" Grid.Column="1"
Content="{DynamicResource Text.CreateBranch.Checkout}"

View File

@@ -0,0 +1,26 @@
<UserControl xmlns="https://github.com/avaloniaui"
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"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SourceGit.Views.DealWithLocalChangesMethod"
x:Name="ThisControl">
<StackPanel Orientation="Vertical" Margin="0,4,0,2">
<RadioButton Content="{DynamicResource Text.DealWithLocalChanges.DoNothing}"
x:Name="RadioDoNothing"
Height="24"
Click="OnRadioButtonClicked"
Tag="{Binding Source={x:Static m:DealWithLocalChanges.DoNothing}}"/>
<RadioButton Content="{DynamicResource Text.DealWithLocalChanges.StashAndReapply}"
x:Name="RadioStashAndReapply"
Height="24"
Click="OnRadioButtonClicked"
Tag="{Binding Source={x:Static m:DealWithLocalChanges.StashAndReapply}}"/>
<RadioButton Content="{DynamicResource Text.DealWithLocalChanges.Discard}"
x:Name="RadioDiscard"
Height="24"
Click="OnRadioButtonClicked"
Tag="{Binding Source={x:Static m:DealWithLocalChanges.Discard}}"/>
</StackPanel>
</UserControl>

View File

@@ -0,0 +1,56 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
namespace SourceGit.Views
{
public partial class DealWithLocalChangesMethod : UserControl
{
public static readonly StyledProperty<Models.DealWithLocalChanges> MethodProperty =
AvaloniaProperty.Register<DealWithLocalChangesMethod, Models.DealWithLocalChanges>(nameof(Method), Models.DealWithLocalChanges.DoNothing);
public Models.DealWithLocalChanges Method
{
get => GetValue(MethodProperty);
set => SetValue(MethodProperty, value);
}
public DealWithLocalChangesMethod()
{
InitializeComponent();
UpdateRadioButtons();
}
private void OnRadioButtonClicked(object sender, RoutedEventArgs e)
{
if (sender is RadioButton { Tag: Models.DealWithLocalChanges way })
{
Method = way;
UpdateRadioButtons();
e.Handled = true;
}
}
private void UpdateRadioButtons()
{
switch (Method)
{
case Models.DealWithLocalChanges.DoNothing:
RadioDoNothing.IsChecked = true;
RadioStashAndReapply.IsChecked = false;
RadioDiscard.IsChecked = false;
break;
case Models.DealWithLocalChanges.StashAndReapply:
RadioDoNothing.IsChecked = false;
RadioStashAndReapply.IsChecked = true;
RadioDiscard.IsChecked = false;
break;
default:
RadioDoNothing.IsChecked = false;
RadioStashAndReapply.IsChecked = false;
RadioDiscard.IsChecked = true;
break;
}
}
}
}

View File

@@ -4,6 +4,7 @@
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"
x:Class="SourceGit.Views.Pull"
x:DataType="vm:Pull">
@@ -78,18 +79,15 @@
<TextBlock Text="{Binding Current.Name}"/>
</StackPanel>
<TextBlock Grid.Row="3" Grid.Column="0"
HorizontalAlignment="Right" VerticalAlignment="Center"
Margin="0,0,8,0"
Text="{DynamicResource Text.Pull.LocalChanges}"/>
<WrapPanel Grid.Row="3" Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center">
<RadioButton GroupName="LocalChanges"
Margin="0,0,8,0"
Content="{DynamicResource Text.Pull.LocalChanges.StashAndReapply}"
IsChecked="{Binding !DiscardLocalChanges, Mode=TwoWay}"/>
<RadioButton GroupName="LocalChanges"
Content="{DynamicResource Text.Pull.LocalChanges.Discard}"/>
</WrapPanel>
<Border Grid.Row="3" Grid.Column="0"
Height="32"
VerticalAlignment="Top">
<TextBlock HorizontalAlignment="Right" VerticalAlignment="Center"
Margin="0,0,8,0"
Text="{DynamicResource Text.Pull.LocalChanges}"/>
</Border>
<v:DealWithLocalChangesMethod Grid.Row="3" Grid.Column="1"
Method="{Binding DealWithLocalChanges, Mode=TwoWay}"/>
<CheckBox Grid.Row="4" Grid.Column="1"
Content="{DynamicResource Text.Pull.UseRebase}"