Skip to content

Commit b501c03

Browse files
committed
merge-ours: integrate with sparse-index
The merge-ours builtin reads the index only to compare it against HEAD via index_differs_from(), whose diff machinery (run_diff_index) is already sparse-aware. Teach merge-ours to opt out of requiring a full index by setting command_requires_full_index to 0. Because merge-ours is invoked as a subprocess by "git merge -s ours" and never previously read config, the global variables core_apply_sparse_checkout and core_sparse_checkout_cone remained unset, causing is_sparse_index_allowed() to return false and the index to be expanded anyway. Add a repo_config() call with git_default_config to populate these globals. Add tests to t1092 verifying that "git merge -s ours" produces identical results across full-checkout, sparse-checkout, and sparse-index modes, including verifying the resulting merge commit structure, and that the sparse index is not expanded during the operation. Signed-off-by: Sam Bostock <sam@bostock.ca>
1 parent 7265a8f commit b501c03

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

builtin/merge-ours.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
#include "git-compat-util.h"
1212
#include "builtin.h"
13+
#include "config.h"
14+
#include "environment.h"
1315
#include "diff.h"
1416

1517
static const char builtin_merge_ours_usage[] =
@@ -22,6 +24,10 @@ int cmd_merge_ours(int argc,
2224
{
2325
show_usage_if_asked(argc, argv, builtin_merge_ours_usage);
2426

27+
repo_config(repo, git_default_config, NULL);
28+
prepare_repo_settings(repo);
29+
repo->settings.command_requires_full_index = 0;
30+
2531
/*
2632
* The contents of the current index becomes the tree we
2733
* commit. The index must match HEAD, or this merge cannot go

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2559,4 +2559,18 @@ test_expect_success 'cat-file --batch' '
25592559
ensure_expanded cat-file --batch <in
25602560
'
25612561

2562+
test_expect_success 'merge -s ours' '
2563+
init_repos &&
2564+
2565+
test_all_match git rev-parse HEAD^{tree} &&
2566+
test_all_match git merge -s ours merge-right &&
2567+
test_all_match git rev-parse HEAD^{tree} &&
2568+
test_all_match git rev-parse HEAD^2
2569+
'
2570+
2571+
test_expect_success 'sparse-index is not expanded: merge-ours' '
2572+
init_repos &&
2573+
ensure_not_expanded merge -s ours merge-right
2574+
'
2575+
25622576
test_done

0 commit comments

Comments
 (0)