From fa9d80fea33e6bd614cc36ac279f5b580d4c3673 Mon Sep 17 00:00:00 2001 From: Marcel Schneider Date: Fri, 16 Apr 2021 14:26:06 +0200 Subject: [PATCH] Add option to append to local ignore file --- src/app.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/app.rs b/src/app.rs index 541e928..481b538 100644 --- a/src/app.rs +++ b/src/app.rs @@ -65,7 +65,10 @@ pub enum Command { /// Add a line to the gitignore Add { /// The glob string that should be added - glob: String, + glob: String, + /// Add the entry to the repo local ignore file + #[structopt(short)] + local: bool, }, /// Download a gitignore for a language Get { @@ -87,7 +90,7 @@ pub enum Command { } /// Runs the command `add` -fn run_add(glob: &str) -> Result<()> { +fn run_add(glob: &str, local: bool) -> Result<()> { trace!("running command `add` with glob '{}'", &glob); let root = match git_dir()? { Some(r) => r, @@ -96,7 +99,11 @@ fn run_add(glob: &str) -> Result<()> { info!("Working with git root in {:?}", root); let mut file_path = PathBuf::from(&root); - file_path.push(".gitignore"); + if local { + file_path.push(".git/info/exclude") + } else { + file_path.push(".gitignore"); + } let gitig = Gitignore::from_path(&file_path); gitig.add_line(glob)?; debug!("Added '{}' to {}", glob, gitig); @@ -158,7 +165,7 @@ fn run_dump_completion(shell: Option) -> Result<()> { /// The actual `main()` pub fn main(opts: CliOpts) -> Result<()> { match opts.cmd { - Command::Add { glob } => run_add(&glob)?, + Command::Add { glob, local } => run_add(&glob, local)?, Command::Get { lang, append } => run_get(&lang, append)?, Command::ListTemplates => run_list_templates()?, Command::DumpCompletions { shell } => run_dump_completion(shell)?,