reflog [show]: display sensible -h output
Change the "git reflog show -h" output to show the usage summary relevant to it, rather than displaying the same output that "git log -h" would show. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committed
Mar 17, 2022 at 19:08 UTC
fbc15b13f7380ee7b52fdcb467c3438c569fd5de
2 files changed
+28
-2
builtin/reflog.c
+23
-2
@@ -5,6 +5,9 @@
5
#include "worktree.h"
6
#include "reflog.h"
7
8
+#define BUILTIN_REFLOG_SHOW_USAGE \
9
+ N_("git reflog [show] [<log-options>] [<ref>]")
10
+
11
#define BUILTIN_REFLOG_EXPIRE_USAGE \
12
N_("git reflog expire [--expire=<time>] [--expire-unreachable=<time>]\n" \
13
" [--rewrite] [--updateref] [--stale-fix]\n" \
@@ -17,6 +20,11 @@
20
#define BUILTIN_REFLOG_EXISTS_USAGE \
21
N_("git reflog exists <ref>")
22
23
+static const char *const reflog_show_usage[] = {
24
+ BUILTIN_REFLOG_SHOW_USAGE,
25
+ NULL,
26
+};
27
+
28
static const char *const reflog_expire_usage[] = {
29
BUILTIN_REFLOG_EXPIRE_USAGE,
30
NULL
@@ -33,7 +41,7 @@ static const char *const reflog_exists_usage[] = {
41
};
42
43
static const char *const reflog_usage[] = {
36
- N_("git reflog [show] [<log-options>] [<ref>]"),
44
+ BUILTIN_REFLOG_SHOW_USAGE,
45
BUILTIN_REFLOG_EXPIRE_USAGE,
46
BUILTIN_REFLOG_DELETE_USAGE,
47
BUILTIN_REFLOG_EXISTS_USAGE,
@@ -207,6 +215,19 @@ static int expire_total_callback(const struct option *opt,
215
return 0;
216
}
217
218
+static int cmd_reflog_show(int argc, const char **argv, const char *prefix)
219
+{
220
+ struct option options[] = {
221
+ OPT_END()
222
+ };
223
+
224
+ parse_options(argc, argv, prefix, options, reflog_show_usage,
225
+ PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_ARGV0 |
226
+ PARSE_OPT_KEEP_UNKNOWN);
227
+
228
+ return cmd_log_reflog(argc - 1, argv + 1, prefix);
229
+}
230
+
231
static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
232
{
233
struct cmd_reflog_expire_cb cmd = { 0 };
@@ -404,7 +425,7 @@ int cmd_reflog(int argc, const char **argv, const char *prefix)
425
goto log_reflog;
426
427
if (!strcmp(argv[1], "show"))
407
- return cmd_log_reflog(argc - 1, argv + 1, prefix);
428
+ return cmd_reflog_show(argc, argv, prefix);
429
else if (!strcmp(argv[1], "expire"))
430
return cmd_reflog_expire(argc - 1, argv + 1, prefix);
431
else if (!strcmp(argv[1], "delete"))
t/t1410-reflog.sh
+5
@@ -111,6 +111,11 @@ test_expect_success 'correct usage on sub-command -h' '
111
grep "git reflog expire" err
112
'
113
114
+test_expect_success 'correct usage on "git reflog show -h"' '
115
+ test_expect_code 129 git reflog show -h >err &&
116
+ grep -F "git reflog [show]" err
117
+'
118
+
119
test_expect_success 'pass through -- to sub-command' '
120
test_when_finished "rm -rf repo" &&
121
git init repo &&