Skip to content

Commit

Permalink
better awareness of line breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
eugene-babichenko committed Jun 13, 2024
1 parent 3695fe9 commit 7aab122
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/cmd/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ impl Cmd {
bar.finish_and_clear();
return Ok(());
};

if log_enabled!(log::Level::Debug) {
let elapsed = SystemTime::now().duration_since(time).unwrap();
log::debug!("command output in {} milliseconds", elapsed.as_millis());
Expand Down
2 changes: 1 addition & 1 deletion src/rules/cargo_install_cwd.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const ERROR: &str = "using `cargo install` to install the binaries from the package in current working directory is no longer supported";
const ERROR: &str = "using `cargo install` to install the binaries";

pub fn cargo_install_cwd(cmd: &[String], error: &str) -> Option<Vec<String>> {
if !error.contains(ERROR) {
Expand Down
19 changes: 11 additions & 8 deletions src/rules/git_no_upstream.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
pub fn git_no_upstream(_cmd: &[String], error: &str) -> Option<Vec<String>> {
let regex = regex::Regex::new(
r"to push the current branch and set the remote as upstream, use\s+([^\n]+)",
)
.unwrap();
let cmd = regex
pub fn git_no_upstream(cmd: &[String], error: &str) -> Option<Vec<String>> {
let regex =
regex::Regex::new(r"--set-upstream\s([A-Za-z0-9-_./]+)\s([A-Za-z0-9-_./]+)").unwrap();
let origin = regex
.captures_iter(error)
.map(|c| c.extract::<1>().1[0])
.map(|c| c.extract::<2>())
.next()?;
shlex::split(cmd)
let (idx, _) = cmd.iter().enumerate().find(|(_, s)| *s == "push")?;
let mut cmd = cmd.to_vec();
cmd.insert(idx + 1, "--set-upstream".to_string());
cmd.insert(idx + 2, origin.1[0].to_string());
cmd.insert(idx + 3, origin.1[1].to_string());
Some(cmd)
}

#[cfg(test)]
Expand Down

0 comments on commit 7aab122

Please sign in to comment.