mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Use root repo hooks in linked worktrees (#21969)
# Why Linked worktrees currently load their own project hook declarations, so the same repo can present different hook definitions depending on which checkout is active. https://github.com/openai/codex/pull/21762 tried to share trust by giving matching worktree hooks a shared synthetic key, but review pointed out that divergent worktree hook definitions would then fight over one `trusted_hash`. Instead of introducing a second trust model, this makes linked worktrees use the root checkout as the single source of truth for project hook declarations. Worktree-local project config can still diverge for unrelated settings, but project hooks now keep one real source path and one trust state per repo. # What - Teach project config loading to remember the matching root-checkout `.codex/` folder for actual linked-worktree project layers. - Keep ordinary project config sourced from the worktree, but replace project hook declarations with the root checkout's matching layer before hook discovery runs, including linked-worktree layers with `.codex/` but no local `config.toml`. - Make hook discovery use that authoritative hook folder for both `hooks.json` and TOML hook source paths, so linked worktrees produce the same hook key and trust state as the root checkout. - Cover the linked-worktree path plus regressions for missing worktree `config.toml` and nested non-worktree project roots.
This commit is contained in:
1 parent
2304ec45ca
commit
934a40c7d9
6 files changed
+567
-39
No files matched your search
@@ -66,6 +66,7 @@ pub struct ConfigLayerEntry {
|
||||
pub raw_toml: Option<String>,
|
||||
pub version: String,
|
||||
pub disabled_reason: Option<String>,
|
||||
hooks_config_folder_override: Option<AbsolutePathBuf>,
|
||||
}
|
||||
|
||||
impl ConfigLayerEntry {
|
||||
@@ -77,6 +78,7 @@ impl ConfigLayerEntry {
|
||||
raw_toml: None,
|
||||
version,
|
||||
disabled_reason: None,
|
||||
hooks_config_folder_override: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,6 +90,7 @@ impl ConfigLayerEntry {
|
||||
raw_toml: Some(raw_toml),
|
||||
version,
|
||||
disabled_reason: None,
|
||||
hooks_config_folder_override: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,6 +106,7 @@ impl ConfigLayerEntry {
|
||||
raw_toml: None,
|
||||
version,
|
||||
disabled_reason: Some(disabled_reason.into()),
|
||||
hooks_config_folder_override: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,6 +118,14 @@ impl ConfigLayerEntry {
|
||||
self.raw_toml.as_deref()
|
||||
}
|
||||
|
||||
pub(crate) fn with_hooks_config_folder_override(
|
||||
mut self,
|
||||
hooks_config_folder_override: Option<AbsolutePathBuf>,
|
||||
) -> Self {
|
||||
self.hooks_config_folder_override = hooks_config_folder_override;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn metadata(&self) -> ConfigLayerMetadata {
|
||||
ConfigLayerMetadata {
|
||||
name: self.name.clone(),
|
||||
@@ -142,6 +154,18 @@ impl ConfigLayerEntry {
|
||||
ConfigLayerSource::LegacyManagedConfigTomlFromMdm => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the `.codex/` folder that should be used for hook declarations.
|
||||
///
|
||||
/// Project layers normally use their own config folder. Linked Git worktrees
|
||||
/// can instead point hook discovery at the matching folder from the root
|
||||
/// checkout while the rest of the project config still comes from the
|
||||
/// worktree.
|
||||
pub fn hooks_config_folder(&self) -> Option<AbsolutePathBuf> {
|
||||
self.hooks_config_folder_override
|
||||
.clone()
|
||||
.or_else(|| self.config_folder())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
|
||||
Reference in new issue
Block a user