diff options
author | Matthias Beyer <matthias.beyer@atos.net> | 2021-01-20 09:05:08 +0100 |
---|---|---|
committer | Matthias Beyer <matthias.beyer@atos.net> | 2021-01-20 09:05:08 +0100 |
commit | b180f981b8c93e8379eb3745692fe05830af4a7b (patch) | |
tree | a5a38ca1bdb6084892586e6b57d447c81ec10c1b /src | |
parent | d3b2551de645466aeb4454325929787b1675fd8b (diff) |
Fix: Check the repository diff to workdir as well
This patch fixes the repository cleanness check, because the Repository::state()
is RepositoryState::Clean even if there are changed files in the worktree.
We want to fail if there's something uncommitted/unclean, so we have to check
the diff here as well.
Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/util/git.rs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/util/git.rs b/src/util/git.rs index 8ac163e..628e511 100644 --- a/src/util/git.rs +++ b/src/util/git.rs @@ -18,9 +18,16 @@ use git2::Repository; use log::trace; pub fn repo_is_clean(p: &Path) -> Result<bool> { - Repository::open(p) + let r = Repository::open(p)?; + + r.diff_index_to_workdir(None, None) + .and_then(|d| d.stats()) .map_err(Error::from) - .map(|r| r.state() == git2::RepositoryState::Clean) + .map(|st| { + trace!("Repo stats: {:?}", st); + trace!("Repo state: {:?}", r.state()); + st.files_changed() == 0 && r.state() == git2::RepositoryState::Clean + }) } pub fn get_repo_head_commit_hash(p: &Path) -> Result<String> { |