MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / git_hook_context

Function git_hook_context

atomic-cli/src/commands/git/hooks.rs:263–299  ·  view source on GitHub ↗
(root: &Path)

Source from the content-addressed store, hash-verified

261}
262
263pub(super) fn git_hook_context(root: &Path) -> CliResult<GitHookContext> {
264 let common_dir = match observe_git(root)
265 .map_err(|error| git_error(format!("cannot resolve Git administrative paths: {error}")))?
266 {
267 GitObservation::NoGit { .. } => {
268 return Err(git_error("cannot enable the shim outside a Git repository"));
269 }
270 GitObservation::Repository(observation) => {
271 if observation.paths.worktree_root.is_none() {
272 return Err(git_error(
273 "cannot enable a working-copy hook for a bare Git repository",
274 ));
275 }
276 observation.paths.common_dir.clone()
277 }
278 };
279
280 let repository = GitRepository::open(root)
281 .map_err(|error| git_error(format!("cannot open Git repository: {error}")))?;
282 let config = repository
283 .config()
284 .map_err(|error| git_error(format!("cannot read Git configuration: {error}")))?;
285 let custom_hooks_path = match config.get_path("core.hooksPath") {
286 Ok(path) => Some(path),
287 Err(error) if error.code() == ErrorCode::NotFound => None,
288 Err(error) => {
289 return Err(git_error(format!(
290 "cannot read configured core.hooksPath: {error}"
291 )))
292 }
293 };
294
295 Ok(GitHookContext {
296 common_dir,
297 custom_hooks_path,
298 })
299}
300
301fn dispatcher_script(binary: &Path, subcommand: &str) -> io::Result<String> {
302 let binary = shell_quote(binary)?;

Callers 4

enable_shimFunction · 0.85
uninstall_shimFunction · 0.85
show_statusFunction · 0.85
inspect_dispatchersFunction · 0.85

Calls 7

observe_gitFunction · 0.85
openFunction · 0.85
is_noneMethod · 0.80
git_errorFunction · 0.70
cloneMethod · 0.45
get_pathMethod · 0.45
codeMethod · 0.45

Tested by

no test coverage detected