arxanas / git-branchless

High-velocity, monorepo-scale workflow for Git
Apache License 2.0
3.37k stars 80 forks source link

Crash when installing hooks with invalid `core.hooksPath` #1328

Closed hkrutzer closed 1 month ago

hkrutzer commented 1 month ago

Description of the bug

$ /tmp> mkdir testrepo
$ /tmp> cd testrepo
$ /t/testrepo (master) [101]> RUST_BACKTRACE=1 git branchless init
Created config file at /private/tmp/testrepo/.git/branchless/config
Your main branch name could not be auto-detected!
Examples of a main branch: master, main, trunk, etc.
See https://github.com/arxanas/git-branchless/wiki/Concepts#main-branch
Enter the name of your main branch: master
Installing hooks: post-applypatch, post-checkout, post-commit, post-merge, post-rewrite, pre-auto-gc, reference-transaction
The application panicked (crashed).
Message:  A fatal error occurred:
   0: Not a directory (os error 20)

Location:
   ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/git-branchless-init-0.9.0/src/lib.rs:221

  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ SPANTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   0: git_branchless_init::update_hook_contents with hook=RegularHook { path: "/dev/null/post-applypatch" } hook_contents="\ngit branchless hook post-applypatch \"$@\"\n"
      at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/git-branchless-init-0.9.0/src/lib.rs:206
   1: git_branchless_init::install_hook with repo=<Git repository at: "/private/tmp/testrepo/.git/"> hooks_dir="/dev/null" hook_type="post-applypatch" hook_script="\ngit branchless hook post-applypatch \"$@\"\n"
      at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/git-branchless-init-0.9.0/src/lib.rs:232
   2: git_branchless_init::install_hooks with effects=<Output fancy=true> git_run_info=<GitRunInfo path_to_git="git" working_directory="/private/tmp/testrepo" env=not shown> repo=<Git repository at: "/private/tmp/testrepo/.git/">
      at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/git-branchless-init-0.9.0/src/lib.rs:244
   3: git_branchless_init::command_init with effects=<Output fancy=true> git_run_info=<GitRunInfo path_to_git="git" working_directory="/private/tmp/testrepo" env=not shown> main_branch_name=None
      at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/git-branchless-init-0.9.0/src/lib.rs:602
   4: git_branchless_init::command_main with ctx=CommandContext { effects: <Output fancy=true>, git_run_info: <GitRunInfo path_to_git="git" working_directory="/private/tmp/testrepo" env=not shown> } args=InitArgs { uninstall: false, main_branch_name: None }
      at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/git-branchless-init-0.9.0/src/lib.rs:671

  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
                                ⋮ 5 frames hidden ⋮
   6: git_branchless_init::install_hook::h6bf892420dc15bd3
      at <unknown source file>:<unknown line>
   7: git_branchless_init::install_hooks::haa8dcd4c9def637a
      at <unknown source file>:<unknown line>
   8: git_branchless_init::command_main::h6364932b9c81106e
      at <unknown source file>:<unknown line>
   9: git_branchless::commands::command_main::hf4b99a6187dc988a
      at <unknown source file>:<unknown line>
  10: git_branchless_invoke::do_main_and_drop_locals::h3c3925fd58d8e309
      at <unknown source file>:<unknown line>
  11: git_branchless::commands::main::h0afd290a39a3e692
      at <unknown source file>:<unknown line>
  12: std::sys_common::backtrace::__rust_begin_short_backtrace::hd70560f092d0847c
      at <unknown source file>:<unknown line>
  13: std::rt::lang_start::{{closure}}::h72656fa04be4b91b
      at <unknown source file>:<unknown line>
  14: std::rt::lang_start_internal::h39923ab4c3913741
      at <unknown source file>:<unknown line>
  15: _main<unknown>
      at <unknown source file>:<unknown line>

Run with COLORBT_SHOW_HIDDEN=1 environment variable to disable frame filtering.
Run with RUST_BACKTRACE=full to include source snippets.
Location: ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/git-branchless-0.9.0/src/commands/mod.rs:235

  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
                                ⋮ 10 frames hidden ⋮
  11: core::result::Result<T,E>::expect::h9801a800f3193a2e
      at <unknown source file>:<unknown line>
  12: git_branchless::commands::main::h0afd290a39a3e692
      at <unknown source file>:<unknown line>
  13: std::sys_common::backtrace::__rust_begin_short_backtrace::hd70560f092d0847c
      at <unknown source file>:<unknown line>
  14: std::rt::lang_start::{{closure}}::h72656fa04be4b91b
      at <unknown source file>:<unknown line>
  15: std::rt::lang_start_internal::h39923ab4c3913741
      at <unknown source file>:<unknown line>
  16: _main<unknown>
      at <unknown source file>:<unknown line>

Run with COLORBT_SHOW_HIDDEN=1 environment variable to disable frame filtering.
Run with RUST_BACKTRACE=full to include source snippets.

(I've replaced the path to my homedir with ~)

Expected behavior

No response

Actual behavior

No response

Version of rustc

rustc 1.78.0 (9b00956e5 2024-04-29)

Automated bug report

Software version

git-branchless 0.9.0

Operating system

macOS 13.6.7 (Darwin 22.6.0)

Command-line

~/.cargo/bin/git-branchless bug-report

Environment variables

SHELL=/opt/homebrew/bin/fish
EDITOR=nvim

Git version

> git version
git version 2.45.0

Hooks

Error: Not a directory (os error 20)

Events

Error: Could not find repository main branch

Version of git-branchless

git-branchless-opts 0.9.0

Version of git

git version 2.45.0

arxanas commented 1 month ago

Your prompt says master after you cd into the new directory, but I don't see a git init in your repro steps; is it missing?

hkrutzer commented 1 month ago

Sorry, I ran git branchless init twice, the second time with RUST_BACKTRACE. I removed the first time for brevity and must have accidentally removed git init as well. But it is supposed to be there.

arxanas commented 1 month ago

I wasn't able to reproduce this.

arxanas commented 1 month ago

I opened https://github.com/arxanas/git-branchless/pull/1331 to include that information in the bug-report output.

hkrutzer commented 1 month ago

What is the value of git config --type path core.hooksPath for you? The output above suggests that it might be /dev/null, which would not be a valid directory to put hooks in.

Oops, I totally forgot I did that 🙂. That was indeed the problem. I should have seen that from the logs. Feel free this to close this issue (maybe you want to change the error message to say more but I don't think people often change core.hooksPath).

arxanas commented 1 month ago

maybe you want to change the error message to say more

I don't have time to adjust it right now, but I'm happy to accept a PR if you want to improve the message 🙂. Closing this issue for now (after having retitled it).