mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-24 20:57:19 -08:00
Merge branch 'bogomolets-owl/develop' into develop (#98)
This commit is contained in:
commit
2e53945058
7 changed files with 100 additions and 18 deletions
|
@ -52,7 +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.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.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>
|
||||||
|
|
|
@ -53,6 +53,9 @@
|
||||||
<x:String x:Key="Text.ChangeDisplayMode.Tree" xml:space="preserve">树形模式</x:String>
|
<x:String x:Key="Text.ChangeDisplayMode.Tree" xml:space="preserve">树形模式</x:String>
|
||||||
<x:String x:Key="Text.Checkout" xml:space="preserve">检出(checkout)分支</x:String>
|
<x:String x:Key="Text.Checkout" xml:space="preserve">检出(checkout)分支</x:String>
|
||||||
<x:String x:Key="Text.Checkout.Target" xml:space="preserve">目标分支 :</x:String>
|
<x:String x:Key="Text.Checkout.Target" 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.Discard" 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>
|
||||||
|
|
|
@ -10,6 +10,12 @@ namespace SourceGit.ViewModels
|
||||||
private set;
|
private set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool AutoStash
|
||||||
|
{
|
||||||
|
get => _autoStash;
|
||||||
|
set => SetProperty(ref _autoStash, value);
|
||||||
|
}
|
||||||
|
|
||||||
public Checkout(Repository repo, string branch)
|
public Checkout(Repository repo, string branch)
|
||||||
{
|
{
|
||||||
_repo = repo;
|
_repo = repo;
|
||||||
|
@ -22,14 +28,56 @@ namespace SourceGit.ViewModels
|
||||||
_repo.SetWatcherEnabled(false);
|
_repo.SetWatcherEnabled(false);
|
||||||
ProgressDescription = $"Checkout '{Branch}' ...";
|
ProgressDescription = $"Checkout '{Branch}' ...";
|
||||||
|
|
||||||
|
var hasLocalChanges = _repo.WorkingCopyChangesCount > 0;
|
||||||
return Task.Run(() =>
|
return Task.Run(() =>
|
||||||
{
|
{
|
||||||
var succ = new Commands.Checkout(_repo.FullPath).Branch(Branch, SetProgressDescription);
|
var needPopStash = false;
|
||||||
|
if (hasLocalChanges)
|
||||||
|
{
|
||||||
|
if (AutoStash)
|
||||||
|
{
|
||||||
|
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 (!succ)
|
||||||
|
{
|
||||||
|
CallUIThread(() => _repo.SetWatcherEnabled(true));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
needPopStash = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetProgressDescription("Discard local changes ...");
|
||||||
|
Commands.Discard.All(_repo.FullPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SetProgressDescription("Checkout branch ...");
|
||||||
|
var rs = new Commands.Checkout(_repo.FullPath).Branch(Branch, SetProgressDescription);
|
||||||
|
|
||||||
|
if(needPopStash)
|
||||||
|
{
|
||||||
|
SetProgressDescription("Re-apply local changes...");
|
||||||
|
rs = new Commands.Stash(_repo.FullPath).Apply("stash@{0}");
|
||||||
|
if (rs)
|
||||||
|
{
|
||||||
|
rs = new Commands.Stash(_repo.FullPath).Drop("stash@{0}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CallUIThread(() => _repo.SetWatcherEnabled(true));
|
CallUIThread(() => _repo.SetWatcherEnabled(true));
|
||||||
return succ;
|
return rs;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly Repository _repo;
|
private readonly Repository _repo = null;
|
||||||
|
private bool _autoStash = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -447,8 +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);
|
||||||
PopupHost.ShowAndStartPopup(new Checkout(_repo, branch.Name));
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
};
|
};
|
||||||
submenu.Items.Add(checkout);
|
submenu.Items.Add(checkout);
|
||||||
|
@ -524,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())
|
|
||||||
PopupHost.ShowAndStartPopup(new Checkout(_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,8 +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);
|
||||||
PopupHost.ShowAndStartPopup(new Checkout(this, branch.Name));
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
};
|
};
|
||||||
menu.Items.Add(checkout);
|
menu.Items.Add(checkout);
|
||||||
|
|
|
@ -10,10 +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"
|
||||||
|
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>
|
||||||
|
|
||||||
|
<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 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.PopupHost.ShowAndStartPopup(new ViewModels.Checkout(repo, branch.Name));
|
repo.CheckoutLocalBranch(branch.Name);
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue