Merge branch 'mr/merge-file-object-id-worktree-fix'

merge-file --object-id used to trigger a BUG when run in a linked
worktree, which has been fixed.

* mr/merge-file-object-id-worktree-fix:
  merge-file: fix BUG when --object-id is used in a worktree
This commit is contained in:
Junio C Hamano
2026-03-27 11:00:01 -07:00
2 changed files with 11 additions and 1 deletions

View File

@@ -108,7 +108,8 @@ int cmd_merge_file(int argc,
return error_errno("failed to redirect stderr to /dev/null");
}
if (object_id)
if (!repo && object_id)
/* emit the correct "not a git repo" error in this case */
setup_git_directory();
for (i = 0; i < 3; i++) {

View File

@@ -542,6 +542,15 @@ test_expect_success '--object-id fails without repository' '
grep "not a git repository" err
'
test_expect_success 'run in a linked worktree with --object-id' '
empty="$(test_oid empty_blob)" &&
git worktree add work &&
git -C work merge-file --object-id $empty $empty $empty >actual &&
git worktree remove work &&
git merge-file --object-id $empty $empty $empty >expected &&
test_cmp actual expected
'
test_expect_success 'merging C files with "myers" diff algorithm creates some spurious conflicts' '
cat >expect.c <<-\EOF &&
int g(size_t u)