commit/status -h: show usage even with broken configuration
"git status" and "git commit" read .git/config and .gitmodules before parsing options, but there is no reason to access a repository at all when the caller just wanted to know what arguments are accepted. [jn: rewrote the log message and added test] 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:45 UTC
5d3dd915e64ea42ba6bf7646937784f6ddc71422
2 files changed
+30
builtin/commit.c
+6
@@ -1070,6 +1070,9 @@ int cmd_status(int argc, const char **argv, const char *prefix)
1070
OPT_END(),
1071
};
1072
1073
+ if (argc == 2 && !strcmp(argv[1], "-h"))
1074
+ usage_with_options(builtin_status_usage, builtin_status_options);
1075
+
1076
if (null_termination && status_format == STATUS_FORMAT_LONG)
1077
status_format = STATUS_FORMAT_PORCELAIN;
1078
@@ -1255,6 +1258,9 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1258
int allow_fast_forward = 1;
1259
struct wt_status s;
1260
1261
+ if (argc == 2 && !strcmp(argv[1], "-h"))
1262
+ usage_with_options(builtin_commit_usage, builtin_commit_options);
1263
+
1264
wt_status_prepare(&s);
1265
git_config(git_commit_config, &s);
1266
in_merge = file_exists(git_path("MERGE_HEAD"));
t/t7508-status.sh
+24
@@ -7,6 +7,30 @@ test_description='git status'
7
8
. ./test-lib.sh
9
10
+test_expect_success 'status -h in broken repository' '
11
+ mkdir broken &&
12
+ test_when_finished "rm -fr broken" &&
13
+ (
14
+ cd broken &&
15
+ git init &&
16
+ echo "[status] showuntrackedfiles = CORRUPT" >>.git/config &&
17
+ test_expect_code 129 git status -h >usage 2>&1
18
+ ) &&
19
+ grep "[Uu]sage" broken/usage
20
+'
21
+
22
+test_expect_success 'commit -h in broken repository' '
23
+ mkdir broken &&
24
+ test_when_finished "rm -fr broken" &&
25
+ (
26
+ cd broken &&
27
+ git init &&
28
+ echo "[status] showuntrackedfiles = CORRUPT" >>.git/config &&
29
+ test_expect_code 129 git commit -h >usage 2>&1
30
+ ) &&
31
+ grep "[Uu]sage" broken/usage
32
+'
33
+
34
test_expect_success 'setup' '
35
: >tracked &&
36
: >modified &&