git-codereview: fix hooks install when using 'git worktree'

Use 'git rev-parse' to obtain the repo root (toplevel) and the hooks
directory (git-path hooks).

Git knows better how to handle more complex scenarios, e.g. in a
linked worktree (created using "git worktree add"), ".git" is not
a directory but a regular file, that contains the path to the linked
gitdir, that then contains the path to the main gitdir. The hooks
should be there.

For older version git versions without --git-path (and without
worktree), fallback to the previous approach.

Updates golang/go#12182.

Change-Id: I7a90362409fc5000282db95c4ec2ab5052ae59a8
Reviewed-on: https://go-review.googlesource.com/19882
Run-TryBot: Andrew Gerrand <adg@golang.org>
Reviewed-by: Andrew Gerrand <adg@golang.org>
2 files changed