mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-11-01 13:13:21 -07:00
49 lines
1.4 KiB
C#
49 lines
1.4 KiB
C#
|
using System;
|
||
|
|
||
|
namespace SourceGit.Commands {
|
||
|
|
||
|
/// <summary>
|
||
|
/// 拉回
|
||
|
/// </summary>
|
||
|
public class Pull : Command {
|
||
|
private Action<string> handler = null;
|
||
|
private bool needStash = false;
|
||
|
|
||
|
public Pull(string repo, string remote, string branch, bool useRebase, bool autoStash, Action<string> onProgress) {
|
||
|
Cwd = repo;
|
||
|
Args = "-c credential.helper=manager pull --verbose --progress --tags ";
|
||
|
TraitErrorAsOutput = true;
|
||
|
handler = onProgress;
|
||
|
|
||
|
if (useRebase) Args += "--rebase ";
|
||
|
if (autoStash) {
|
||
|
if (useRebase) Args += "--autostash ";
|
||
|
else needStash = true;
|
||
|
}
|
||
|
|
||
|
Args += $"{remote} {branch}";
|
||
|
}
|
||
|
|
||
|
public bool Run() {
|
||
|
if (needStash) {
|
||
|
var changes = new LocalChanges(Cwd).Result();
|
||
|
if (changes.Count > 0) {
|
||
|
if (!new Stash(Cwd).Push(null, "PULL_AUTO_STASH", true)) {
|
||
|
return false;
|
||
|
}
|
||
|
} else {
|
||
|
needStash = false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var succ = Exec();
|
||
|
if (needStash) new Stash(Cwd).Pop("stash@{0}");
|
||
|
return succ;
|
||
|
}
|
||
|
|
||
|
public override void OnReadline(string line) {
|
||
|
handler?.Invoke(line);
|
||
|
}
|
||
|
}
|
||
|
}
|