Why isn't my git hook firing? - githooks

I'm trying to write a git hook that fires on git pull, git merge, and git checkout, when my .emacs file changes. For some reason, the hook never seems to fire.
https://github.com/mcandre/dotfiles/blob/master/hooks/post-merge-checkout

osse on #git / #bash helped me identify the issue: I was using the wrong git command to search for file changes. The new one works:
https://github.com/mcandre/dotfiles/blob/594e24d28e599e57b401d3c163d72498b8a3c1f0/hooks/post-merge-checkout

Related

Git react folder in Gitlab

I'm going to make a git to my project include spring and react, as shown below:
after I create a local repo and just push this into gitlab as it told me: btw before I git push I have to write "git pull --rebase origin main", otherwise I can't push my repo to gitlab. But I think that is maybe not the reason.
And afterwards it has problem with the react folder in gitlab, and there is no problem with the spring folder, as shown below: I can't open the react folder in gitlab.
So my question was: why only the react folder has this problem but spring not? and how can I fix it? When I open the react folder by vs code, the version control tool also doesn't work when I made some changes.
Very thankful for answering!
why only the react folder has this problem but spring not?
Because delivery-react is probably a nested Git repository (meaning there is a delivery-react/.git), unless you have a .gitmodules file in your main repository.
If you want to add delivery-react as a regular folder:
git rm --cached delivery-react # no trailing /
git commit -m "Remove nested folder"
git add delivery-react
git commit -m "Add deliver-react"
git push

How to handle git and react project for the first time?

I've installed a react project recently this way:
npx create-react-app projectName
When it successfully installed, apparently the git is also installed on it. Since there is .git directory exist in the root.
From the other side, I created a new project on Gitlab and connected it to the project this way:
git remote add origin http://gitlab.<domain>.com/myName/projectName.git
Now, I want to push a commit on the git named something like "Project Init". But there is no change detected when I run git status. So I cannot add and commit anything.
So, when I run git push origin master I get this error:
hint: 'git pull ...') before pushing again.
When I run git pull origin master, get this error:
fatal: refusing to merge unrelated histories
I stuck in this part ..! What I have to do? In other word, how to synchronise the git and a react project created just now?
Correct way to do it is to create new repo without "initial readme.md commit". Fast way is to git push origin main --allow-unrelated-histories. Or just simply use --force flag in push, but be careful with that
You can use the allow-unrelated-histories flag when pushing.

React through Vscode, I want to push an update to github

I have a Github repo made, and I have pushed an update before, but I did it with help. I still feel pretty lost, what would be the commands to commit the new update to GitHub through Vscode's terminal?
If you have pushed to the repo before, the following commands should do it:
git add .
git commit -m "your commit message"
git push

How to prepend partial branch name to git commit with husky

I have a functional commit-msg git hook that takes the string from beginning up to the first underscore from a git branch's name and prepends it to the commit message.
For better understanding: The branch name is JIRA-123_fix_problem, the commit command goes: git commit -m 'Fix problem' and through the commit-msg hook the commit message will automatically be changed into JIRA-123: Fix problem.
Now we're using Nuxt for our current Vuejs project and this makes use of husky. We want to keep husky in this project. Unfortunately (and, I guess, intentionally), husky works by overwriting the git commit hooks, and thus the file .git/hooks/commit-msg I use will be overwritten by husky and the original commit-msg hook does not work any more.
How can I either prevent husky from overwriting the commit-msg hook or instruct husky to do the same thing?
I can't find any documentation for this problem.
Ok, I finally found (and verified) the soution:
In this husky issue ("Support custom git hooks to be not overridden by husky #323") typicode says:
Husky is overwriting file, because there [is] # husky in it. It checks for this string to know if it's a user script or if it has been generared by husky.
If you delete # husky, it will never overwrite them again.
After I removed the # husky line, re-installing all node modules in our project finally keeps the commit-msg hook I want to use. I originally just copied & pasted the code while maintaining the # husky line from the scaffolding of the project.

How can I manually run a Git pre-commit hook, without attempting a commit?

I just want to be able to run it to see if the code in my working tree passes it, without actually attempting a commit.
Just run the pre-commit script through the shell:
bash .git/hooks/pre-commit
There's a Python package for this available here. Per the usage documentation:
If you want to manually run all pre-commit hooks on a repository, run pre-commit run --all-files. To run individual hooks use pre-commit run <hook_id>.
So pre-commit run --all-files is what the OP is after.
For a single file:
pre-commit run --files YOUR_FILENAME
Just run git commit. You don't have to add anything before doing this, hence in the end you get the message no changes added to commit.

Resources