Skip to content

Respect GIT_DIR set by git#1258

Merged
j178 merged 4 commits intomasterfrom
misc
Dec 23, 2025
Merged

Respect GIT_DIR set by git#1258
j178 merged 4 commits intomasterfrom
misc

Conversation

@j178
Copy link
Owner

@j178 j178 commented Dec 22, 2025

Closes #1239
Closes #1252

@j178 j178 added the bug Something isn't working label Dec 22, 2025
@codecov
Copy link

codecov bot commented Dec 22, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.05%. Comparing base (9e7b674) to head (b65c9f6).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1258      +/-   ##
==========================================
+ Coverage   90.03%   90.05%   +0.02%     
==========================================
  Files          80       80              
  Lines       15627    15654      +27     
==========================================
+ Hits        14069    14097      +28     
+ Misses       1558     1557       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link

github-actions bot commented Dec 22, 2025

📦 Cargo Bloat Comparison

Binary size change: +0.00% (16.7 MiB → 16.7 MiB)

Expand for cargo-bloat output

Head Branch Results

 File  .text     Size          Crate Name
 0.6%   1.4% 107.3KiB          prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.6%   1.4% 107.2KiB           prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.3%   0.7%  54.7KiB           prek prek::archive::unpack::{{closure}}
 0.3%   0.7%  52.8KiB             h2 h2::proto::connection::Connection<T,P,B>::poll
 0.2%   0.5%  39.2KiB          prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.2%   0.5%  39.2KiB           prek prek::run::{{closure}}
 0.2%   0.5%  38.3KiB           prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.2%   0.5%  37.3KiB          hyper hyper::proto::h1::dispatch::Dispatcher<D,Bs,I,T>::poll_loop
 0.2%   0.5%  36.9KiB regex_automata regex_automata::meta::strategy::new
 0.2%   0.5%  36.5KiB           prek prek::workspace::Workspace::discover
 0.2%   0.4%  30.8KiB           std? <core::marker::PhantomData<T> as serde_core::de::DeserializeSeed>::deserialize
 0.2%   0.4%  30.7KiB           prek prek::cli::run::run::run::{{closure}}
 0.2%   0.4%  29.8KiB           prek prek::languages::rust::installer::RustInstaller::install::{{closure}}
 0.2%   0.4%  28.4KiB           prek prek::languages::node::installer::NodeInstaller::install::{{closure}}
 0.2%   0.4%  27.9KiB             h2 h2::proto::connection::DynConnection<B>::recv_frame
 0.2%   0.3%  27.6KiB           prek prek::identify::by_extension::{{closure}}
 0.2%   0.3%  25.7KiB           prek prek::cli::run::run::run_hooks::{{closure}}
 0.1%   0.3%  25.3KiB           prek prek::main
 0.1%   0.3%  24.4KiB     hyper_util hyper_util::client::legacy::client::Client<C,B>::send_request::{{closure}}
 0.1%   0.3%  24.3KiB        globset globset::GlobSetBuilder::build
41.2%  88.6%   6.9MiB                And 10641 smaller methods. Use -n N to show more.
46.5% 100.0%   7.8MiB                .text section size, the file size is 16.7MiB

Base Branch Results

 File  .text     Size          Crate Name
 0.6%   1.4% 107.3KiB          prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.6%   1.3% 107.2KiB           prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.3%   0.7%  54.7KiB           prek prek::archive::unpack::{{closure}}
 0.3%   0.7%  52.8KiB             h2 h2::proto::connection::Connection<T,P,B>::poll
 0.2%   0.5%  39.2KiB          prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.2%   0.5%  38.4KiB           prek prek::run::{{closure}}
 0.2%   0.5%  38.3KiB           prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.2%   0.5%  37.3KiB          hyper hyper::proto::h1::dispatch::Dispatcher<D,Bs,I,T>::poll_loop
 0.2%   0.5%  36.9KiB regex_automata regex_automata::meta::strategy::new
 0.2%   0.5%  36.5KiB           prek prek::workspace::Workspace::discover
 0.2%   0.4%  30.8KiB           std? <core::marker::PhantomData<T> as serde_core::de::DeserializeSeed>::deserialize
 0.2%   0.4%  30.7KiB           prek prek::cli::run::run::run::{{closure}}
 0.2%   0.4%  29.8KiB           prek prek::languages::rust::installer::RustInstaller::install::{{closure}}
 0.2%   0.4%  28.4KiB           prek prek::languages::node::installer::NodeInstaller::install::{{closure}}
 0.2%   0.4%  27.9KiB             h2 h2::proto::connection::DynConnection<B>::recv_frame
 0.2%   0.3%  27.6KiB           prek prek::identify::by_extension::{{closure}}
 0.2%   0.3%  25.7KiB           prek prek::cli::run::run::run_hooks::{{closure}}
 0.1%   0.3%  25.3KiB           prek prek::main
 0.1%   0.3%  24.4KiB     hyper_util hyper_util::client::legacy::client::Client<C,B>::send_request::{{closure}}
 0.1%   0.3%  24.3KiB        globset globset::GlobSetBuilder::build
41.2%  88.6%   6.9MiB                And 10639 smaller methods. Use -n N to show more.
46.5% 100.0%   7.8MiB                .text section size, the file size is 16.7MiB

@j178
Copy link
Owner Author

j178 commented Dec 22, 2025

Hey @jmelahman,
I poked around a bit, and it looks like the right move is to keep GIT_DIR and just set the missing GIT_WORK_TREE. Can you check if that actually fixed the issue on your end?

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR changes how prek handles Git environment variables when running hooks. Instead of unsetting GIT_DIR in generated hook scripts, prek now respects the GIT_DIR value set by git and intelligently sets GIT_WORK_TREE when necessary to ensure correct git behavior.

  • Removed unset GIT_DIR from all generated hook scripts
  • Added logic to set GIT_WORK_TREE when GIT_DIR is set but GIT_WORK_TREE is not
  • Incremented hook script version from 3 to 4 to trigger re-installation
  • Added comprehensive test coverage for the new behavior

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
crates/prek/src/main.rs Added logic to detect when GIT_DIR is set and intelligently set GIT_WORK_TREE to the current directory before any --cd operations
crates/prek/src/cli/install.rs Removed unset GIT_DIR from hook template and incremented script version to 4
crates/prek-consts/src/env_vars.rs Added constants for GIT_DIR and GIT_WORK_TREE environment variables
crates/prek/tests/hook_impl.rs Added new test git_dir_respected() to verify hooks work correctly with GIT_DIR set; reorganized setup calls in run_worktree() test; added PREK_HOME env var to workspace test command; cleaned up string literal delimiter
crates/prek/tests/install.rs Updated all test snapshots to reflect removal of unset GIT_DIR and script version bump to 4
crates/prek/tests/run.rs Added PREK_HOME environment variable to git commit command in test

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@j178 j178 merged commit 19dcd5c into master Dec 23, 2025
28 checks passed
@j178 j178 deleted the misc branch December 23, 2025 02:49
@jmelahman
Copy link
Contributor

I agree, much cleaner :) I confirmed this resolved my issue. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

error: Command get git root exited with an error:

3 participants