checkout-index -h: show usage even in an invalid repository
checkout-index loads the index before parsing options. Erroring out is counterproductive at that point if the operator is hunting for a command to recover useful data from the broken repository. [jn: new commit message, tests] Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Oct 22, 2010 at 01:44 UTC
cf9d52e4899219523359ad1542605395c8c86337
2 files changed
+27
builtin/checkout-index.c
+3
@@ -241,6 +241,9 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
241
OPT_END()
242
};
243
244
+ if (argc == 2 && !strcmp(argv[1], "-h"))
245
+ usage_with_options(builtin_checkout_index_usage,
246
+ builtin_checkout_index_options);
247
git_config(git_default_config, NULL);
248
state.base_dir = "";
249
prefix_length = prefix ? strlen(prefix) : 0;
t/t2006-checkout-index-basic.sh
new
+24
@@ -0,0 +1,24 @@
1
+#!/bin/sh
2
+
3
+test_description='basic checkout-index tests
4
+'
5
+
6
+. ./test-lib.sh
7
+
8
+test_expect_success 'checkout-index --gobbledegook' '
9
+ test_expect_code 129 git checkout-index --gobbledegook 2>err &&
10
+ grep "[Uu]sage" err
11
+'
12
+
13
+test_expect_success 'checkout-index -h in broken repository' '
14
+ mkdir broken &&
15
+ (
16
+ cd broken &&
17
+ git init &&
18
+ >.git/index &&
19
+ test_expect_code 129 git checkout-index -h >usage 2>&1
20
+ ) &&
21
+ grep "[Uu]sage" broken/usage
22
+'
23
+
24
+test_done