Skip to content

merge-ours: sparse-index integration#2041

Closed
sambostock wants to merge 2 commits intogitgitgadget:masterfrom
sambostock:sb/merge-ours-sparse-index
Closed

merge-ours: sparse-index integration#2041
sambostock wants to merge 2 commits intogitgitgadget:masterfrom
sambostock:sb/merge-ours-sparse-index

Conversation

@sambostock
Copy link

@sambostock sambostock commented Feb 6, 2026

This short series teaches merge-ours to work with a sparse index.

Patch 1 is a preparatory cleanup that converts merge-ours away from
the_repository global, using the repo parameter instead.

Patch 2 adds the actual sparse-index integration and tests. Because
merge-ours is invoked as a subprocess by git merge -s ours and never
previously read config, the sparse-checkout globals remained unset,
causing the index to be expanded unconditionally. A repo_config() call
fixes this.

Developed with AI assistance (Claude).

Use the `repo` parameter passed to cmd_merge_ours() instead of
`the_repository`, and drop the USE_THE_REPOSITORY_VARIABLE macro that
is no longer needed.

While at it, remove a stray double blank line between the #include
block and the usage string.

Signed-off-by: Sam Bostock <sam@sambostock.ca>
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@sambostock.ca>
@sambostock sambostock force-pushed the sb/merge-ours-sparse-index branch from b501c03 to 20b9e0b Compare February 6, 2026 00:38
@sambostock
Copy link
Author

Opened against wrong repo. Re-opening against git/git.

@sambostock sambostock closed this Feb 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant