[gitutil] Fix compatibility with git<2.31.0

The --path-format flag was only added to git in version 2.31.0 (released
in 2021). Many open-source contributors in particular are on older
versions of git and it's a bad experience to require a super up-to-date
Git in order to check out Fuchsia when it's easy enough to fix the
backwards compatibility.

Bug: 323233422
Change-Id: I430cc686c5368812a2cd2cbcb8e68288b799f969
Reviewed-on: https://fuchsia-review.googlesource.com/c/jiri/+/984153
Commit-Queue: Oliver Newman <olivernewman@google.com>
Reviewed-by: Drew Fisher <zarvox@google.com>
diff --git a/gitutil/git.go b/gitutil/git.go
index 93b698a..4b749df 100644
--- a/gitutil/git.go
+++ b/gitutil/git.go
@@ -754,14 +754,21 @@
 // CurrentGitHooksPath returns the gitHooks directory of a project.
 // Submodules gitHooks are under //.git/modules under superproject.
 func (g *Git) CurrentGitHooksPath() (string, error) {
-	out, err := g.runOutput("rev-parse", "--path-format=absolute", "--git-path", "hooks")
+	out, err := g.runOutput("rev-parse", "--git-path", "hooks")
 	if err != nil {
 		return "", err
 	}
 	if len(out) != 1 {
 		return "", fmt.Errorf("unexpected length of %v: got %v, want 1", out, len(out))
 	}
-	return out[0], nil
+	hooksPath := out[0]
+	// rev-parse will return an absolute path if the hooks directory and the cwd
+	// don't share a prefix. Only newer versions of git (2.31.0 and later)
+	// support the `--path-format=absolute` flag to `git rev-parse`.
+	if filepath.IsAbs(hooksPath) {
+		return hooksPath, nil
+	}
+	return filepath.Join(g.rootDir, hooksPath), nil
 }
 
 // CurrentRevision returns the current revision.