Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hook doesn't work: bad fd number #1084

Closed
5 tasks done
ablacklama opened this issue May 9, 2023 · 5 comments · Fixed by #1085
Closed
5 tasks done

Hook doesn't work: bad fd number #1084

ablacklama opened this issue May 9, 2023 · 5 comments · Fixed by #1085
Labels

Comments

@ablacklama
Copy link

Describe the bug

Getting an error whenever i run git commit with the new hook.
error: .git/hooks/prepare-commit-msg: 10: Syntax error: Bad fd number

It looks like it's due to a change in the prepare-commit-msg script generated by gitmoji -i.
The old code it used to generate works well for me but the new one is broken.

old:

#!/bin/sh
# gitmoji as a commit hook
if test -t 1 && ! grep -q -m 1 '^[^#]' $1; then
  # it has been invoked from a tty and no commit message is already set
  exec < /dev/tty
  gitmoji --hook $1
fi

new:

#!/usr/bin/env sh
# gitmoji as a commit hook
if npx -v >&/dev/null
then
  exec < /dev/tty
  npx -c "gitmoji --hook $1 $2"
else
  exec < /dev/tty
  gitmoji --hook $1 $2
fi

I made sure to test out both the old and new hooks in several repos and the behavior is consistent.

Reproduction

I've reproduced it in bash and zsh (not that it should matter for an sh script). But I just ran gitmoji -i and then committed a file and it gave the error.

System Info

System:
    OS: Linux 5.15 Ubuntu 22.04.1 LTS 22.04.1 LTS (Jammy Jellyfish)
    CPU: (64) x64 AMD Ryzen Threadripper 3970X 32-Core Processor
    Memory: 231.16 GB / 251.55 GB
    Container: Yes
    Shell: 5.8.1 - /usr/bin/zsh
  Binaries:
    Node: 18.6.0 - ~/.nvm/versions/node/v18.6.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v18.6.0/bin/yarn
    npm: 9.6.5 - ~/.nvm/versions/node/v18.6.0/bin/npm
  Browsers:
    Brave Browser: 113.1.51.110

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating duplicates.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.
@carloscuesta
Copy link
Owner

Hey!

Thanks for reporting the issue, indeed looks related with the usage of the &> syntax:

https://unix.stackexchange.com/questions/407798/syntax-error-bad-fd-number

@carloscuesta
Copy link
Owner

Can you try changing the shebang to:

#!/usr/bin/env bash
# gitmoji as a commit hook
if npx -v >&/dev/null
then
  exec < /dev/tty
  npx -c "gitmoji --hook $1 $2"
else
  exec < /dev/tty
  gitmoji --hook $1 $2
fi

Are you still able to reproduce the issue?

@ablacklama
Copy link
Author

That works

@carloscuesta
Copy link
Owner

I'll make the change and ship a fix 👍🏼

Thanks for reporting the issue

@carloscuesta
Copy link
Owner

Fixed in 8.2.2 going live now 🚀

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants