using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SourceGit.Git {
///
/// Git stash
///
public class Stash {
///
/// SHA for this stash
///
public string SHA { get; set; }
///
/// Name
///
public string Name { get; set; }
///
/// Author
///
public User Author { get; set; } = new User();
///
/// Message
///
public string Message { get; set; }
///
/// Stash push.
///
///
///
///
///
public static void Push(Repository repo, bool includeUntracked, string message, List files) {
string specialFiles = "";
if (files.Count > 0) {
specialFiles = " --";
foreach (var f in files) specialFiles += $" \"{f}\"";
}
string args = "stash push ";
if (includeUntracked) args += "-u ";
if (!string.IsNullOrEmpty(message)) args += $"-m \"{message}\" ";
var errs = repo.RunCommand(args + specialFiles, null);
if (errs != null) App.RaiseError(errs);
}
///
/// Get changed file list in this stash.
///
///
///
public List GetChanges(Repository repo) {
List changes = new List();
var errs = repo.RunCommand($"diff --name-status --pretty=format: {SHA}^ {SHA}", line => {
var change = Change.Parse(line);
if (change != null) changes.Add(change);
});
if (errs != null) App.RaiseError(errs);
return changes;
}
///
/// Apply stash.
///
///
public void Apply(Repository repo) {
var errs = repo.RunCommand($"stash apply -q {Name}", null);
if (errs != null) App.RaiseError(errs);
}
///
/// Pop stash
///
///
public void Pop(Repository repo) {
var errs = repo.RunCommand($"stash pop -q {Name}", null);
if (errs != null) App.RaiseError(errs);
}
///
/// Drop stash
///
///
public void Drop(Repository repo) {
var errs = repo.RunCommand($"stash drop -q {Name}", null);
if (errs != null) App.RaiseError(errs);
}
}
}