mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-23 20:47:25 -08: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.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.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" 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" 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.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.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" 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.Commit" xml:space="preserve">Commit :</x:String>
|
||||||
<x:String x:Key="Text.CherryPick.CommitChanges" xml:space="preserve">Commit all changes</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" 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.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.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" 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.Commit" xml:space="preserve">提交ID :</x:String>
|
||||||
<x:String x:Key="Text.CherryPick.CommitChanges" xml:space="preserve">提交变化</x:String>
|
<x:String x:Key="Text.CherryPick.CommitChanges" xml:space="preserve">提交变化</x:String>
|
||||||
|
|
|
@ -9,28 +9,11 @@ namespace SourceGit.ViewModels
|
||||||
get;
|
get;
|
||||||
private set;
|
private set;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool HasLocalChanges
|
|
||||||
{
|
|
||||||
get => _repo.WorkingCopyChangesCount > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool LeaveLocalChanges
|
public bool AutoStash
|
||||||
{
|
{
|
||||||
get => _leaveLocalChanges;
|
get => _autoStash;
|
||||||
set => SetProperty(ref _leaveLocalChanges, value);
|
set => SetProperty(ref _autoStash, value);
|
||||||
}
|
|
||||||
|
|
||||||
public bool DiscardLocalChanges
|
|
||||||
{
|
|
||||||
get => _discardLocalChanges;
|
|
||||||
set => SetProperty(ref _discardLocalChanges, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool StashLocalChanges
|
|
||||||
{
|
|
||||||
get => _stashLocalChanges;
|
|
||||||
set => SetProperty(ref _stashLocalChanges, value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Checkout(Repository repo, string branch)
|
public Checkout(Repository repo, string branch)
|
||||||
|
@ -38,69 +21,63 @@ namespace SourceGit.ViewModels
|
||||||
_repo = repo;
|
_repo = repo;
|
||||||
Branch = branch;
|
Branch = branch;
|
||||||
View = new Views.Checkout() { DataContext = this };
|
View = new Views.Checkout() { DataContext = this };
|
||||||
|
|
||||||
StashLocalChanges = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task<bool> Sure()
|
public override Task<bool> Sure()
|
||||||
{
|
{
|
||||||
_repo.SetWatcherEnabled(false);
|
_repo.SetWatcherEnabled(false);
|
||||||
ProgressDescription = $"Checkout '{Branch}' ...";
|
ProgressDescription = $"Checkout '{Branch}' ...";
|
||||||
var hasLocalChanges = HasLocalChanges;
|
|
||||||
|
|
||||||
|
var hasLocalChanges = _repo.WorkingCopyChangesCount > 0;
|
||||||
return Task.Run(() =>
|
return Task.Run(() =>
|
||||||
{
|
{
|
||||||
var succ = false;
|
var needPopStash = false;
|
||||||
if (hasLocalChanges)
|
if (hasLocalChanges)
|
||||||
{
|
{
|
||||||
if (DiscardLocalChanges)
|
if (AutoStash)
|
||||||
{
|
{
|
||||||
SetProgressDescription("Discard local changes...");
|
SetProgressDescription("Adding untracked changes ...");
|
||||||
Commands.Discard.All(_repo.FullPath);
|
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)
|
||||||
|
{
|
||||||
|
CallUIThread(() => _repo.SetWatcherEnabled(true));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
needPopStash = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
SetProgressDescription("Stash local changes...");
|
SetProgressDescription("Discard local changes ...");
|
||||||
succ = new Commands.Add(_repo.FullPath).Exec();
|
Commands.Discard.All(_repo.FullPath);
|
||||||
succ = new Commands.Stash(_repo.FullPath).Push("CHECKOUT_AUTO_STASH");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SetProgressDescription("Checkout branch ...");
|
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...");
|
SetProgressDescription("Re-apply local changes...");
|
||||||
succ = new Commands.Stash(_repo.FullPath).Apply("stash@{0}");
|
rs = new Commands.Stash(_repo.FullPath).Apply("stash@{0}");
|
||||||
if (succ)
|
if (rs)
|
||||||
{
|
{
|
||||||
succ = new Commands.Stash(_repo.FullPath).Drop("stash@{0}");
|
rs = new Commands.Stash(_repo.FullPath).Drop("stash@{0}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CallUIThread(() => _repo.SetWatcherEnabled(true));
|
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 readonly Repository _repo = null;
|
||||||
private bool _leaveLocalChanges;
|
private bool _autoStash = true;
|
||||||
private bool _discardLocalChanges;
|
|
||||||
private bool _stashLocalChanges;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -447,10 +447,7 @@ namespace SourceGit.ViewModels
|
||||||
checkout.Icon = App.CreateMenuIcon("Icons.Check");
|
checkout.Icon = App.CreateMenuIcon("Icons.Check");
|
||||||
checkout.Click += (o, e) =>
|
checkout.Click += (o, e) =>
|
||||||
{
|
{
|
||||||
if (PopupHost.CanCreatePopup())
|
_repo.CheckoutLocalBranch(branch.Name);
|
||||||
{
|
|
||||||
Checkout.ShowPopup(_repo, branch.Name);
|
|
||||||
}
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
};
|
};
|
||||||
submenu.Items.Add(checkout);
|
submenu.Items.Add(checkout);
|
||||||
|
@ -526,16 +523,16 @@ namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
if (b.IsLocal && b.Upstream == branch.FullName)
|
if (b.IsLocal && b.Upstream == branch.FullName)
|
||||||
{
|
{
|
||||||
if (b.IsCurrent)
|
if (!b.IsCurrent)
|
||||||
return;
|
_repo.CheckoutLocalBranch(b.Name);
|
||||||
if (PopupHost.CanCreatePopup())
|
|
||||||
Checkout.ShowPopup(_repo, b.Name);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PopupHost.CanCreatePopup())
|
if (PopupHost.CanCreatePopup())
|
||||||
PopupHost.ShowPopup(new CreateBranch(_repo, branch));
|
PopupHost.ShowPopup(new CreateBranch(_repo, branch));
|
||||||
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
};
|
};
|
||||||
submenu.Items.Add(checkout);
|
submenu.Items.Add(checkout);
|
||||||
|
|
|
@ -690,6 +690,17 @@ namespace SourceGit.ViewModels
|
||||||
PopupHost.ShowPopup(new CreateBranch(this, current));
|
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()
|
public void CreateNewTag()
|
||||||
{
|
{
|
||||||
var current = Branches.Find(x => x.IsCurrent);
|
var current = Branches.Find(x => x.IsCurrent);
|
||||||
|
@ -842,11 +853,7 @@ namespace SourceGit.ViewModels
|
||||||
checkout.Icon = App.CreateMenuIcon("Icons.Check");
|
checkout.Icon = App.CreateMenuIcon("Icons.Check");
|
||||||
checkout.Click += (o, e) =>
|
checkout.Click += (o, e) =>
|
||||||
{
|
{
|
||||||
if (PopupHost.CanCreatePopup())
|
CheckoutLocalBranch(branch.Name);
|
||||||
{
|
|
||||||
Checkout.ShowPopup(this, branch.Name);
|
|
||||||
}
|
|
||||||
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
};
|
};
|
||||||
menu.Items.Add(checkout);
|
menu.Items.Add(checkout);
|
||||||
|
|
|
@ -10,22 +10,29 @@
|
||||||
<TextBlock FontSize="18"
|
<TextBlock FontSize="18"
|
||||||
Classes="bold"
|
Classes="bold"
|
||||||
Text="{DynamicResource Text.Checkout}"/>
|
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,*">
|
||||||
<Path Width="14" Height="14" Margin="8,0" Data="{StaticResource Icons.Branch}"/>
|
<TextBlock Grid.Row="0" Grid.Column="0"
|
||||||
<TextBlock Text="{Binding Branch}"/>
|
HorizontalAlignment="Right" VerticalAlignment="Center"
|
||||||
</StackPanel>
|
Margin="0,0,8,0"
|
||||||
<StackPanel Orientation="Vertical" IsVisible="{Binding HasLocalChanges}">
|
Text="{DynamicResource Text.Checkout.Target}"/>
|
||||||
<TextBlock Text="{DynamicResource Text.Checkout.LocalChanges}"/>
|
<StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal">
|
||||||
<RadioButton Content="{DynamicResource Text.Checkout.LocalChanges.StashAndReply}"
|
<Path Width="14" Height="14" Margin="8,0" Data="{StaticResource Icons.Branch}"/>
|
||||||
GroupName="LocalChanges"
|
<TextBlock Text="{Binding Branch}"/>
|
||||||
IsChecked="{Binding StashLocalChanges, Mode=TwoWay }"/>
|
</StackPanel>
|
||||||
<RadioButton Content="{DynamicResource Text.Checkout.LocalChanges.Discard}"
|
|
||||||
GroupName="LocalChanges"
|
<TextBlock Grid.Row="1" Grid.Column="0"
|
||||||
IsChecked="{Binding DiscardLocalChanges, Mode=TwoWay}"/>
|
HorizontalAlignment="Right" VerticalAlignment="Center"
|
||||||
<RadioButton Content="{DynamicResource Text.Checkout.LocalChanges.Leave}"
|
Margin="0,0,8,0"
|
||||||
GroupName="LocalChanges"
|
Text="{DynamicResource Text.Checkout.LocalChanges}"/>
|
||||||
IsChecked="{Binding LeaveLocalChanges, Mode=TwoWay}"/>
|
<StackPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal">
|
||||||
</StackPanel>
|
<RadioButton Content="{DynamicResource Text.Checkout.LocalChanges.StashAndReply}"
|
||||||
|
GroupName="LocalChanges"
|
||||||
|
IsChecked="{Binding AutoStash, Mode=TwoWay}"/>
|
||||||
|
<RadioButton Content="{DynamicResource Text.Checkout.LocalChanges.Discard}"
|
||||||
|
GroupName="LocalChanges"
|
||||||
|
Margin="8,0,0,0"/>
|
||||||
|
</StackPanel>
|
||||||
|
</Grid>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|
|
@ -298,7 +298,7 @@ namespace SourceGit.Views
|
||||||
if (branch.IsCurrent)
|
if (branch.IsCurrent)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ViewModels.Checkout.ShowPopup(repo, branch.Name);
|
repo.CheckoutLocalBranch(branch.Name);
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue