From bbd590bc4996425913c7c41b87f0134528971b8d Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 1 Mar 2019 18:49:25 +0100 Subject: [PATCH] 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. --- .gitHEAD | 1 - dune | 19 ++++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) delete mode 120000 .gitHEAD diff --git a/.gitHEAD b/.gitHEAD deleted file mode 120000 index 85273d468..000000000 --- a/.gitHEAD +++ /dev/null @@ -1 +0,0 @@ -.git/HEAD \ No newline at end of file diff --git a/dune b/dune index 8afa14ac1..c43133f81 100644 --- a/dune +++ b/dune @@ -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