Skip to content

Commit

Permalink
Reset conflicted files (#10854)
Browse files Browse the repository at this point in the history
  • Loading branch information
gerhardol committed Apr 11, 2023
1 parent bf2b22e commit e68c983
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
13 changes: 13 additions & 0 deletions GitUI/CommandsDialogs/FormCommit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2129,6 +2129,7 @@ private void ResetFilesClick(object sender, EventArgs e)
bool deleteNewFiles = _currentFilesList.SelectedItems.Any(item => DeletableItem(item)) && (resetType == FormResetChanges.ActionEnum.ResetAndDelete);
List<string> filesInUse = new();
List<string> filesToReset = new();
List<string> conflictsToReset = new();
StringBuilder output = new();
foreach (var item in _currentFilesList.SelectedItems)
{
Expand Down Expand Up @@ -2162,13 +2163,25 @@ private void ResetFilesClick(object sender, EventArgs e)
{
filesToReset.Add(item.Item.OldName);
}
else if (item.Item.IsConflict)
{
conflictsToReset.Add(item.Item.Name);
}
else if (!item.Item.IsNew)
{
filesToReset.Add(item.Item.Name);
}
}

output.Append(Module.ResetFiles(filesToReset));
if (conflictsToReset.Count > 0)
{
// Special handling for conflicted files, shown in worktree (with the raw diff).
// Must be reset to HEAD as Index is just a status marker.
ObjectId headId = Module.RevParse("HEAD");
Module.CheckoutFiles(conflictsToReset, headId, force: false);
}

toolStripProgressBar1.Value = toolStripProgressBar1.Maximum;
toolStripProgressBar1.Visible = false;

Expand Down
10 changes: 9 additions & 1 deletion GitUI/CommandsDialogs/RevisionDiffControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -536,10 +536,18 @@ private void ResetSelectedItemsTo(bool actsAsChild, bool deleteUncommittedAddedI
foreach (ObjectId parentId in selectedItems.FirstIds())
{
List<string> itemsToCheckout = selectedItems
.Where(item => !item.Item.IsNew && item.FirstRevision?.ObjectId == parentId)
.Where(item => !item.Item.IsNew && !(item.Item.IsConflict && parentId == ObjectId.IndexId) && item.FirstRevision?.ObjectId == parentId)
.Select(item => RenamedIndexItem(item) ? item.Item.OldName : item.Item.Name)
.ToList();
Module.CheckoutFiles(itemsToCheckout, parentId, force: false);

// Special handling for conflicted files, shown in worktree (with the raw diff).
// Must be reset to HEAD as Index is just a status marker.
List<string> conflictsToCheckout = selectedItems
.Where(item => item.Item.IsConflict && parentId == ObjectId.IndexId)
.Select(item => RenamedIndexItem(item) ? item.Item.OldName : item.Item.Name)
.ToList();
Module.CheckoutFiles(conflictsToCheckout, _revisionGrid.CurrentCheckout, force: false);
}
}
}
Expand Down

0 comments on commit e68c983

Please sign in to comment.