merge -h: show usage even with corrupt index
Part of a campaign to make sure "git <command> -h" works correctly when run from distractingly bad repositories. [jn: with rewritten log message and 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:49 UTC
da53eec68873e76c68086e405f3f1329d47055b3
2 files changed
+13
builtin/merge.c
+2
@@ -909,6 +909,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
909
const char *best_strategy = NULL, *wt_strategy = NULL;
910
struct commit_list **remotes = &remoteheads;
911
912
+ if (argc == 2 && !strcmp(argv[1], "-h"))
913
+ usage_with_options(builtin_merge_usage, builtin_merge_options);
914
if (read_cache_unmerged()) {
915
die_resolve_conflict("merge");
916
}
t/t7600-merge.sh
+11
@@ -144,6 +144,17 @@ test_expect_success 'test option parsing' '
144
test_must_fail git merge
145
'
146
147
+test_expect_success 'merge -h with invalid index' '
148
+ mkdir broken &&
149
+ (
150
+ cd broken &&
151
+ git init &&
152
+ >.git/index &&
153
+ test_expect_code 129 git merge -h 2>usage
154
+ ) &&
155
+ grep "[Uu]sage: git merge" broken/usage
156
+'
157
+
158
test_expect_success 'reject non-strategy with a git-merge-foo name' '
159
test_must_fail git merge -s index c1
160
'