Propper dependency on .git/HEAD and .git/refs/heads/the_current_branch to regenerate Version.ml. Will not update correctly if a git worktree or its main .git are moved, in these cases use dune clean.

This commit is contained in:
Your Name 2019-03-01 18:49:25 +01:00
parent 15d5f2485d
commit bbd590bc49
2 changed files with 18 additions and 2 deletions

View File

@ -1 +0,0 @@
.git/HEAD

19
dune
View File

@ -40,10 +40,27 @@
(mode promote-until-clean)
)
(rule
(targets .git_main_dir)
(deps)
(action (run "sh" "-c" "if test -d ../../.git; then printf %s '../../.git' > .git_main_dir; else cat ../../.git | sed -e 's/^gitdir: //' | sed -e 's|$|/../..|' > .git_main_dir; fi")))
(rule
(targets .git_worktree_dir)
(deps)
(action (run "sh" "-c" "if test -d ../../.git; then printf %s '../../.git' > .git_worktree_dir; else cat ../../.git | sed -e 's/^gitdir: //' > .git_worktree_dir; fi")))
(rule
(targets .gitHEAD)
(deps .git_main_dir .git_worktree_dir)
;; TODO: re-compute .git_main_dir, just in case (since it does not have a dependency on .git)
(action (run "sh" "-c" "ln -s \"$(cat .git_worktree_dir)/HEAD\" .gitHEAD")))
(rule
(targets Version.gitHEAD)
(deps .gitHEAD)
(action (run "sh" "-c" "if git symbolic-ref HEAD; then ln -s ../../.git/\"$(git symbolic-ref HEAD)\" Version.gitHEAD; else ln -s hd Version.gitHEAD; fi"))
;; TODO: re-compute .git_main_dir, just in case (since it does not have a dependency on .git)
(action (run "sh" "-c" "if git symbolic-ref HEAD >/dev/null 2>&1; then ln -s \"$(cat .git_main_dir)/$(git symbolic-ref HEAD)\" Version.gitHEAD; else ln -s \"$(cat .git_worktree_dir)/HEAD\" Version.gitHEAD; fi"))
)
(rule