Skip to content
  • Gábor Szeder's avatar
    blame: default to HEAD in a bare repo when no start commit is given · a544fb08
    Gábor Szeder authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    When 'git blame' is invoked without specifying the commit to start
    blaming from, it starts from the given file's state in the work tree.
    However, when invoked in a bare repository without a start commit,
    then there is no work tree state to start from, and it dies with the
    following error message:
    
      $ git rev-parse --is-bare-repository
      true
      $ git blame file.c
      fatal: this operation must be run in a work tree
    
    This is misleading, because it implies that 'git blame' doesn't work
    in bare repositories at all, but it does, in fact, work just fine when
    it is given a commit to start from.
    
    We could improve the error message, of course, but let's just default
    to HEAD in a bare repository instead, as most likely that is what the
    user wanted anyway (if they wanted to start from an other commit, then
    they would have specified that in the first place).
    
    'git annotate' is just a thin wrapper around 'git blame', so in the
    same situation it printed the same misleading error message, and this
    patch fixes it, too.
    
    Signed-off-by: default avatarSZEDER Gábor <szeder.dev@gmail.com>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    a544fb08