fix<Stash>: fix stash failed when there's too many files to be stashed

This commit is contained in:
leo 2023-10-10 16:59:47 +08:00
parent 905531f2db
commit ccb3c07064
4 changed files with 53 additions and 31 deletions

View file

@ -31,7 +31,7 @@ namespace SourceGit.Commands {
if (needStash) { if (needStash) {
var changes = new LocalChanges(Cwd).Result(); var changes = new LocalChanges(Cwd).Result();
if (changes.Count > 0) { if (changes.Count > 0) {
if (!new Stash(Cwd).Push(changes, "PULL_AUTO_STASH")) { if (!new Stash(Cwd).Push(changes, "PULL_AUTO_STASH", true)) {
return false; return false;
} }
} else { } else {

View file

@ -11,7 +11,27 @@ namespace SourceGit.Commands {
Cwd = repo; Cwd = repo;
} }
public bool Push(List<Models.Change> changes, string message) { public bool Push(List<Models.Change> changes, string message, bool bFull) {
if (bFull) {
var needAdd = new List<string>();
foreach (var c in changes) {
if (c.WorkTree == Models.Change.Status.Added || c.WorkTree == Models.Change.Status.Untracked) {
needAdd.Add(c.Path);
if (needAdd.Count > 10) {
new Add(Cwd, needAdd).Exec();
needAdd.Clear();
}
}
}
if (needAdd.Count > 0) {
new Add(Cwd, needAdd).Exec();
needAdd.Clear();
}
Args = $"stash push -m \"{message}\"";
return Exec();
} else {
var temp = Path.GetTempFileName(); var temp = Path.GetTempFileName();
var stream = new FileStream(temp, FileMode.Create); var stream = new FileStream(temp, FileMode.Create);
var writer = new StreamWriter(stream); var writer = new StreamWriter(stream);
@ -43,6 +63,7 @@ namespace SourceGit.Commands {
File.Delete(temp); File.Delete(temp);
return succ; return succ;
} }
}
public bool Apply(string name) { public bool Apply(string name) {
Args = $"stash apply -q {name}"; Args = $"stash apply -q {name}";

View file

@ -67,7 +67,7 @@ namespace SourceGit.Views.Popups {
var changes = new Commands.LocalChanges(repo).Result(); var changes = new Commands.LocalChanges(repo).Result();
if (changes.Count > 0) { if (changes.Count > 0) {
if (AutoStash) { if (AutoStash) {
if (!new Commands.Stash(repo).Push(changes, "NEWBRANCH_AUTO_STASH")) { if (!new Commands.Stash(repo).Push(changes, "NEWBRANCH_AUTO_STASH", true)) {
return false; return false;
} }
} else { } else {

View file

@ -29,7 +29,8 @@ namespace SourceGit.Views.Popups {
return Task.Run(() => { return Task.Run(() => {
Models.Watcher.SetEnabled(repo, false); Models.Watcher.SetEnabled(repo, false);
if (changes == null || changes.Count == 0) { var bFull = changes == null || changes.Count == 0;
if (bFull) {
changes = new Commands.LocalChanges(repo).Result(); changes = new Commands.LocalChanges(repo).Result();
} }
@ -42,7 +43,7 @@ namespace SourceGit.Views.Popups {
} }
} }
if (jobs.Count > 0) new Commands.Stash(repo).Push(changes, message); if (jobs.Count > 0) new Commands.Stash(repo).Push(changes, message, bFull);
Models.Watcher.SetEnabled(repo, true); Models.Watcher.SetEnabled(repo, true);
return true; return true;
}); });