Skip to content

Commit 3baf204

Browse files
alecthomasclaude
andauthored
fix: move user config to ~/.config/lefthook.yaml (#15)
~/.local/etc is, unfortunately, not a thing Co-authored-by: Claude Code <noreply@anthropic.com>
1 parent a5480b2 commit 3baf204

3 files changed

Lines changed: 15 additions & 8 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ for repo configs), where `<ext>` is `yml`, `yaml`, `json`, `jsonc`, or `toml`.
2929

3030
- Creates shell wrapper scripts for all standard git hooks in `~/.local/libexec/lhm/hooks/`, each invoking `lhm run-hook <hook>`
3131
- Sets `git config --global core.hooksPath ~/.local/libexec/lhm/hooks`
32-
- Writes a default `~/.local/etc/lefthook.yaml` if no user config exists
32+
- Writes a default `~/.config/lefthook.yaml` if no user config exists
3333

3434
### `lhm install --system`
3535

@@ -82,14 +82,14 @@ When git triggers a hook, it runs the wrapper script in the hooks directory. Eac
8282
Config is resolved as a three-layer merge, where later layers override earlier ones:
8383

8484
1. **System** (`/usr/local/etc/lefthook.yaml`) — organizational baseline
85-
2. **User global** (`~/.local/etc/lefthook.yaml`) — per-user overrides
85+
2. **User global** (`~/.config/lefthook.yaml`) — per-user overrides
8686
3. **Repo** (`$REPO/lefthook.yaml` or adapter) — per-repo overrides
8787

8888
Any layer may be absent. When a repo has no lefthook config, the adapter system is used in its place (see below).
8989

9090
### Adapters
9191

92-
When a repo has no `lefthook.yaml`, lhm checks for other git hook managers and transparently adapts them. The generated adapter config is merged with `~/.local/etc/lefthook.yaml` using the standard merging system, so global hooks still apply.
92+
When a repo has no `lefthook.yaml`, lhm checks for other git hook managers and transparently adapts them. The generated adapter config is merged with `~/.config/lefthook.yaml` using the standard merging system, so global hooks still apply.
9393

9494
Adapters are tried in this order (first match wins):
9595

src/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub fn find_config(dir: &Path, check_dot_config: bool) -> Option<PathBuf> {
8484
None
8585
}
8686

87-
/// Find the user-level lefthook config in the given directory (e.g. `~/.local/etc`).
87+
/// Find the user-level lefthook config in the given directory (e.g. `~/.config`).
8888
pub fn global_config(home: &Path, overrides: &ConfigOverrides) -> Option<PathBuf> {
8989
if let Some(ref p) = overrides.global_config {
9090
debug!("using global config override: {}", p.display());
@@ -121,7 +121,7 @@ pub fn install_default_global_config(dir: &Path) -> Result<(), String> {
121121
Ok(())
122122
}
123123

124-
/// Load the user-level config from `~/.local/etc/lefthook.yaml` (or override) if it exists.
124+
/// Load the user-level config from `~/.config/lefthook.yaml` (or override) if it exists.
125125
pub fn load_global_config(dir: &Path, overrides: &ConfigOverrides) -> Result<Option<Value>, String> {
126126
match global_config(dir, overrides) {
127127
Some(path) => read_yaml(&path).map(Some),

src/main.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ impl InstallScope {
130130
}
131131

132132
fn config_dir(&self) -> PathBuf {
133-
self.base_dir().join("etc")
133+
match self {
134+
Self::User => home_dir().join(".config"),
135+
Self::System => self.base_dir().join("etc"),
136+
}
134137
}
135138
}
136139

@@ -566,16 +569,20 @@ mod tests {
566569

567570
#[test]
568571
fn test_install_scope_user_config_dir() {
569-
assert!(InstallScope::User.config_dir().ends_with(".local/etc"));
572+
assert!(InstallScope::User.config_dir().ends_with(".config"));
570573
}
571574

572575
#[test]
573576
fn test_install_scope_base_dir_shared_structure() {
574577
for scope in [InstallScope::User, InstallScope::System] {
575578
let base = scope.base_dir();
576579
assert_eq!(scope.hooks_dir(), base.join("libexec/lhm/hooks"));
577-
assert_eq!(scope.config_dir(), base.join("etc"));
578580
}
581+
assert_eq!(
582+
InstallScope::System.config_dir(),
583+
InstallScope::System.base_dir().join("etc")
584+
);
585+
assert!(InstallScope::User.config_dir().ends_with(".config"));
579586
}
580587

581588
#[test]

0 commit comments

Comments
 (0)