Skip to content

Commit 8fcaca3

Browse files
cxreggitster
authored andcommitted
don't use default revision if a rev was specified
If a revision is specified, it happens not to have any commits, don't use the default revision. By doing so, surprising and undesired behavior can happen, such as showing the reflog for HEAD when a branch was specified. [jc: squashed a test from René] Signed-off-by: Dave Olszewski <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8ca7880 commit 8fcaca3

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

revision.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,7 @@ static void append_prune_data(const char ***prune_data, const char **av)
13341334
*/
13351335
int setup_revisions(int argc, const char **argv, struct rev_info *revs, const char *def)
13361336
{
1337-
int i, flags, left, seen_dashdash, read_from_stdin;
1337+
int i, flags, left, seen_dashdash, read_from_stdin, got_rev_arg = 0;
13381338
const char **prune_data = NULL;
13391339

13401340
/* First, search for "--" */
@@ -1460,6 +1460,8 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
14601460
append_prune_data(&prune_data, argv + i);
14611461
break;
14621462
}
1463+
else
1464+
got_rev_arg = 1;
14631465
}
14641466

14651467
if (prune_data)
@@ -1469,7 +1471,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
14691471
revs->def = def;
14701472
if (revs->show_merge)
14711473
prepare_show_merge(revs);
1472-
if (revs->def && !revs->pending.nr) {
1474+
if (revs->def && !revs->pending.nr && !got_rev_arg) {
14731475
unsigned char sha1[20];
14741476
struct object *object;
14751477
unsigned mode;

t/t1411-reflog-show.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,13 @@ test_expect_success 'using --date= shows reflog date (oneline)' '
6464
test_cmp expect actual
6565
'
6666

67+
: >expect
68+
test_expect_success 'empty reflog file' '
69+
git branch empty &&
70+
: >.git/logs/refs/heads/empty &&
71+
72+
git log -g empty >actual &&
73+
test_cmp expect actual
74+
'
75+
6776
test_done

0 commit comments

Comments
 (0)