Skip to content

Integrate approved task patches with a safe three-way merge #67

Description

@RomanEmreis

Problem

Ferrus currently integrates an approved task with:

git apply --whitespace=nowarn PATCH.diff

Parallel tasks are built from pinned baseline trees. After one task changes a shared file, another task can fail with integration_error even when Git could merge its changes cleanly against the updated canonical workspace.

A literal switch to git apply --3way is not sufficient because it may update the Git index and may leave conflict stages or conflict markers. The current rollback path, git apply -R PATCH.diff, also cannot reliably restore the pre-integration workspace after a three-way merge.

Goal

Integrate approved task changes with a safe three-way workflow using:

  • base: the task baseline tree
  • ours: the exact current canonical workspace state
  • theirs: the frozen submitted tree

Non-overlapping changes to the same file should merge automatically. Genuine conflicts should remain recoverable integration errors.

Requirements

  • Preserve pre-existing canonical staged, unstaged, and untracked changes.
  • Run three-way integration through an isolated worktree or temporary Git index.
  • Do not leave conflict markers or unmerged index entries after failure.
  • Restore the exact pre-attempt canonical state when integration fails.
  • Restore the exact pre-attempt canonical state when post-apply checks fail.
  • Keep the existing approval lock and source identity validation semantics.
  • Continue writing a bounded INTEGRATION_ERROR.md for genuine conflicts.

Tests

  • Two tasks changing different hunks of the same tracked file merge successfully.
  • Overlapping changes produce integration_error.
  • A failed merge leaves the canonical worktree and index unchanged.
  • Failed post-apply checks restore the exact canonical state after a successful three-way merge.
  • Existing staged, unstaged, untracked, binary, added, and deleted paths remain correct.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingworkflow

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions