diff --git a/libimagstorestdhook/src/vcs/git/create.rs b/libimagstorestdhook/src/vcs/git/create.rs index fcba4535..335bf2a6 100644 --- a/libimagstorestdhook/src/vcs/git/create.rs +++ b/libimagstorestdhook/src/vcs/git/create.rs @@ -89,56 +89,9 @@ impl StoreIdAccessor for CreateHook { /// After that, the UpdateHook will take care of committing the changes or new file. /// fn access(&self, id: &StoreId) -> HookResult<()> { - use vcs::git::action::StoreAction; - use vcs::git::config::commit_message; - use vcs::git::error::MapIntoHookError; - use vcs::git::util::fetch_index; - debug!("[GIT CREATE HOOK]: {:?}", id); - - let path = try!( - id.clone() - .into_pathbuf() - .map_err_into(GHEK::StoreIdHandlingError) - .map_into_hook_error() - ); - - let action = StoreAction::Create; - try!(self.runtime.ensure_cfg_branch_is_checked_out(&action)); - - let cfg = try!(self.runtime.config_value_or_err(&action)); - let repo = try!(self.runtime.repository(&action)); - let mut index = try!(fetch_index(repo, &action)); - - let file_status = try!( - repo - .status_file(&path) - .map_err_into(GHEK::RepositoryFileStatusError) - .map_into_hook_error() - ); - - let cb = &mut |path: &Path, _matched_spec: &[u8]| -> i32 { - if file_status.contains(STATUS_WT_MODIFIED) || - file_status.contains(STATUS_WT_NEW) { - - debug!("[GIT CREATE HOOK]: File is new or modified: {}", path.display()); - 0 - } else { - debug!("[GIT CREATE HOOK]: Ignoring file: {}", path.display()); - 1 - } - }; - - try!( - index.add_all(&[path], ADD_DEFAULT, Some(cb as &mut IndexMatchedPath)) - .map_err_into(GHEK::RepositoryPathAddingError) - .map_into_hook_error() - ); - - index - .write() - .map_err_into(GHEK::RepositoryIndexWritingError) - .map_into_hook_error() + debug!("[GIT CREATE HOOK]: Doing nothing as Store::create() is lazy and does not write to disk"); + Ok(()) } } diff --git a/libimagstorestdhook/src/vcs/git/update.rs b/libimagstorestdhook/src/vcs/git/update.rs index fa4af2c9..7dd3a13c 100644 --- a/libimagstorestdhook/src/vcs/git/update.rs +++ b/libimagstorestdhook/src/vcs/git/update.rs @@ -1,4 +1,5 @@ use std::path::PathBuf; +use std::path::Path; use std::fmt::{Debug, Formatter, Error as FmtError}; use std::result::Result as RResult; @@ -88,6 +89,8 @@ impl StoreIdAccessor for UpdateHook { use vcs::git::config::commit_message; use vcs::git::error::MapIntoHookError; use vcs::git::util::fetch_index; + use git2::{Reference as GitReference, Repository, Error as Git2Error}; + use git2::{ADD_DEFAULT, STATUS_WT_NEW, STATUS_WT_MODIFIED, IndexMatchedPath}; debug!("[GIT UPDATE HOOK]: {:?}", id); @@ -96,6 +99,13 @@ impl StoreIdAccessor for UpdateHook { let repo = try!(self.runtime.repository(&action)); let mut index = try!(fetch_index(repo, &action)); + let path = try!( + id.clone() + .into_pathbuf() + .map_err_into(GHEK::StoreIdHandlingError) + .map_into_hook_error() + ); + let tree_id = try!( index.write_tree() .map_err_into(GHEK::RepositoryIndexWritingError) @@ -114,6 +124,29 @@ impl StoreIdAccessor for UpdateHook { .map_into_hook_error() ); + let file_status = try!( + repo + .status_file(&path) + .map_err_into(GHEK::RepositoryFileStatusError) + .map_into_hook_error() + ); + + let cb = &mut |path: &Path, _matched_spec: &[u8]| -> i32 { + if file_status.contains(STATUS_WT_NEW) || file_status.contains(STATUS_WT_MODIFIED) { + debug!("[GIT CREATE HOOK]: File is modified/new: {}", path.display()); + 0 + } else { + debug!("[GIT CREATE HOOK]: Ignoring file: {}", path.display()); + 1 + } + }; + + try!( + index.add_all(&[path], ADD_DEFAULT, Some(cb as &mut IndexMatchedPath)) + .map_err_into(GHEK::RepositoryPathAddingError) + .map_into_hook_error() + ); + let mut parents = Vec::new(); { let commit = try!(