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

pre-push and pre-commit git hooks are handled differently when errors occur #178175

Open
IlIlIllIllI opened this issue Mar 23, 2023 · 1 comment
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug git GIT issues
Milestone

Comments

@IlIlIllIllI
Copy link

Does this issue occur when all extensions are disabled?: Yes

Version: 1.76.2 (user setup)
Commit: ee2b180
Date: 2023-03-14T17:55:54.936Z
Electron: 19.1.11
Chromium: 102.0.5005.196
Node.js: 16.14.2
V8: 10.2.154.26-electron.0
OS: Windows_NT x64 10.0.19044
Sandboxed: No

Issue:

pre-commit and pre-push git hooks are not handled consistently when errors occur.

pre-commit:
commit error

pre-push:
push error

Steps to Reproduce:

  1. Create a fresh directory
  2. git init
  3. Create pre-commit and pre-push files in the git hooks directory with the following contents:
    #!/bin/sh
    
    echo "Failure message"
    exit 1
  4. Try to commit from VSCode Source Control Tab
  5. Error message says "Git: Failure message"
  6. Disable the pre-commit hook
  7. Make a successful commit
  8. Configure a remote and attempt to run git push
  9. Error message says "Can't push refs to remote. Try running "Pull" first to integrate your changes"

pre-commit seems to use the first line of output in the error dialog, whereas pre-push uses the last one. It'd be nice if these were consistent. Furthermore, it seems that I just can't control the dialog message for pre-push failures, it's always the same.

@lszomoru lszomoru added bug Issue identified by VS Code Team member as probable bug git GIT issues labels Mar 27, 2023
@lszomoru lszomoru added this to the On Deck milestone Mar 27, 2023
@VladislavSorokin-sy
Copy link

VladislavSorokin-sy commented Mar 12, 2024

hey guys, do you know how could I write commit-msg so vscode could catch the error message correctly?

Here is my current version:

#!/bin/sh
message=$(cat $1)
npx commitlint --edit "$1" || {
  echo >&2 "Please follow the "conventional commit" format"
  exit 1
}

but the error message is Git: ⧗ input: <COMMIT_MESSAGE>

UPD. Found a solution! (more like a hack, but I am happy)

#!/bin/sh
message=$(cat $1)
if ! npx commitlint --edit "$1" > /dev/null 2>&1; then
  echo "Please follow the conventional commit format"
  exit 1
fi

mind the > /dev/null 2>&1;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug git GIT issues
Projects
None yet
Development

No branches or pull requests

3 participants