Commit d8620d3c authored by Junio C Hamano's avatar Junio C Hamano

Merge branch 'sg/blame-in-bare-start-at-head'

"git blame -- path" in a non-bare repository starts blaming from
the working tree, and the same command in a bare repository errors
out because there is no working tree by definition.  The command
has been taught to instead start blaming from the commit at HEAD,
which is more useful.

* sg/blame-in-bare-start-at-head:
  blame: default to HEAD in a bare repo when no start commit is given
parents 503f5809 a544fb08
......@@ -27,6 +27,7 @@
#include "object-store.h"
#include "blame.h"
#include "string-list.h"
#include "refs.h"
static char blame_usage[] = N_("git blame [<options>] [<rev-opts>] [<rev>] [--] <file>");
......@@ -993,6 +994,18 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
revs.disable_stdin = 1;
setup_revisions(argc, argv, &revs, NULL);
if (! && is_bare_repository()) {
struct commit *head_commit;
struct object_id head_oid;
if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING,
&head_oid, NULL) ||
!(head_commit = lookup_commit_reference_gently(revs.repo,
&head_oid, 1)))
die("no such ref: HEAD");
add_pending_object(&revs, &head_commit->object, "HEAD");
sb.revs = &revs;
......@@ -68,6 +68,14 @@ test_expect_success 'blame 1 author' '
check_count A 2
test_expect_success 'blame in a bare repo without starting commit' '
git clone --bare . bare.git &&
cd bare.git &&
check_count A 2
test_expect_success 'blame by tag objects' '
git tag -m "test tag" testTag &&
git tag -m "test tag #2" testTag2 testTag &&
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment