From b180f981b8c93e8379eb3745692fe05830af4a7b Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 20 Jan 2021 09:05:08 +0100 Subject: 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 --- src/util/git.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src') 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 { - 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 { -- cgit v1.2.3