Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2019-04-25 10:41:21 +0300
committerJunio C Hamano <gitster@pobox.com>2019-04-25 10:41:21 +0300
commitd8620d3ca7a01c1108f3145cc77dbda6e0e970c6 (patch)
tree26c7106af5727b8b0740eea664da5cedcebbb6e5 /builtin/blame.c
parent503f5809e8b32a9f5b0137bf6d1a4cac21818a51 (diff)
parenta544fb08f8bfa3a9a566d436e5e81dd30fb21c4c (diff)
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
Diffstat (limited to 'builtin/blame.c')
-rw-r--r--builtin/blame.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/builtin/blame.c b/builtin/blame.c
index 177c1022a0..21cde57e71 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -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 @@ parse_done:
revs.disable_stdin = 1;
setup_revisions(argc, argv, &revs, NULL);
+ if (!revs.pending.nr && 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");
+ }
init_scoreboard(&sb);
sb.revs = &revs;