mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-11-01 13:13:21 -07:00
code_review: PR #98
* remove the `Leave` option (it may lead to an undefined behaviour), so user can only choose `Stash & reapply` or `Discard`. * re-design the UI * remove unused resources
This commit is contained in:
parent
927a1cab24
commit
776605cb68
7 changed files with 75 additions and 89 deletions
|
@ -52,11 +52,10 @@
|
|||
<x:String x:Key="Text.ChangeDisplayMode.List" xml:space="preserve">Show as List</x:String>
|
||||
<x:String x:Key="Text.ChangeDisplayMode.Tree" xml:space="preserve">Show as Tree</x:String>
|
||||
<x:String x:Key="Text.Checkout" xml:space="preserve">Checkout Branch</x:String>
|
||||
<x:String x:Key="Text.Checkout.Target" xml:space="preserve">Target :</x:String>
|
||||
<x:String x:Key="Text.Checkout.Target" xml:space="preserve">Branch :</x:String>
|
||||
<x:String x:Key="Text.Checkout.LocalChanges" xml:space="preserve">Local Changes :</x:String>
|
||||
<x:String x:Key="Text.Checkout.LocalChanges.StashAndReply" xml:space="preserve">Stash & Reapply</x:String>
|
||||
<x:String x:Key="Text.Checkout.LocalChanges.Discard" xml:space="preserve">Discard</x:String>
|
||||
<x:String x:Key="Text.Checkout.LocalChanges.Leave" xml:space="preserve">Leave</x:String>
|
||||
<x:String x:Key="Text.CherryPick" xml:space="preserve">Cherry-Pick This Commit</x:String>
|
||||
<x:String x:Key="Text.CherryPick.Commit" xml:space="preserve">Commit :</x:String>
|
||||
<x:String x:Key="Text.CherryPick.CommitChanges" xml:space="preserve">Commit all changes</x:String>
|
||||
|
|
|
@ -56,7 +56,6 @@
|
|||
<x:String x:Key="Text.Checkout.LocalChanges" xml:space="preserve">未提交更改 :</x:String>
|
||||
<x:String x:Key="Text.Checkout.LocalChanges.StashAndReply" xml:space="preserve">贮藏(stash)并自动恢复</x:String>
|
||||
<x:String x:Key="Text.Checkout.LocalChanges.Discard" xml:space="preserve">忽略</x:String>
|
||||
<x:String x:Key="Text.Checkout.LocalChanges.Leave" xml:space="preserve">保持原样</x:String>
|
||||
<x:String x:Key="Text.CherryPick" xml:space="preserve">挑选(cherry-pick)此提交</x:String>
|
||||
<x:String x:Key="Text.CherryPick.Commit" xml:space="preserve">提交ID :</x:String>
|
||||
<x:String x:Key="Text.CherryPick.CommitChanges" xml:space="preserve">提交变化</x:String>
|
||||
|
|
|
@ -10,27 +10,10 @@ namespace SourceGit.ViewModels
|
|||
private set;
|
||||
}
|
||||
|
||||
public bool HasLocalChanges
|
||||
public bool AutoStash
|
||||
{
|
||||
get => _repo.WorkingCopyChangesCount > 0;
|
||||
}
|
||||
|
||||
public bool LeaveLocalChanges
|
||||
{
|
||||
get => _leaveLocalChanges;
|
||||
set => SetProperty(ref _leaveLocalChanges, value);
|
||||
}
|
||||
|
||||
public bool DiscardLocalChanges
|
||||
{
|
||||
get => _discardLocalChanges;
|
||||
set => SetProperty(ref _discardLocalChanges, value);
|
||||
}
|
||||
|
||||
public bool StashLocalChanges
|
||||
{
|
||||
get => _stashLocalChanges;
|
||||
set => SetProperty(ref _stashLocalChanges, value);
|
||||
get => _autoStash;
|
||||
set => SetProperty(ref _autoStash, value);
|
||||
}
|
||||
|
||||
public Checkout(Repository repo, string branch)
|
||||
|
@ -38,69 +21,63 @@ namespace SourceGit.ViewModels
|
|||
_repo = repo;
|
||||
Branch = branch;
|
||||
View = new Views.Checkout() { DataContext = this };
|
||||
|
||||
StashLocalChanges = true;
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
{
|
||||
_repo.SetWatcherEnabled(false);
|
||||
ProgressDescription = $"Checkout '{Branch}' ...";
|
||||
var hasLocalChanges = HasLocalChanges;
|
||||
|
||||
var hasLocalChanges = _repo.WorkingCopyChangesCount > 0;
|
||||
return Task.Run(() =>
|
||||
{
|
||||
var succ = false;
|
||||
var needPopStash = false;
|
||||
if (hasLocalChanges)
|
||||
{
|
||||
if (DiscardLocalChanges)
|
||||
if (AutoStash)
|
||||
{
|
||||
SetProgressDescription("Discard local changes...");
|
||||
Commands.Discard.All(_repo.FullPath);
|
||||
SetProgressDescription("Adding untracked changes ...");
|
||||
var succ = new Commands.Add(_repo.FullPath).Exec();
|
||||
if (succ)
|
||||
{
|
||||
SetProgressDescription("Stash local changes ...");
|
||||
succ = new Commands.Stash(_repo.FullPath).Push("CHECKOUT_AUTO_STASH");
|
||||
}
|
||||
|
||||
if (StashLocalChanges)
|
||||
if (!succ)
|
||||
{
|
||||
SetProgressDescription("Stash local changes...");
|
||||
succ = new Commands.Add(_repo.FullPath).Exec();
|
||||
succ = new Commands.Stash(_repo.FullPath).Push("CHECKOUT_AUTO_STASH");
|
||||
CallUIThread(() => _repo.SetWatcherEnabled(true));
|
||||
return false;
|
||||
}
|
||||
|
||||
needPopStash = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
SetProgressDescription("Discard local changes ...");
|
||||
Commands.Discard.All(_repo.FullPath);
|
||||
}
|
||||
}
|
||||
|
||||
SetProgressDescription("Checkout branch ...");
|
||||
succ = new Commands.Checkout(_repo.FullPath).Branch(Branch, SetProgressDescription);
|
||||
var rs = new Commands.Checkout(_repo.FullPath).Branch(Branch, SetProgressDescription);
|
||||
|
||||
if(hasLocalChanges && StashLocalChanges)
|
||||
if(needPopStash)
|
||||
{
|
||||
SetProgressDescription("Re-apply local changes...");
|
||||
succ = new Commands.Stash(_repo.FullPath).Apply("stash@{0}");
|
||||
if (succ)
|
||||
rs = new Commands.Stash(_repo.FullPath).Apply("stash@{0}");
|
||||
if (rs)
|
||||
{
|
||||
succ = new Commands.Stash(_repo.FullPath).Drop("stash@{0}");
|
||||
rs = new Commands.Stash(_repo.FullPath).Drop("stash@{0}");
|
||||
}
|
||||
}
|
||||
|
||||
CallUIThread(() => _repo.SetWatcherEnabled(true));
|
||||
return succ;
|
||||
return rs;
|
||||
});
|
||||
}
|
||||
|
||||
public static void ShowPopup(Repository repo, string branch)
|
||||
{
|
||||
var checkout = new Checkout(repo, branch);
|
||||
if (repo.WorkingCopyChangesCount > 0)
|
||||
{
|
||||
PopupHost.ShowPopup(checkout);
|
||||
}
|
||||
else
|
||||
{
|
||||
PopupHost.ShowAndStartPopup(checkout);
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Repository _repo;
|
||||
private bool _leaveLocalChanges;
|
||||
private bool _discardLocalChanges;
|
||||
private bool _stashLocalChanges;
|
||||
private readonly Repository _repo = null;
|
||||
private bool _autoStash = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -447,10 +447,7 @@ namespace SourceGit.ViewModels
|
|||
checkout.Icon = App.CreateMenuIcon("Icons.Check");
|
||||
checkout.Click += (o, e) =>
|
||||
{
|
||||
if (PopupHost.CanCreatePopup())
|
||||
{
|
||||
Checkout.ShowPopup(_repo, branch.Name);
|
||||
}
|
||||
_repo.CheckoutLocalBranch(branch.Name);
|
||||
e.Handled = true;
|
||||
};
|
||||
submenu.Items.Add(checkout);
|
||||
|
@ -526,16 +523,16 @@ namespace SourceGit.ViewModels
|
|||
{
|
||||
if (b.IsLocal && b.Upstream == branch.FullName)
|
||||
{
|
||||
if (b.IsCurrent)
|
||||
return;
|
||||
if (PopupHost.CanCreatePopup())
|
||||
Checkout.ShowPopup(_repo, b.Name);
|
||||
if (!b.IsCurrent)
|
||||
_repo.CheckoutLocalBranch(b.Name);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (PopupHost.CanCreatePopup())
|
||||
PopupHost.ShowPopup(new CreateBranch(_repo, branch));
|
||||
|
||||
e.Handled = true;
|
||||
};
|
||||
submenu.Items.Add(checkout);
|
||||
|
|
|
@ -690,6 +690,17 @@ namespace SourceGit.ViewModels
|
|||
PopupHost.ShowPopup(new CreateBranch(this, current));
|
||||
}
|
||||
|
||||
public void CheckoutLocalBranch(string branch)
|
||||
{
|
||||
if (!PopupHost.CanCreatePopup())
|
||||
return;
|
||||
|
||||
if (WorkingCopyChangesCount > 0)
|
||||
PopupHost.ShowPopup(new Checkout(this, branch));
|
||||
else
|
||||
PopupHost.ShowAndStartPopup(new Checkout(this, branch));
|
||||
}
|
||||
|
||||
public void CreateNewTag()
|
||||
{
|
||||
var current = Branches.Find(x => x.IsCurrent);
|
||||
|
@ -842,11 +853,7 @@ namespace SourceGit.ViewModels
|
|||
checkout.Icon = App.CreateMenuIcon("Icons.Check");
|
||||
checkout.Click += (o, e) =>
|
||||
{
|
||||
if (PopupHost.CanCreatePopup())
|
||||
{
|
||||
Checkout.ShowPopup(this, branch.Name);
|
||||
}
|
||||
|
||||
CheckoutLocalBranch(branch.Name);
|
||||
e.Handled = true;
|
||||
};
|
||||
menu.Items.Add(checkout);
|
||||
|
|
|
@ -10,22 +10,29 @@
|
|||
<TextBlock FontSize="18"
|
||||
Classes="bold"
|
||||
Text="{DynamicResource Text.Checkout}"/>
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,16,0,0">
|
||||
<TextBlock Text="{DynamicResource Text.Checkout.Target}"/>
|
||||
|
||||
<Grid Margin="0,16,0,0" RowDefinitions="32,32" ColumnDefinitions="150,*">
|
||||
<TextBlock Grid.Row="0" Grid.Column="0"
|
||||
HorizontalAlignment="Right" VerticalAlignment="Center"
|
||||
Margin="0,0,8,0"
|
||||
Text="{DynamicResource Text.Checkout.Target}"/>
|
||||
<StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal">
|
||||
<Path Width="14" Height="14" Margin="8,0" Data="{StaticResource Icons.Branch}"/>
|
||||
<TextBlock Text="{Binding Branch}"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Vertical" IsVisible="{Binding HasLocalChanges}">
|
||||
<TextBlock Text="{DynamicResource Text.Checkout.LocalChanges}"/>
|
||||
|
||||
<TextBlock Grid.Row="1" Grid.Column="0"
|
||||
HorizontalAlignment="Right" VerticalAlignment="Center"
|
||||
Margin="0,0,8,0"
|
||||
Text="{DynamicResource Text.Checkout.LocalChanges}"/>
|
||||
<StackPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal">
|
||||
<RadioButton Content="{DynamicResource Text.Checkout.LocalChanges.StashAndReply}"
|
||||
GroupName="LocalChanges"
|
||||
IsChecked="{Binding StashLocalChanges, Mode=TwoWay }"/>
|
||||
IsChecked="{Binding AutoStash, Mode=TwoWay}"/>
|
||||
<RadioButton Content="{DynamicResource Text.Checkout.LocalChanges.Discard}"
|
||||
GroupName="LocalChanges"
|
||||
IsChecked="{Binding DiscardLocalChanges, Mode=TwoWay}"/>
|
||||
<RadioButton Content="{DynamicResource Text.Checkout.LocalChanges.Leave}"
|
||||
GroupName="LocalChanges"
|
||||
IsChecked="{Binding LeaveLocalChanges, Mode=TwoWay}"/>
|
||||
Margin="8,0,0,0"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
|
|
|
@ -298,7 +298,7 @@ namespace SourceGit.Views
|
|||
if (branch.IsCurrent)
|
||||
return;
|
||||
|
||||
ViewModels.Checkout.ShowPopup(repo, branch.Name);
|
||||
repo.CheckoutLocalBranch(branch.Name);
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue