gnustavo / Git-Hooks

Framework for implementing Git (and Gerrit) hooks
http://search.cpan.org/dist/Git-Hooks/
41 stars 17 forks source link

Remove error when repo has no commits #74

Closed mikkoi closed 2 years ago

mikkoi commented 2 years ago

When executing git rev-parse --verify HEAD in a repo which has no commits, it prints error to STDERR:

fatal: Needed a single revision

This happens in method Git::Repository::Plugin::GitHooks::get_head_or_empty_tree().

We can avoid this error by first checking if there is commits in the repo. The method Git::Repository::Plugin::GitHooks::has_any_commits() does this.

Signed-off-by: Mikko Johannes Koivunalho mikko.koivunalho@iki.fi

gnustavo commented 2 years ago

Hi Mikko. These warnings are really annoying. I noticed that they are produced in other places in the code.

Fortunately, there is a simpler and more general solution to all of them, which I implemented in commit 416f2ed6a.

What do you think?

mikkoi commented 2 years ago

It's better solution than mine because now we only need to run git once. In my solution, in most circumstances, git needs to be run twice.