using System; namespace SourceGit.Commands { /// /// 拉回 /// public class Pull : Command { private Action handler = null; private bool needStash = false; public Pull(string repo, string remote, string branch, bool useRebase, bool autoStash, Action 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); } } }