Skip to content

fix(agents): make git-commit-patch work on a Git whose merge-tree rejects trees #79

Description

@AbysmalBiscuit

git-commit-patch.py merges the selected tree against the staged tree directly:

git.run("merge-tree", "--write-tree", f"--merge-base={base_tree}", selected_tree, prior_tree)

Git only learned to accept tree arguments there at some point after 2.43. On 2.43 the merge fails and the whole patch commit is refused:

git-commit-patch: patch overlaps staged changes; HEAD and the shared index are unchanged
error: 9f8ae23686f67ca9c0711b7c784e8162c4218a3f: expected commit type, but the object dereferences to tree type
merge-tree: 9f8ae23686f67ca9c0711b7c784e8162c4218a3f - not something we can merge

The reported message is wrong twice over. There is no overlap; the merge never ran. And the advice it implies, that the user should unstage something, does not help.

Reproduced on git 2.43.0 with the empty tree, so it is the argument type and nothing about the patch:

$ E=4b825dc642cb6eb9a060e54bf8d69288fbee4904
$ git merge-tree --write-tree --merge-base=$E $E $E
error: 4b825dc642cb6eb9a060e54bf8d69288fbee4904: expected commit type, but the object dereferences to tree type

Ubuntu 24.04 ships git 2.43, so every cloud VM and container on that base loses devrun task commit-patch entirely. devrun task commit is unaffected: it does not merge trees.

Suggested fix

Wrap each tree in a throwaway commit with git commit-tree and merge the commits, which every Git carrying --write-tree (2.38 and later) accepts. The commits are unreferenced and cost a gc nothing. It is a change to three arguments, not to the index, hook, or recovery machinery around them.

Failing that, detect the condition and say so, rather than reporting an overlap that did not happen.

Acceptance criteria

  • devrun task commit-patch commits a patch and preserves unrelated staging on git 2.43.
  • test_devkit_commits_patch_and_preserves_unrelated_staging runs rather than skips on git 2.43.
  • A merge that genuinely conflicts still reports an overlap, and one that cannot run reports its own cause.

Notes

#77 added a capability probe that skips that test where merge-tree will not take trees, so the suite is green on an old Git instead of failing with a misleading message. Remove the probe and the skip when this is fixed.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:cloudCloud agent setup and executionarea:tasksdevrun tasks and templatesbugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions