githooks

git commit in pre-push hook

允我心安 提交于 2019-12-01 02:31:57
I have added something like that in pre-push hook: gs0=$(git status) pip-dump gs1=$(git status) if [ "gs0" != "gs1" ] then git commit -m "pip-dump" fi (this is updating my pip requirements file) It seems that the push is not pushing the new commit, but the one which the HEAD was on at the beginning of the script. How to fix that? You can't: the push command figures out which commits to push before invoking the hook, and pushes that if the hook exits 0. I see three options: Exit nonzero, telling the user "push rejected because I added a commit" Exit zero, telling the user "push went through but

Git hook for any action that updates the working directory

时光总嘲笑我的痴心妄想 提交于 2019-12-01 00:19:50
Following an answer to a previous question , I implemented a Git hook script which needs to fire whenever the working directory is updated. I linked this script to the following in .git/hooks: post-checkout post-commit post-merge This mostly works, but not always. One case I found is git stash . This is a problem because my hook generates a text file wihch I also mark with git update-index --assume-unchanged to tell Git that I don't want to check in changes (an empty version is checked in). However, git stash will revert the assume-unchanged file (to the empty file), which means the hook needs

git diff during pre-commit hook results in Not a git repository

假装没事ソ 提交于 2019-11-30 22:21:57
I'm trying to build a pre-commit script in git. In that script I plan on running tasks if a certain folder has changed. To test, in my script I have git diff --cached | grep -q "^my/folder" This results in... Not a git repository To compare two paths outside a working tree: usage: git diff [--no-index] <path> <path> pwd says I'm in the correct directory and $GIT_DIR is .git . I was lead to belive that --cached was the special sauce to get this working in a hook. Is there a way to do this? Even though GIT_DIR is set, I would still try a: git --git-dir=/full/path/to/repo/.git --work-tree=/full

git post-commit hook - script on committed files

点点圈 提交于 2019-11-30 20:24:32
Can I see somewhere an example post-commit hook to run a script on each committed file? eg. git add file1 git add file2 git commit -am "my commit" and the hook executes: myscript -myparams "file1" myscript -myparams "file2" The best would be to have parameter to commit command to run this hook or not, eg. git commit -X … executes this post commit hook. Eventually an alias like git-commitx . How about the same version as a pre-commit hook on files in index? Can I abort a commit when execution of the scripts fails on one of the files? Edit: Here is what I have now: #!/bin/sh #.git/hooks/post

git diff during pre-commit hook results in Not a git repository

六月ゝ 毕业季﹏ 提交于 2019-11-30 17:50:05
问题 I'm trying to build a pre-commit script in git. In that script I plan on running tasks if a certain folder has changed. To test, in my script I have git diff --cached | grep -q "^my/folder" This results in... Not a git repository To compare two paths outside a working tree: usage: git diff [--no-index] <path> <path> pwd says I'm in the correct directory and $GIT_DIR is .git . I was lead to belive that --cached was the special sauce to get this working in a hook. Is there a way to do this? 回答1

Why is my Git pre-commit hook not executable by default?

瘦欲@ 提交于 2019-11-30 17:33:34
If you see the accepted answer in: Aggregating and uglifying javascript in a git pre-commit hook , you'll see that I had to do a chmod +x on my pre-commit hook to get it to work. Why is this not executable by Git by default? Because files are not executable by default; they must be set to be executable. The sample files from a git init are all executable; if it's copied or renamed to a non-sample file, it will retain the original file's x flag. New files will be created with current defaults. In your case, view those defaults with umask : $ umask 0022 By default, new files won't be u+x unless

How do I check for valid Git branch names?

独自空忆成欢 提交于 2019-11-30 17:20:09
I'm developing a git post-receive hook in Python . Data is supplied on stdin with lines similar to ef4d4037f8568e386629457d4d960915a85da2ae 61a4033ccf9159ae69f951f709d9c987d3c9f580 refs/heads/master The first hash is the old-ref, the second the new-ref and the third column is the reference being updated. I want to split this into 3 variables, whilst also validating input. How do I validate the branch name? I am currently using the following regular expression ^([0-9a-f]{40}) ([0-9a-f]{40}) refs/heads/([0-9a-zA-Z]+)$ This doesn't accept all possible branch names, as set out by man git-check-ref

How to get ALL hashes that are being committed in a pre-receive hook?

为君一笑 提交于 2019-11-30 15:47:16
I am writing a pre-receive hook for Git. This is the one where if multiple commits are pushed, and any one of them fail, then the whole push fails. Which is what I want. My problem is that not all the hashes from all commits are passed in. Only the most recent commit hash is, e.g. 2 commits are being pushed to a repo: Commit 1 - 4b5w<br> Commit 2 - 6gh7 -------------> passed in to pre-receive hook, but I want the previous hash too. I can't use the update hook which is called for each ref, because I don't want any commits to go through if any one of them fails, e.g. commit 1 passing and commit

Minify CSS files via git hook

好久不见. 提交于 2019-11-30 13:18:08
问题 My ideal situation is to automatically minify CSS files and add them to the git commit. I'm not sure if #4 below can be done, but I would like the following flow to be performed: Modify CSS file Add to staging area Commit Run script that updates the minified files and adds them to the commit Commit completes If there is another way, I'd be interested in that as well. 回答1: Whether you should is another matter, but you can. in .git/hooks/, write a script in your language of choice (make sure it

Make Github push to a remote server when it receives updates

北战南征 提交于 2019-11-30 12:36:13
What is the set up for having Github automatically push any updates to a remote server? This is useful for maintaining a codebase on Github, and having a website run off that codebase. I have my repo on my own computer, this is where I work. I commit my changes on my local repo, and push them to my Github repo. I want my Github repo to then push these changes to my remote server. I've been researching all day, and using the 'hooks' sounds reasonable. Maybe using a 'post-receive' hook on Github which then runs a push command to my remote server. Any suggestions? As I understand github doesn't