Skip to content

Commit fbc15b1

Browse files
avargitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e3c3675 commit fbc15b1

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

builtin/reflog.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
#include "worktree.h"
66
#include "reflog.h"
77

8+
#define BUILTIN_REFLOG_SHOW_USAGE \
9+
N_("git reflog [show] [<log-options>] [<ref>]")
10+
811
#define BUILTIN_REFLOG_EXPIRE_USAGE \
912
N_("git reflog expire [--expire=<time>] [--expire-unreachable=<time>]\n" \
1013
" [--rewrite] [--updateref] [--stale-fix]\n" \
@@ -17,6 +20,11 @@
1720
#define BUILTIN_REFLOG_EXISTS_USAGE \
1821
N_("git reflog exists <ref>")
1922

23+
static const char *const reflog_show_usage[] = {
24+
BUILTIN_REFLOG_SHOW_USAGE,
25+
NULL,
26+
};
27+
2028
static const char *const reflog_expire_usage[] = {
2129
BUILTIN_REFLOG_EXPIRE_USAGE,
2230
NULL
@@ -33,7 +41,7 @@ static const char *const reflog_exists_usage[] = {
3341
};
3442

3543
static const char *const reflog_usage[] = {
36-
N_("git reflog [show] [<log-options>] [<ref>]"),
44+
BUILTIN_REFLOG_SHOW_USAGE,
3745
BUILTIN_REFLOG_EXPIRE_USAGE,
3846
BUILTIN_REFLOG_DELETE_USAGE,
3947
BUILTIN_REFLOG_EXISTS_USAGE,
@@ -207,6 +215,19 @@ static int expire_total_callback(const struct option *opt,
207215
return 0;
208216
}
209217

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+
210231
static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
211232
{
212233
struct cmd_reflog_expire_cb cmd = { 0 };
@@ -404,7 +425,7 @@ int cmd_reflog(int argc, const char **argv, const char *prefix)
404425
goto log_reflog;
405426

406427
if (!strcmp(argv[1], "show"))
407-
return cmd_log_reflog(argc - 1, argv + 1, prefix);
428+
return cmd_reflog_show(argc, argv, prefix);
408429
else if (!strcmp(argv[1], "expire"))
409430
return cmd_reflog_expire(argc - 1, argv + 1, prefix);
410431
else if (!strcmp(argv[1], "delete"))

t/t1410-reflog.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ test_expect_success 'correct usage on sub-command -h' '
111111
grep "git reflog expire" err
112112
'
113113

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+
114119
test_expect_success 'pass through -- to sub-command' '
115120
test_when_finished "rm -rf repo" &&
116121
git init repo &&

0 commit comments

Comments
 (0)