Skip to content

Commit

Permalink
print squashed detected diff
Browse files Browse the repository at this point in the history
Do not print the changes commit per commits for the commits within the
range, but directly print the whole diff of the range start to the range
end.

This behavior is possible by changing the `git log` command usage to
`git diff` instead.
  • Loading branch information
nm2107 committed May 14, 2020
1 parent 8bf07fd commit 4c5728a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
12 changes: 6 additions & 6 deletions git/src/commits_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ pub struct CommitsRange {
}

impl CommitsRange {
pub fn to_str(&self) -> String {
return format!(
"{}..{}",
&self.from,
&self.to,
);
pub fn from(&self) -> &String {
return &self.from;
}

pub fn to(&self) -> &String {
return &self.to;
}
}

Expand Down
14 changes: 10 additions & 4 deletions git/src/path_inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ pub fn has_changes_in_paths(
) -> bool {
let mut cmd = Command::new("git");
cmd
.arg("log")
.arg(commits_range.to_str())
.arg("diff")
.arg("--stat")
.arg(commits_range.from())
.arg(commits_range.to())
.args(paths)
.current_dir(&working_directory)
;
Expand All @@ -28,9 +29,14 @@ pub fn has_changes_in_paths(
.expect("Failed to run git log command.")
;

assert_or_panic(&result, &String::from("git log"));
assert_or_panic(&result, &String::from("git diff"));

info!("{}", String::from_utf8(result.stdout.to_vec()).unwrap());
info!(
"Detected diff from {} to {} :\n{}",
commits_range.from(),
commits_range.to(),
String::from_utf8(result.stdout.to_vec()).unwrap()
);

return !result.stdout.is_empty();
}

0 comments on commit 4c5728a

Please sign in to comment.