| 1 | use std::io::Write; |
| 2 | use std::path::Path; |
| 3 | |
| 4 | use anyhow::Context; |
| 5 | |
| 6 | use crate::flags::InitRepo; |
| 7 | |
| 8 | impl InitRepo { |
| 9 | pub fn run(self) -> anyhow::Result<()> { |
| 10 | append(&self.repo.join(".gitignore"), "*/*.so\n*/.BUILD_COOKIE\n")?; |
| 11 | append( |
| 12 | &self.repo.join(".gitattributes"), |
| 13 | "*/src/parser.c binary\n*/src/grammar.json binary\n", |
| 14 | )?; |
| 15 | Ok(()) |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | fn append(path: &Path, contents: &str) -> anyhow::Result<()> { |
| 20 | std::fs::File::options() |
| 21 | .create(true) |
| 22 | .append(true) |
| 23 | .open(path)? |
| 24 | .write_all(contents.as_bytes()) |
| 25 | .with_context(|| format!("failed to write {}", path.display())) |
| 26 | } |