extrawurst / gitui

Blazing 💥 fast terminal-ui for git written in rust 🦀
MIT License
18.53k stars 570 forks source link

Pre-commit hooks are executed only when launched from the git root #2281

Open savchenko opened 4 months ago

savchenko commented 4 months ago

Describe the bug Pre-commit hook is ignored.

To Reproduce Steps to reproduce the behavior:

  1. mkdir .githooks && git config --local core.hooksPath .githooks
  2. Create .githooks/pre-commit with echo "Hook triggered" && exit 1 and chmod +x it.
  3. git commit now fails, as expected.
  4. gitui ignores the hook.

Expected behavior pre-commit behaviour is the same when using git CLI.

Screenshots N/A.

Context (please complete the following information):

Additional context Relates to:

extrawurst commented 4 months ago

It seems your repro steps are not correct: you say you create mkdir .githooks but then you create ./githooks/pre-commit (which is a subtle but very different folder name). if I fix this and create the pre-commit hook inside the path you configure: .githooks/pre-commit then gitui correct blocks the commit.

why in your case git rejects and gitui does not is beyond me

Screenshot 2024-06-28 at 09 12 51
savchenko commented 4 months ago

@extrawurst , a typo, fixed the original message. Git picks it up as it is configured to do so, in the local config:

[core]
    hooksPath = .githooks/

Turns out gitui correctly triggers the hook only when launched from the root folder (git rev-parse --show-toplevel).

Corresponding log record:

12:16:35 [TRACE] (1) git2_hooks::hookspath: [git2-hooks/src/hookspath.rs:114] run hook '".githooks/pre-commit"' in '"/home/user/foo/"'

And here is the successful attempt to commit the same file from one of the subfolders (e.g. /home/user/foo/src)

12:22:10 [ERROR] theme error ["/home/user/.config/gitui/theme.ron"]: 24:35: Failed to parse Colors: data did not match any variant of untagged enum ColorFormat
12:22:10 [TRACE] (1) gitui::app: [src/app.rs:154] open repo at: RefCell { value: Path(".") }
12:22:10 [TRACE] (6) mio::poll: [/home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/mio-0.8.11/src/poll.rs:551] registering event source with poller: token=Token(0), interests=READABLE
12:22:10 [TRACE] (6) mio::poll: [/home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/mio-0.8.11/src/poll.rs:551] registering event source with poller: token=Token(1), interests=READABLE
12:22:10 [TRACE] (1) asyncgit::status: [asyncgit/src/status.rs:102] request: [hash: 5275764462638972305] (type: WorkingDir)
12:22:10 [TRACE] (1) asyncgit::status: [asyncgit/src/status.rs:102] request: [hash: 4542120333235219920] (type: Stage)
12:22:10 [TRACE] (2) asyncgit::status: [asyncgit/src/status.rs:160] status fetched: 5275764462638972305 (type: WorkingDir)
12:22:10 [TRACE] (4) asyncgit::status: [asyncgit/src/status.rs:160] status fetched: 4542120333235219920 (type: Stage)
12:22:10 [TRACE] (1) gitui: [src/main.rs:215] app start: 21 ms
12:22:10 [TRACE] (1) gitui::app: [src/app.rs:375] update
12:22:10 [TRACE] (1) asyncgit::status: [asyncgit/src/status.rs:102] request: [hash: 7094696850961575051] (type: WorkingDir)
12:22:10 [TRACE] (1) asyncgit::status: [asyncgit/src/status.rs:102] request: [hash: 12783852074258472187] (type: Stage)
12:22:10 [TRACE] (2) asyncgit::status: [asyncgit/src/status.rs:160] status fetched: 7094696850961575051 (type: WorkingDir)
12:22:10 [TRACE] (4) asyncgit::status: [asyncgit/src/status.rs:160] status fetched: 12783852074258472187 (type: Stage)
12:22:10 [TRACE] (1) gitui::app: [src/app.rs:395] update_async: Git(Status)
12:22:10 [TRACE] (1) gitui::app: [src/app.rs:395] update_async: Git(Status)
12:22:10 [TRACE] (1) gitui::app: [src/app.rs:395] update_async: Git(Status)
12:22:10 [TRACE] (1) gitui::app: [src/app.rs:395] update_async: Git(Status)
12:22:11 [TRACE] (1) gitui::app: [src/app.rs:278] event: Input(Key(KeyEvent { code: Char('w'), modifiers: KeyModifiers(0x0), kind: Press, state: KeyEventState(0x0) }))
12:22:11 [TRACE] (1) asyncgit::diff: [asyncgit/src/diff.rs:101] request DiffParams { path: "foo.py", diff_type: Stage, options: DiffOptions { ignore_whitespace: false, context: 3, interhunk_lines: 0 } }
12:22:11 [TRACE] (1) gitui::app: [src/app.rs:395] update_async: Git(Diff)
12:22:11 [TRACE] (1) asyncgit::diff: [asyncgit/src/diff.rs:101] request DiffParams { path: "foo.py", diff_type: Stage, options: DiffOptions { ignore_whitespace: false, context: 3, interhunk_lines: 0 } }
12:22:11 [TRACE] (1) gitui::app: [src/app.rs:278] event: Input(Key(KeyEvent { code: Char('c'), modifiers: KeyModifiers(0x0), kind: Press, state: KeyEventState(0x0) }))
12:22:11 [TRACE] (1) gitui::app: [src/app.rs:278] event: Input(Key(KeyEvent { code: Char('R'), modifiers: KeyModifiers(SHIFT), kind: Press, state: KeyEventState(0x0) }))
12:22:12 [TRACE] (1) gitui::app: [src/app.rs:278] event: Input(Key(KeyEvent { code: Char('o'), modifiers: KeyModifiers(0x0), kind: Press, state: KeyEventState(0x0) }))
12:22:12 [TRACE] (1) gitui::app: [src/app.rs:278] event: Input(Key(KeyEvent { code: Char('g'), modifiers: KeyModifiers(0x0), kind: Press, state: KeyEventState(0x0) }))
12:22:12 [TRACE] (1) gitui::app: [src/app.rs:278] event: Input(Key(KeyEvent { code: Char('u'), modifiers: KeyModifiers(0x0), kind: Press, state: KeyEventState(0x0) }))
12:22:12 [TRACE] (1) gitui::app: [src/app.rs:278] event: Input(Key(KeyEvent { code: Char('e'), modifiers: KeyModifiers(0x0), kind: Press, state: KeyEventState(0x0) }))
12:22:12 [TRACE] (1) gitui::app: [src/app.rs:278] event: Input(Key(KeyEvent { code: Char('!'), modifiers: KeyModifiers(0x0), kind: Press, state: KeyEventState(0x0) }))
12:22:14 [TRACE] (1) gitui::app: [src/app.rs:278] event: Input(Key(KeyEvent { code: Char('d'), modifiers: KeyModifiers(CONTROL), kind: Press, state: KeyEventState(0x0) }))
12:22:14 [TRACE] (1) gitui::app: [src/app.rs:375] update
12:22:14 [TRACE] (1) asyncgit::diff: [asyncgit/src/diff.rs:101] request DiffParams { path: "foo.py", diff_type: Stage, options: DiffOptions { ignore_whitespace: false, context: 3, interhunk_lines: 0 } }
12:22:14 [TRACE] (1) asyncgit::status: [asyncgit/src/status.rs:102] request: [hash: 17309038260000894423] (type: WorkingDir)
12:22:14 [TRACE] (1) asyncgit::status: [asyncgit/src/status.rs:102] request: [hash: 9501808690652183810] (type: Stage)
12:22:14 [TRACE] (4) asyncgit::status: [asyncgit/src/status.rs:160] status fetched: 9501808690652183810 (type: Stage)
12:22:14 [TRACE] (5) asyncgit::status: [asyncgit/src/status.rs:160] status fetched: 17309038260000894423 (type: WorkingDir)
12:22:14 [TRACE] (1) gitui::app: [src/app.rs:395] update_async: Git(Diff)
12:22:14 [TRACE] (1) gitui::app: [src/app.rs:395] update_async: Git(Status)
12:22:14 [TRACE] (1) gitui::app: [src/app.rs:395] update_async: Git(Status)
12:22:14 [TRACE] (1) gitui::app: [src/app.rs:278] event: Input(Key(KeyEvent { code: Char('c'), modifiers: KeyModifiers(CONTROL), kind: Press, state: KeyEventState(0x0) }))