mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-21 20:24:59 +00:00
refactor<*>: rewrite all codes...
This commit is contained in:
parent
89ff8aa744
commit
30ab8ae954
342 changed files with 17208 additions and 19633 deletions
48
src/Commands/Pull.cs
Normal file
48
src/Commands/Pull.cs
Normal file
|
@ -0,0 +1,48 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue