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

Function enable_shim

atomic-cli/src/commands/git/hooks.rs:86–234  ·  view source on GitHub ↗

Enable the shim's advisory `post-checkout` integration. Only a missing hook or an exact Atomic-owned dispatcher is written. A custom `core.hooksPath`, symlink, binary, or unmanaged hook is reported with an integration command and left byte-for-byte untouched.

(root: &Path, mirror_ignores: bool)

Source from the content-addressed store, hash-verified

84/// custom `core.hooksPath`, symlink, binary, or unmanaged hook is reported with
85/// an integration command and left byte-for-byte untouched.
86pub(crate) fn enable_shim(root: &Path, mirror_ignores: bool) -> CliResult<()> {
87 let root = canonical_root(root)?;
88 let binary = std::env::current_exe()
89 .map_err(|error| git_error(format!("cannot resolve the Atomic binary path: {error}")))?;
90 let context = git_hook_context(&root)?;
91
92 if let Some(custom_hooks_path) = context.custom_hooks_path {
93 print_unmanaged_instructions(
94 &format!(
95 "core.hooksPath is configured as '{}'; Atomic did not modify that hook system",
96 custom_hooks_path.display()
97 ),
98 &binary,
99 )?;
100 return Ok(());
101 }
102
103 let hooks_dir = context.common_dir.join("hooks");
104 fs::create_dir_all(&hooks_dir).map_err(|error| {
105 git_error(format!(
106 "cannot create Git hooks directory '{}': {error}",
107 hooks_dir.display()
108 ))
109 })?;
110
111 migrate_legacy_import_hooks(&hooks_dir, &binary)?;
112
113 let hook_path = hooks_dir.join("post-checkout");
114 let script = dispatcher_script(&binary, "hook-post-checkout").map_err(|error| {
115 git_error(format!(
116 "cannot build the advisory post-checkout dispatcher: {error}"
117 ))
118 })?;
119 match install_or_refresh_dispatcher(&hook_path, &script).map_err(|error| {
120 git_error(format!(
121 "cannot install advisory dispatcher '{}': {error}",
122 hook_path.display()
123 ))
124 })? {
125 DispatcherInstall::Installed => print_info(&format!(
126 "Installed Atomic advisory post-checkout dispatcher at {}",
127 hook_path.display()
128 )),
129 DispatcherInstall::Refreshed => print_info(&format!(
130 "Refreshed Atomic advisory post-checkout dispatcher at {}",
131 hook_path.display()
132 )),
133 DispatcherInstall::Unmanaged => print_unmanaged_instructions(
134 &format!(
135 "existing post-checkout hook '{}' is not Atomic-owned and was left untouched",
136 hook_path.display()
137 ),
138 &binary,
139 )?,
140 }
141
142 // CB-9B: journal post-rewrite and reference-transaction evidence with the
143 // same ownership rules — a missing hook or an exact Atomic-owned

Callers 5

runMethod · 0.85
runMethod · 0.85
adopt_git_checkoutFunction · 0.85
enabled_repositoryFunction · 0.85

Calls 10

canonical_rootFunction · 0.85
git_hook_contextFunction · 0.85
dispatcher_scriptFunction · 0.85
print_infoFunction · 0.85
print_warningFunction · 0.85
git_errorFunction · 0.70