@matheusbsbs / matheus-bagliano / commits / 0c8151b6ff
Fork 0

gc -h: show usage even with broken configuration

Given a request for command-line usage information rather than some more substantial action, the only friendly thing to do is to report the usage information as soon as possible and exit. Without this change, as "git gc" glances over the repository, it can be distracted by the desire to report a malformed configuration file. Noticed while working through reports from Duy's repository access checker. [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:47 UTC 0c8151b6ff5b79e6638e4f8339d62b051998dc2f
2 files changed +31
builtin/gc.c
+3
@@ -189,6 +189,9 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
189 OPT_END()
190 };
191
192 + if (argc == 2 && !strcmp(argv[1], "-h"))
193 + usage_with_options(builtin_gc_usage, builtin_gc_options);
194 +
195 git_config(gc_config, NULL);
196
197 if (pack_refs < 0)
t/t6500-gc.sh new
+28
@@ -0,0 +1,28 @@
1 +#!/bin/sh
2 +
3 +test_description='basic git gc tests
4 +'
5 +
6 +. ./test-lib.sh
7 +
8 +test_expect_success 'gc empty repository' '
9 + git gc
10 +'
11 +
12 +test_expect_success 'gc --gobbledegook' '
13 + test_expect_code 129 git gc --nonsense 2>err &&
14 + grep "[Uu]sage: git gc" err
15 +'
16 +
17 +test_expect_success 'gc -h with invalid configuration' '
18 + mkdir broken &&
19 + (
20 + cd broken &&
21 + git init &&
22 + echo "[gc] pruneexpire = CORRUPT" >>.git/config &&
23 + test_expect_code 129 git gc -h >usage 2>&1
24 + ) &&
25 + grep "[Uu]sage" broken/usage
26 +'
27 +
28 +test_done