@matheusbsbs / matheus-bagliano / commits / 8fcaca3ff2
Fork 0

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 <cxreg@pobox.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Dave Olszewski committed Mar 13, 2010 at 14:47 UTC 8fcaca3ff29a193f50a44bb3d5734a503e0539a6
2 files changed +13 -2
revision.c
+4 -2
@@ -1334,7 +1334,7 @@ static void append_prune_data(const char ***prune_data, const char **av)
1334 */
1335 int setup_revisions(int argc, const char **argv, struct rev_info *revs, const char *def)
1336 {
1337 - int i, flags, left, seen_dashdash, read_from_stdin;
1337 + int i, flags, left, seen_dashdash, read_from_stdin, got_rev_arg = 0;
1338 const char **prune_data = NULL;
1339
1340 /* First, search for "--" */
@@ -1460,6 +1460,8 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
1460 append_prune_data(&prune_data, argv + i);
1461 break;
1462 }
1463 + else
1464 + got_rev_arg = 1;
1465 }
1466
1467 if (prune_data)
@@ -1469,7 +1471,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
1471 revs->def = def;
1472 if (revs->show_merge)
1473 prepare_show_merge(revs);
1472 - if (revs->def && !revs->pending.nr) {
1474 + if (revs->def && !revs->pending.nr && !got_rev_arg) {
1475 unsigned char sha1[20];
1476 struct object *object;
1477 unsigned mode;
t/t1411-reflog-show.sh
+9
@@ -64,4 +64,13 @@ test_expect_success 'using --date= shows reflog date (oneline)' '
64 test_cmp expect actual
65 '
66
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 +
76 test_done