Fix linked worktree hook loading when the root .codex is a file (#63088)

## Why

When `.codex` in the root checkout is a regular file, reading
`.codex/config.toml` returns `NotADirectory`. That error aborts project
configuration loading for the linked worktree.

## What changed

Treat `NotADirectory` like a missing config when reading project hook
configuration from the root checkout.

## Testing

Cover a linked worktree that keeps its local project settings and inherits
hooks from the matching subdirectory in the root checkout even when the
root checkout's top-level `.codex` is a file.

GitOrigin-RevId: 2cb7fcb340ce85253641c016dace5177096ba205
This commit is contained in:
Eric Traut
2026-11-22 07:01:32 +00:00
committed by copyberry
parent 618d501ea0
commit e1ecb5c8fc
2 changed files with 26 additions and 9 deletions
+6 -1
View File
@@ -2076,7 +2076,12 @@ async fn load_root_checkout_project_config(
};
parsed
}
Err(err) if err.kind() == io::ErrorKind::NotFound => {
Err(err)
if matches!(
err.kind(),
io::ErrorKind::NotFound | io::ErrorKind::NotADirectory
) =>
{
TomlValue::Table(toml::map::Map::new())
}
Err(err) => {
@@ -3554,18 +3554,26 @@ async fn malformed_untrusted_linked_worktree_does_not_read_root_hooks() -> std::
}
#[tokio::test]
async fn linked_worktree_project_layers_use_root_repo_hooks_without_worktree_config_toml()
async fn linked_worktree_project_layers_skip_non_directory_base_config_and_inherit_nested_hooks()
-> std::io::Result<()> {
let tmp = tempdir()?;
let repo_root = tmp.path().join("repo");
let worktree_root = tmp.path().join("worktree");
let worktree_child = worktree_root.join("child");
tokio::fs::create_dir_all(worktree_root.join(".codex")).await?;
tokio::fs::create_dir_all(worktree_child.join(".codex")).await?;
write_linked_worktree_pointer(&repo_root, &worktree_root).await?;
tokio::fs::write(repo_root.join(".codex"), "").await?;
write_project_hook_config(
&repo_root.join(".codex"),
&worktree_root.join(".codex"),
Some("worktree-root"),
"echo worktree hook",
)
.await?;
write_project_hook_config(
&repo_root.join("child/.codex"),
/*foo*/ None,
"echo repo root hook",
"echo repo child hook",
)
.await?;
@@ -3579,7 +3587,7 @@ async fn linked_worktree_project_layers_use_root_repo_hooks_without_worktree_con
)
.await?;
let cwd = AbsolutePathBuf::from_absolute_path(&worktree_root)?;
let cwd = AbsolutePathBuf::from_absolute_path(&worktree_child)?;
let layers = load_config_layers_state(
LOCAL_FS.as_ref(),
&codex_home,
@@ -3594,16 +3602,20 @@ async fn linked_worktree_project_layers_use_root_repo_hooks_without_worktree_con
.layers_high_to_low()
.filter(|layer| matches!(layer.name, ConfigLayerSource::Project { .. }))
.collect();
assert_eq!(project_layers.len(), 1);
assert_eq!(project_layers.len(), 2);
assert_eq!(
project_layers[1].config,
TomlValue::Table(toml::toml! { foo = "worktree-root" })
);
assert_eq!(
project_layers[0].hooks_config_folder(),
Some(AbsolutePathBuf::from_absolute_path(
repo_root.join(".codex")
repo_root.join("child/.codex")
)?)
);
assert_eq!(
project_hook_command(project_layers[0]),
Some("echo repo root hook")
Some("echo repo child hook")
);
Ok(())