Skip to content

build: Support building inside of a git worktree

Summary

The current build does not support building inside of a git-worktree because in a worktree .git is just a file pointing to the actual git directory inside the parent repository.

To fix this we use git rev-parse --absolute-git-dir to locate the git directory instead. This flag is in rev-parse since git version 2.13 so we provide a fallback path for previous git versions.

Test plan

  • git worktree add ../testworkdir
  • cd ../testworkdir ; mkdir build ; cd build
  • cmake -GNinja ..
  • grep logs/HEAD build.ninja # Confirm the correct HEAD is used
  • ninja all check-all
Edited by Calin Culianu

Merge request reports