Skip to content

Commit

Permalink
rules: add git_commit_untracked_files
Browse files Browse the repository at this point in the history
  • Loading branch information
eugene-babichenko committed Aug 16, 2024
1 parent 87a12f6 commit ce422ff
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ and this project adheres to

- Support for getting command output from iTerm2.
- rules: `sudo` now reacts to `operation not permitted` messages.
- rules: react to `nothing added to commit but untracked files present` with
`git commit`.

### Fixed

Expand Down
38 changes: 38 additions & 0 deletions src/rules/git_commit_untracked_files.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
pub fn git_commit_untracked_files(mut cmd: Vec<String>, error: &str) -> Option<Vec<String>> {
if !(error.contains("no changes added to commit") || error.contains("untracked files present"))
{
log::debug!("does not contain a matching error message");
return None;
}
let mut new_cmd = vec![
"git".to_string(),
"add".to_string(),
"-A".to_string(),
"&&".to_string(),
];
new_cmd.append(&mut cmd);
Some(new_cmd)
}

#[cfg(test)]
mod test {
use crate::shlex::shlex;

use super::*;

#[test]
fn git_commit_no_changes_test() {
let cmd = shlex("git commit -m 'initial commit'");
let error = "no changes added to commit (use \"git add\" and/or \"git commit -a\")";
let expected = shlex("git add -A && git commit -m 'initial commit'");
assert_eq!(Some(expected), git_commit_untracked_files(cmd, error));
}

#[test]
fn git_commit_untracked_files_test() {
let cmd = shlex("git commit -m 'initial commit'");
let error = "nothing added to commit but untracked files present";
let expected = shlex("git add -A && git commit -m 'initial commit'");
assert_eq!(Some(expected), git_commit_untracked_files(cmd, error));
}
}
1 change: 1 addition & 0 deletions src/rules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ define_rules!(
cp_dir,
git_add_all_lowercase,
git_commit_no_changes,
git_commit_untracked_files,
git_no_upstream,
git_wrong_command,
mkdir_missing_parent,
Expand Down

0 comments on commit ce422ff

Please sign in to comment.