diff --git a/builtin/merge-file.c b/builtin/merge-file.c index 084fdfec58..59a9792208 100644 --- a/builtin/merge-file.c +++ b/builtin/merge-file.c @@ -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++) { diff --git a/t/t6403-merge-file.sh b/t/t6403-merge-file.sh index 4d6e748320..801284cf8f 100755 --- a/t/t6403-merge-file.sh +++ b/t/t6403-merge-file.sh @@ -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)