Skip to content

Commit 632ac9f

Browse files
author
Junio C Hamano
committed
show-branch -g: default to the current branch.
Now we have a separate reflog on HEAD, show-branch -g without an explicit parameter defaults to the current branch, or HEAD when it is detached from branches. Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent dc9195a commit 632ac9f

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

Documentation/git-show-branch.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ SYNOPSIS
1111
'git-show-branch' [--all] [--remotes] [--topo-order] [--current]
1212
[--more=<n> | --list | --independent | --merge-base]
1313
[--no-name | --sha1-name] [--topics] [<rev> | <glob>]...
14-
'git-show-branch' (-g|--reflog)[=<n>[,<base>]] [--list] <ref>
14+
'git-show-branch' (-g|--reflog)[=<n>[,<base>]] [--list] [<ref>]
1515

1616
DESCRIPTION
1717
-----------
@@ -97,11 +97,13 @@ OPTIONS
9797
will show the revisions given by "git rev-list {caret}master
9898
topic1 topic2"
9999

100-
--reflog[=<n>[,<base>]] <ref>::
100+
--reflog[=<n>[,<base>]] [<ref>]::
101101
Shows <n> most recent ref-log entries for the given
102102
ref. If <base> is given, <n> entries going back from
103103
that entry. <base> can be specified as count or date.
104-
`-g` can be used as a short-hand for this option.
104+
`-g` can be used as a short-hand for this option. When
105+
no explicit <ref> parameter is given, it defaults to the
106+
current branch (or `HEAD` if it is detached).
105107

106108
Note that --more, --list, --independent and --merge-base options
107109
are mutually exclusive.

builtin-show-branch.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,10 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
690690

691691
if (ac == 0) {
692692
static const char *fake_av[2];
693-
fake_av[0] = "HEAD";
693+
const char *refname;
694+
695+
refname = resolve_ref("HEAD", sha1, 1, NULL);
696+
fake_av[0] = xstrdup(refname);
694697
fake_av[1] = NULL;
695698
av = fake_av;
696699
ac = 1;

0 commit comments

Comments
 (0)