standard in as a newline-delimited list instead of from the arguments.
'disable'::
- Remove the sparse-checkout file, set `core.sparseCheckout` to
- `false`, and restore the working directory to include all files.
+ Disable the `core.sparseCheckout` config setting, and restore the
+ working directory to include all files. Leaves the sparse-checkout
+ file intact so a later 'git sparse-checkout init' command may
+ return the working directory to the same state.
SPARSE CHECKOUT
---------------
static int sparse_checkout_disable(int argc, const char **argv)
{
- char *sparse_filename;
- FILE *fp;
+ static const char *empty_base = "";
+ struct pattern_list pl;
+ struct strbuf match_all = STRBUF_INIT;
- if (set_config(MODE_ALL_PATTERNS))
- die(_("failed to change config"));
+ memset(&pl, 0, sizeof(pl));
+ hashmap_init(&pl.recursive_hashmap, pl_hashmap_cmp, NULL, 0);
+ hashmap_init(&pl.parent_hashmap, pl_hashmap_cmp, NULL, 0);
+ pl.use_cone_patterns = 0;
+ core_apply_sparse_checkout = 1;
- sparse_filename = get_sparse_checkout_filename();
- fp = xfopen(sparse_filename, "w");
- fprintf(fp, "/*\n");
- fclose(fp);
+ strbuf_addstr(&match_all, "/*");
+ add_pattern(strbuf_detach(&match_all, NULL), empty_base, 0, &pl, 0);
- core_apply_sparse_checkout = 1;
- if (update_working_directory(NULL))
+ if (update_working_directory(&pl))
die(_("error while refreshing working directory"));
- unlink(sparse_filename);
- free(sparse_filename);
-
+ clear_pattern_list(&pl);
return set_config(MODE_NO_PATTERNS);
}
'
test_expect_success 'sparse-checkout disable' '
+ test_when_finished rm -rf repo/.git/info/sparse-checkout &&
git -C repo sparse-checkout disable &&
- test_path_is_missing repo/.git/info/sparse-checkout &&
+ test_path_is_file repo/.git/info/sparse-checkout &&
git -C repo config --list >config &&
test_must_fail git config core.sparseCheckout &&
ls repo >dir &&