Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Add pre-commit hooks to improve code quality
Maximilian Roosd9d64340b249
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yamlnew file mode 100644index 000000000..08f8e2273--- /dev/null+++ b/.pre-commit-config.yaml@@ -0,0 +1,45 @@+repos:+ - repo: https://github.com/pre-commit/pre-commit-hooks+ rev: v6.0.0+ hooks:+ - id: end-of-file-fixer+ exclude: '.*\.snap$'+ - id: check-yaml+ - id: mixed-line-ending+ - id: trailing-whitespace+ # rustfmt handles rust files, and in snapshots we expect trailing spaces.+ exclude: '.*\.(rs|snap)$'+ - repo: https://github.com/crate-ci/typos+ rev: v1.37.2+ hooks:+ - id: typos+ # https://github.com/crate-ci/typos/issues/347+ pass_filenames: false+ - repo: https://github.com/r0x0d/pre-commit-rust+ rev: v1.0.1+ hooks:+ - id: fmt+ - repo: https://github.com/r0x0d/pre-commit-rust+ rev: v1.0.1+ hooks:+ - id: clippy+ stages: [manual]+ - repo: https://github.com/tcort/markdown-link-check+ rev: v3.14.1+ hooks:+ - id: markdown-link-check+ name: markdown-link-check+ types: [markdown]+ - repo: local+ hooks:+ - id: no-dbg+ name: no-dbg+ description: We shouldn't merge code with `dbg!` in+ language: pygrep+ types: ["rust"]+ entry: "dbg!"++ci:+ # Currently network access isn't supported in the CI product.+ skip: [fmt, markdown-link-check]+ autoupdate_commit_msg: "chore: pre-commit autoupdate"diff --git a/src/git.rs b/src/git.rsindex 47a1c8aa1..7e3fc9928 100644--- a/src/git.rs+++ b/src/git.rs@@ -170,9 +170,7 @@ fn parse_local_default_branch(output: &str) -> Result<String, GitError> {let trimmed = output.trim();// Strip "origin/" prefix if present- let branch = trimmed- .strip_prefix("origin/")- .unwrap_or(trimmed);+ let branch = trimmed.strip_prefix("origin/").unwrap_or(trimmed);if branch.is_empty() {return Err(GitError::ParseError(diff --git a/src/main.rs b/src/main.rsindex dfd2f9e8e..b807721c6 100644--- a/src/main.rs+++ b/src/main.rs@@ -1,7 +1,7 @@use clap::{Parser, Subcommand};+use std::process;use worktrunk::git::{GitError, list_worktrees};use worktrunk::shell;-use std::process;#[derive(Parser)]#[command(name = "wt")]diff --git a/tests/integration_tests/default_branch.rs b/tests/integration_tests/default_branch.rsindex 1fee011bb..c02dbe8e7 100644--- a/tests/integration_tests/default_branch.rs+++ b/tests/integration_tests/default_branch.rs@@ -45,8 +45,7 @@ fn test_get_default_branch_caches_result() {assert!(!repo.has_origin_head());// First call queries remote and caches- worktrunk::git::get_default_branch_in(repo.root_path())- .expect("Failed to get default branch");+ worktrunk::git::get_default_branch_in(repo.root_path()).expect("Failed to get default branch");assert!(repo.has_origin_head());// Second call uses cache (fast path)