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

prepare-commit-msg hook code is populated in SCM commit message input #71550

Closed
mliq opened this issue Apr 1, 2019 · 5 comments
Closed

prepare-commit-msg hook code is populated in SCM commit message input #71550

mliq opened this issue Apr 1, 2019 · 5 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug git GIT issues help wanted Issues identified as good community contribution opportunities
Milestone

Comments

@mliq
Copy link

mliq commented Apr 1, 2019

  • Still happens in Insiders Build: ✅

  • VSCode Version: 1.32.3

  • OS Version: macOS 10.14.4

Steps to Reproduce:

  1. Have a custom prepare-commit-msg git hook located either in your project at ./.git/hooks OR in your global git hooks directory - Example provided below
  2. Open any vscode project folder
  3. Select menu View -> SCM
  4. Observe that the full code (minus comments) of the prepare-commit-msg is inserted in the git commit entry input area.
  5. Observe that this code will be repopulated after any commit or when VSCode is closed and opened again, or when a new project is opened.

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

Additional Info:

  • I have used this hook for several months and it worked correctly until the most recent VSCode update (1.32.3). By "correctly" I mean that the VSCode commit message window was empty and functioned just as if I had no git hook, but the resulting commit message did reflect the results of the hook.

  • Here is the prepare-commit-msg hook I use, which simply adds <current-branch-name> - to the front of each commit where <current-branch-name> is the actual name of the current branch.

#!/bin/bash

# You can copy this to a repo as `.git/hooks/prepare-commit-msg`, or
# Add to global .gitconfig and global hooks folder with git config --global core.hooksPath ./hooks
# also had to make executable `chmod u+x ./hooks/prepare-commit-msg`

# This way you can customize which branches should be skipped when
# prepending commit message.
if [ -z "$BRANCHES_TO_SKIP" ]; then
  BRANCHES_TO_SKIP=(master develop test)
fi

BRANCH_NAME=$(git symbolic-ref --short HEAD)
BRANCH_NAME="${BRANCH_NAME##*/}"

BRANCH_EXCLUDED=$(printf "%s\n" "${BRANCHES_TO_SKIP[@]}" | grep -c "^$BRANCH_NAME$")
BRANCH_IN_COMMIT=$(grep -c "\[$BRANCH_NAME\]" $1)

if [ -n "$BRANCH_NAME" ] && ! [[ $BRANCH_EXCLUDED -eq 1 ]] && ! [[ $BRANCH_IN_COMMIT -ge 1 ]]; then
  sed -i.bak -e "1s/^/$BRANCH_NAME - /" $1
fi

Screenshot:
Screen Shot 2019-04-01 at 10 19 40 AM

@vscodebot vscodebot bot added the git GIT issues label Apr 1, 2019
@joaomoreno joaomoreno added bug Issue identified by VS Code Team member as probable bug help wanted Issues identified as good community contribution opportunities labels Apr 2, 2019
@joaomoreno joaomoreno added this to the Backlog milestone Apr 2, 2019
@mliq
Copy link
Author

mliq commented Jun 1, 2019

There is a new bug where CMD+A no longer selects all text in the commit window, making the workaround to this bug much more egregious 😞

@joaomoreno
Copy link
Member

@mliq That might happen due to a keybinding you have defined... can you double check?

@mliq
Copy link
Author

mliq commented Jun 6, 2019

@joaomoreno I did check that, can't see what the issue is but maybe you can? (Same keybindings I've had for about a year and the problem only started now)
Screen Shot 2019-06-05 at 9 47 58 PM

@joaomoreno
Copy link
Member

joaomoreno commented Jun 6, 2019

Maybe let's try to repro this in a new user data dir:

code --user-data-dir $(mktemp -d) --extensions-dir $(mktemp -d)

Still happens?

@mliq
Copy link
Author

mliq commented Jun 11, 2019

Solved: I had a ~/.stCommitMsg file referenced in my global git config as:

[commit]
	template = /Users/mliq/.stCommitMsg

I suspect that SourceTree created this file by taking the code from my prepare-commit-msg hook and inserting it as a text template in my git config 😠

@mliq mliq closed this as completed Jun 11, 2019
@vscodebot vscodebot bot locked and limited conversation to collaborators Jul 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug git GIT issues help wanted Issues identified as good community contribution opportunities
Projects
None yet
Development

No branches or pull requests

2 participants