builtin/checkout-index: stop using the_repository

Remove the_repository global variable in favor of the repository
argument that gets passed in "builtin/checkout-index.c".

When `-h` is passed to the command outside a Git repository, the
`run_builtin()` will call the `cmd_checkout_index()` function with `repo`
set to NULL and then early in the function, `show_usage_with_options_if_asked()`
call will give the options help and exit.

Pass an instance of "struct index_state" available in the calling
context to both `checkout_all()` and `checkout_file()` to remove their
dependency on the global `the_repository` variable.

Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Usman Akinyemi
2025-03-08 05:05:07 +05:30
committed by Junio C Hamano
parent d9dce89192
commit 09cbf1597e
2 changed files with 28 additions and 22 deletions

View File

@@ -21,6 +21,13 @@ test_expect_success 'checkout-index -h in broken repository' '
test_grep "[Uu]sage" broken/usage
'
test_expect_success 'checkout-index does not crash with -h' '
test_expect_code 129 git checkout-index -h >usage &&
test_grep "[Uu]sage: git checkout-index " usage &&
test_expect_code 129 nongit git checkout-index -h >usage &&
test_grep "[Uu]sage: git checkout-index " usage
'
test_expect_success 'checkout-index reports errors (cmdline)' '
test_must_fail git checkout-index -- does-not-exist 2>stderr &&
test_grep not.in.the.cache stderr