Opt the repository into the optional watch daemon (the shim opt-in itself is recorded by `git shim enable`). The serialized configuration always carries a `[git.shim.watch]` table (the disabled default), so the flip edits that table in place.
(root: &Path)
| 155 | /// configuration always carries a `[git.shim.watch]` table (the |
| 156 | /// disabled default), so the flip edits that table in place. |
| 157 | fn enable_watch(root: &Path) { |
| 158 | let config = root.join(".atomic/config.toml"); |
| 159 | let content = fs::read_to_string(&config).expect("read repo config"); |
| 160 | assert!( |
| 161 | content.contains("[git.shim]"), |
| 162 | "shim enable must have recorded the consent table first" |
| 163 | ); |
| 164 | let mut in_watch = false; |
| 165 | let mut flipped = false; |
| 166 | let rewritten: String = content |
| 167 | .lines() |
| 168 | .map(|line| { |
| 169 | if line.trim() == "[git.shim.watch]" { |
| 170 | in_watch = true; |
| 171 | return line.to_string(); |
| 172 | } |
| 173 | if line.trim().starts_with('[') { |
| 174 | in_watch = false; |
| 175 | return line.to_string(); |
| 176 | } |
| 177 | if in_watch && line.trim() == "enabled = false" { |
| 178 | flipped = true; |
| 179 | return "enabled = true".to_string(); |
| 180 | } |
| 181 | line.to_string() |
| 182 | }) |
| 183 | .collect::<Vec<_>>() |
| 184 | .join("\n"); |
| 185 | let rewritten = rewritten + "\n"; |
| 186 | assert!( |
| 187 | flipped, |
| 188 | "the disabled watch default must be present to flip:\n{content}" |
| 189 | ); |
| 190 | fs::write(config, rewritten).expect("write repo config"); |
| 191 | } |
| 192 | |
| 193 | /// Remove the watch consent while keeping the shim consent. |
| 194 | fn disable_watch(root: &Path) { |