Merge branch 'sg/blame-in-bare-start-at-head'
authorJunio C Hamano <gitster@pobox.com>
Thu, 25 Apr 2019 07:41:21 +0000 (16:41 +0900)
committerJunio C Hamano <gitster@pobox.com>
Thu, 25 Apr 2019 07:41:21 +0000 (16:41 +0900)
"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

1  2 
builtin/blame.c
diff --combined builtin/blame.c
index 177c1022a0c46dbd8983224719d4d9cc0106a9fb,8f66eb478606ce468244cd195507bd4c7f2c748f..21cde57e711e337f3c123b35332bb2af0ebdf9cf
@@@ -27,6 -27,7 +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>");
  
@@@ -814,7 -815,7 +815,7 @@@ int cmd_blame(int argc, const char **ar
                 * and are only included here to get included in the "-h"
                 * output:
                 */
 -              { OPTION_LOWLEVEL_CALLBACK, 0, "indent-heuristic", NULL, NULL, N_("Use an experimental heuristic to improve diffs"), PARSE_OPT_NOARG, parse_opt_unknown_cb },
 +              { OPTION_LOWLEVEL_CALLBACK, 0, "indent-heuristic", NULL, NULL, N_("Use an experimental heuristic to improve diffs"), PARSE_OPT_NOARG, NULL, 0, parse_opt_unknown_cb },
  
                OPT_BIT(0, "minimal", &xdl_opts, N_("Spend extra cycles to find better match"), XDF_NEED_MINIMAL),
                OPT_STRING('S', NULL, &revs_file, N_("file"), N_("Use revisions from <file> instead of calling git-rev-list")),
@@@ -993,6 -994,18 +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;