mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-22 20:37:19 -08:00
feature<Fast-Forward>: allow fast-forward on local branch that not checked out.
This commit is contained in:
parent
12511007e3
commit
9d6ac9c449
4 changed files with 88 additions and 1 deletions
|
@ -29,6 +29,22 @@ namespace SourceGit.Commands {
|
|||
AutoFetch.MarkFetched(repo);
|
||||
}
|
||||
|
||||
public Fetch(string repo, string remote, string localBranch, string remoteBranch, Action<string> outputHandler) {
|
||||
Cwd = repo;
|
||||
TraitErrorAsOutput = true;
|
||||
|
||||
var sshKey = new Config(repo).Get($"remote.{remote}.sshkey");
|
||||
if (!string.IsNullOrEmpty(sshKey)) {
|
||||
Envs.Add("GIT_SSH_COMMAND", $"ssh -i '{sshKey}'");
|
||||
Args = "";
|
||||
} else {
|
||||
Args = "-c credential.helper=manager-core ";
|
||||
}
|
||||
|
||||
Args += $"fetch --progress --verbose {remote} {remoteBranch}:{localBranch}";
|
||||
handler = outputHandler;
|
||||
}
|
||||
|
||||
public override void OnReadline(string line) {
|
||||
handler?.Invoke(line);
|
||||
}
|
||||
|
|
10
src/Views/Popups/FastForwardWithoutCheckout.xaml
Normal file
10
src/Views/Popups/FastForwardWithoutCheckout.xaml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<controls:PopupWidget
|
||||
x:Class="SourceGit.Views.Popups.FastForwardWithoutCheckout"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:controls="clr-namespace:SourceGit.Views.Controls"
|
||||
mc:Ignorable="d"
|
||||
d:DesignWidth="500" Height="100">
|
||||
</controls:PopupWidget>
|
46
src/Views/Popups/FastForwardWithoutCheckout.xaml.cs
Normal file
46
src/Views/Popups/FastForwardWithoutCheckout.xaml.cs
Normal file
|
@ -0,0 +1,46 @@
|
|||
using System.Threading.Tasks;
|
||||
|
||||
namespace SourceGit.Views.Popups {
|
||||
/// <summary>
|
||||
/// 对于不是当前分支的本地分支,Fast-Forward
|
||||
/// </summary>
|
||||
public partial class FastForwardWithoutCheckout : Controls.PopupWidget {
|
||||
private string repo = null;
|
||||
private string remote = null;
|
||||
private string localBranch = null;
|
||||
private string remoteBranch = null;
|
||||
private bool isValid = false;
|
||||
|
||||
public FastForwardWithoutCheckout(string repo, string branch, string upstream) {
|
||||
int idx = upstream.IndexOf('/');
|
||||
if (idx < 0 || idx == upstream.Length - 1) {
|
||||
Models.Exception.Raise($"Invalid upstream: {upstream}");
|
||||
return;
|
||||
}
|
||||
|
||||
this.repo = repo;
|
||||
this.remote = upstream.Substring(0, idx);
|
||||
this.localBranch = branch;
|
||||
this.remoteBranch = upstream.Substring(idx+1);
|
||||
this.isValid = true;
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public override string GetTitle() {
|
||||
return App.Text("Fetch.Title");
|
||||
}
|
||||
|
||||
public override Task<bool> Start() {
|
||||
return Task.Run(() => {
|
||||
if (isValid) {
|
||||
Models.Watcher.SetEnabled(repo, false);
|
||||
new Commands.Fetch(repo, remote, localBranch, remoteBranch, UpdateProgress).Exec();
|
||||
Models.Watcher.SetEnabled(repo, true);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -654,7 +654,7 @@ namespace SourceGit.Views.Widgets {
|
|||
var upstream = branch.Upstream.Substring(13);
|
||||
var fastForward = new MenuItem();
|
||||
fastForward.Header = App.Text("BranchCM.FastForward", upstream);
|
||||
fastForward.IsEnabled = !string.IsNullOrEmpty(branch.UpstreamTrackStatus);
|
||||
fastForward.IsEnabled = !string.IsNullOrEmpty(branch.UpstreamTrackStatus) && branch.UpstreamTrackStatus.IndexOf('↑') < 0;
|
||||
fastForward.Click += (o, e) => {
|
||||
new Popups.Merge(repo.Path, upstream, branch.Name).ShowAndStart();
|
||||
e.Handled = true;
|
||||
|
@ -683,6 +683,21 @@ namespace SourceGit.Views.Widgets {
|
|||
e.Handled = true;
|
||||
};
|
||||
menu.Items.Add(checkout);
|
||||
|
||||
if (!string.IsNullOrEmpty(branch.Upstream)) {
|
||||
var upstream = branch.Upstream.Substring(13);
|
||||
var fastForward = new MenuItem();
|
||||
fastForward.Header = App.Text("BranchCM.FastForward", upstream);
|
||||
fastForward.IsEnabled = !string.IsNullOrEmpty(branch.UpstreamTrackStatus) && branch.UpstreamTrackStatus.IndexOf('↑') < 0;
|
||||
fastForward.Click += (o, e) => {
|
||||
new Popups.FastForwardWithoutCheckout(repo.Path, branch.Name, upstream).ShowAndStart();
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
menu.Items.Add(new Separator());
|
||||
menu.Items.Add(fastForward);
|
||||
}
|
||||
|
||||
menu.Items.Add(new Separator());
|
||||
menu.Items.Add(push);
|
||||
|
||||
|
|
Loading…
Reference in a new issue