refactor: rewrite amend behaviour (#300)

* toggle amend will show changes in HEAD commit
* since discard is not compatible with staged changes in `amend` mode, we only allows user to discard unstaged changes
This commit is contained in:
leo 2024-07-31 12:04:29 +08:00
parent 3c5a661fa0
commit f55a576013
No known key found for this signature in database
9 changed files with 261 additions and 86 deletions

View file

@ -11,7 +11,7 @@ namespace SourceGit.Commands
new Clean(repo).Exec();
}
public static void ChangesInWorkTree(string repo, List<Models.Change> changes)
public static void Changes(string repo, List<Models.Change> changes)
{
var needClean = new List<string>();
var needCheckout = new List<string>();
@ -19,13 +19,9 @@ namespace SourceGit.Commands
foreach (var c in changes)
{
if (c.WorkTree == Models.ChangeState.Untracked || c.WorkTree == Models.ChangeState.Added)
{
needClean.Add(c.Path);
}
else
{
needCheckout.Add(c.Path);
}
}
for (int i = 0; i < needClean.Count; i += 10)
@ -40,17 +36,5 @@ namespace SourceGit.Commands
new Restore(repo, needCheckout.GetRange(i, count), "--worktree --recurse-submodules").Exec();
}
}
public static void ChangesInStaged(string repo, List<Models.Change> changes)
{
for (int i = 0; i < changes.Count; i += 10)
{
var count = Math.Min(10, changes.Count - i);
var files = new List<string>();
for (int j = 0; j < count; j++)
files.Add(changes[i + j].Path);
new Restore(repo, files, "--staged --worktree --recurse-submodules").Exec();
}
}
}
}