1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//! Which git paths the build script asks Cargo to watch, so that `ANT_GIT_COMMIT`
//! is refreshed whenever `HEAD` resolves to a different commit.
//!
//! Shared by `build.rs` and its regression test (`tests/build_script_git_watch.rs`)
//! through `#[path]`, because a build script can't have tests of its own.
use ;
/// The paths to pass to `cargo:rerun-if-changed`, given the per-worktree git
/// dir (`git rev-parse --git-dir`) and the common dir that all worktrees share
/// (`git rev-parse --git-common-dir`). In a plain clone both are `.git`.
///
/// Every returned path exists. Cargo treats a `rerun-if-changed` path that does
/// not exist as changed on every build, which reruns the build script and
/// recompiles the whole crate each time; hard-coded `.git/...` paths hit that
/// in a git worktree (where `.git` is a file) and in CI checkouts.
///
/// What is watched, and why:
/// * `HEAD` in the git dir. It changes on checkout or branch switch, and on
/// every commit when `HEAD` is detached.
/// * `refs/heads` in the common dir, which Cargo scans recursively. A commit on
/// a branch rewrites the loose ref file `refs/heads/<branch>`. When every ref
/// is packed the directory can be absent, and the next commit then *creates*
/// `refs/heads/<branch>` without touching `HEAD` or `packed-refs`. So when
/// `refs/heads` is missing, its nearest existing ancestor inside the common
/// dir (normally `refs`) is watched instead, which sees that file appear.
/// * `packed-refs` in the common dir, when present. It changes when refs are
/// packed or a packed ref is updated in place.