mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-21 12:15:00 +00:00
fix<Discard>: fix discard with files not only dropped changes selected but also others
This commit is contained in:
parent
30ab8ae954
commit
8f3c2fdc32
4 changed files with 47 additions and 20 deletions
|
@ -7,31 +7,37 @@ namespace SourceGit.Commands {
|
|||
/// </summary>
|
||||
public class Discard {
|
||||
private string repo = null;
|
||||
private List<string> files = new List<string>();
|
||||
|
||||
public Discard(string repo, List<Models.Change> changes) {
|
||||
public Discard(string repo) {
|
||||
this.repo = repo;
|
||||
|
||||
if (changes != null && changes.Count > 0) {
|
||||
foreach (var c in changes) {
|
||||
if (c.WorkTree == Models.Change.Status.Untracked || c.WorkTree == Models.Change.Status.Added) continue;
|
||||
files.Add(c.Path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool Exec() {
|
||||
if (files.Count == 0) {
|
||||
new Reset(repo, "HEAD", "--hard").Exec();
|
||||
} else {
|
||||
for (int i = 0; i < files.Count; i += 10) {
|
||||
var count = Math.Min(10, files.Count - i);
|
||||
new Checkout(repo).Files(files.GetRange(i, count));
|
||||
public void Whole() {
|
||||
new Reset(repo, "HEAD", "--hard").Exec();
|
||||
new Clean(repo).Exec();
|
||||
}
|
||||
|
||||
public void Changes(List<Models.Change> changes) {
|
||||
var needClean = new List<string>();
|
||||
var needCheckout = new List<string>();
|
||||
|
||||
foreach (var c in changes) {
|
||||
if (c.WorkTree == Models.Change.Status.Untracked || c.WorkTree == Models.Change.Status.Added) {
|
||||
needClean.Add(c.Path);
|
||||
} else {
|
||||
needCheckout.Add(c.Path);
|
||||
}
|
||||
}
|
||||
|
||||
new Clean(repo).Exec();
|
||||
return true;
|
||||
for (int i = 0; i < needClean.Count; i += 10) {
|
||||
var count = Math.Min(10, needClean.Count - i);
|
||||
new Clean(repo, needClean.GetRange(i, count)).Exec();
|
||||
}
|
||||
|
||||
for (int i = 0; i < needCheckout.Count; i += 10) {
|
||||
var count = Math.Min(10, needCheckout.Count - i);
|
||||
new Checkout(repo).Files(needCheckout.GetRange(i, count));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue