mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-21 04:04:59 +00:00
fix: resolve conflict with deleted files does not work (#1009)
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
9da2c787db
commit
2b4fc64c73
3 changed files with 64 additions and 18 deletions
|
@ -12,7 +12,7 @@ namespace SourceGit.Commands
|
|||
Args = includeUntracked ? "add ." : "add -u .";
|
||||
}
|
||||
|
||||
public Add(string repo, List<Models.Change> changes)
|
||||
public Add(string repo, List<string> changes)
|
||||
{
|
||||
WorkingDirectory = repo;
|
||||
Context = repo;
|
||||
|
@ -22,7 +22,7 @@ namespace SourceGit.Commands
|
|||
foreach (var c in changes)
|
||||
{
|
||||
builder.Append(" \"");
|
||||
builder.Append(c.Path);
|
||||
builder.Append(c);
|
||||
builder.Append("\"");
|
||||
}
|
||||
Args = builder.ToString();
|
||||
|
|
|
@ -353,38 +353,80 @@ namespace SourceGit.ViewModels
|
|||
|
||||
public async void UseTheirs(List<Models.Change> changes)
|
||||
{
|
||||
_repo.SetWatcherEnabled(false);
|
||||
|
||||
var files = new List<string>();
|
||||
var needStage = new List<string>();
|
||||
|
||||
foreach (var change in changes)
|
||||
{
|
||||
if (change.IsConflit)
|
||||
if (!change.IsConflit)
|
||||
continue;
|
||||
|
||||
if (change.WorkTree == Models.ChangeState.Deleted)
|
||||
{
|
||||
var fullpath = Path.Combine(_repo.FullPath, change.Path);
|
||||
if (File.Exists(fullpath))
|
||||
File.Delete(fullpath);
|
||||
|
||||
needStage.Add(change.Path);
|
||||
}
|
||||
else
|
||||
{
|
||||
files.Add(change.Path);
|
||||
}
|
||||
}
|
||||
|
||||
_repo.SetWatcherEnabled(false);
|
||||
if (files.Count > 0)
|
||||
{
|
||||
var succ = await Task.Run(() => new Commands.Checkout(_repo.FullPath).UseTheirs(files));
|
||||
if (succ)
|
||||
{
|
||||
await Task.Run(() => new Commands.Add(_repo.FullPath, changes).Exec());
|
||||
needStage.AddRange(files);
|
||||
}
|
||||
|
||||
if (needStage.Count > 0)
|
||||
await Task.Run(() => new Commands.Add(_repo.FullPath, needStage).Exec());
|
||||
|
||||
_repo.MarkWorkingCopyDirtyManually();
|
||||
_repo.SetWatcherEnabled(true);
|
||||
}
|
||||
|
||||
public async void UseMine(List<Models.Change> changes)
|
||||
{
|
||||
_repo.SetWatcherEnabled(false);
|
||||
|
||||
var files = new List<string>();
|
||||
var needStage = new List<string>();
|
||||
|
||||
foreach (var change in changes)
|
||||
{
|
||||
if (change.IsConflit)
|
||||
if (!change.IsConflit)
|
||||
continue;
|
||||
|
||||
if (change.Index == Models.ChangeState.Deleted)
|
||||
{
|
||||
var fullpath = Path.Combine(_repo.FullPath, change.Path);
|
||||
if (File.Exists(fullpath))
|
||||
File.Delete(fullpath);
|
||||
|
||||
needStage.Add(change.Path);
|
||||
}
|
||||
else
|
||||
{
|
||||
files.Add(change.Path);
|
||||
}
|
||||
}
|
||||
|
||||
_repo.SetWatcherEnabled(false);
|
||||
if (files.Count > 0)
|
||||
{
|
||||
var succ = await Task.Run(() => new Commands.Checkout(_repo.FullPath).UseMine(files));
|
||||
if (succ)
|
||||
{
|
||||
await Task.Run(() => new Commands.Add(_repo.FullPath, changes).Exec());
|
||||
needStage.AddRange(files);
|
||||
}
|
||||
|
||||
if (needStage.Count > 0)
|
||||
await Task.Run(() => new Commands.Add(_repo.FullPath, needStage).Exec());
|
||||
|
||||
_repo.MarkWorkingCopyDirtyManually();
|
||||
_repo.SetWatcherEnabled(true);
|
||||
}
|
||||
|
@ -1502,7 +1544,8 @@ namespace SourceGit.ViewModels
|
|||
|
||||
private async void StageChanges(List<Models.Change> changes, Models.Change next)
|
||||
{
|
||||
if (changes.Count == 0)
|
||||
var count = changes.Count;
|
||||
if (count == 0)
|
||||
return;
|
||||
|
||||
// Use `_selectedUnstaged` instead of `SelectedUnstaged` to avoid UI refresh.
|
||||
|
@ -1510,7 +1553,7 @@ namespace SourceGit.ViewModels
|
|||
|
||||
IsStaging = true;
|
||||
_repo.SetWatcherEnabled(false);
|
||||
if (changes.Count == _unstaged.Count)
|
||||
if (count == _unstaged.Count)
|
||||
{
|
||||
await Task.Run(() => new Commands.Add(_repo.FullPath, _repo.IncludeUntracked).Exec());
|
||||
}
|
||||
|
@ -1527,10 +1570,13 @@ namespace SourceGit.ViewModels
|
|||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < changes.Count; i += 10)
|
||||
var paths = new List<string>();
|
||||
foreach (var c in changes)
|
||||
paths.Add(c.Path);
|
||||
|
||||
for (int i = 0; i < count; i += 10)
|
||||
{
|
||||
var count = Math.Min(10, changes.Count - i);
|
||||
var step = changes.GetRange(i, count);
|
||||
var step = paths.GetRange(i, Math.Min(10, count - i));
|
||||
await Task.Run(() => new Commands.Add(_repo.FullPath, step).Exec());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1796,7 +1796,7 @@ namespace SourceGit.Views
|
|||
|
||||
if (!selection.HasLeftChanges)
|
||||
{
|
||||
new Commands.Add(repo.FullPath, [change]).Exec();
|
||||
new Commands.Add(repo.FullPath, [change.Path]).Exec();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue