githooks

`git diff` does not work when run from a git pre-commit hook

落花浮王杯 提交于 2019-12-24 00:54:49
问题 I have a git pre-commit hook that does some style checking on any modified files before committing. The implementation is irrelevant, but it starts by calling git diff . Here's what i have in (repo)/.git/hooks/pre-commit . #!/bin/sh echo "=== Running script..." git diff echo "=== Done running script..." # Other stuf # .... # Always exit with 1 so pre-commit hook always fails. # Useful for testing exit 1 When I actually try committing something, the pre-commit hook correctly fires, but the git

git init template, replacing modified hooks

天大地大妈咪最大 提交于 2019-12-23 17:06:13
问题 I am constantly updating my local git hooks. I have a repo to house my .git template. This means that I am constantly running git init --template=../git-template to update repos with my hook changes. Problem: Everytime I run git init --temp..., I need to first remove the hooks in .git/hooks that will be replaced with the updated hooks. This is annoying. I know I can script the removal of these hooks from the repo that I want to update, but is this functionality built into git already? 回答1:

git pre-commit hook to format and re-add files at the same time

ε祈祈猫儿з 提交于 2019-12-23 15:47:15
问题 We're currently using a git hook (below) to run astyle on our source code before allowing the user to commit. This has the caveat that the user must commit, have their code formatted, then commit again which is a bit of a nuisance. Ideally we'd want the hook to format the code and then include that formatted code in the original commit instead. I've tried re-adding the changed files but it causes ref errors (obviously). I've also tried getting the history in the pre-commit hook and trying to

How to configure a global git hook in GitLab version 11.11?

梦想与她 提交于 2019-12-23 04:55:28
问题 I'm really confused about how to configure a GitLab global hook. The documentation is clear about how to set a global hook. So I login in my GitLab instance, go to the directory /opt/gitlab/embedded/service/gitlab-shell/hooks , and it has 3 files: -rwxr-xr-x 1 root root 131 Jun 10 16:22 post-receive -rwxr-xr-x 1 root root 131 Jun 10 16:22 pre-receive -rwxr-xr-x 1 root root 131 Jun 10 16:22 update All the files have the same content: # cat pre-receive #!/bin/sh echo "The gitlab-shell hooks

How to know the “remote” in git pre-push hook file

ぐ巨炮叔叔 提交于 2019-12-23 04:10:38
问题 In the "pre-push" file, I can get some params using " read local_ref local_sha remote_ref remote_sha ", but I wanna do some restrictions stuff according to the specific remote repo(yes, there's mutiple remote address in my project), so how can I do this? Thanks in advance! 回答1: remote name and url are supplied as parameters to the pre-push. remote="$1 url="$2" will give the information you needed 来源: https://stackoverflow.com/questions/40837679/how-to-know-the-remote-in-git-pre-push-hook-file

Git post-receive hook for push-to-deploy only works with master

懵懂的女人 提交于 2019-12-23 02:47:14
问题 I have a remote bare git repository created following: @server:~$ mkdir -p /home/myuser/domain.git && chmod 770 /home/myuser/domain.git && cd /home/myuser/domain.git && git init --bare With a post-receive hook: @server:~$ nano hooks/post-receive The hook script is: #!/bin/sh git --work-tree=/var/www/domain --git-dir=/home/myuser/domain.git checkout -f It has permission to execute: @server:~$ chmod +x hooks/post-receive However, it only changes the website when I push to the master branch. Why

With a git hook, how do I force or check user identity?

拟墨画扇 提交于 2019-12-23 02:47:13
问题 I'm trying to setup a gitolite server. One problem that I find annoying in git is the username is not checked when committing code. This can lead to a possible "identity phishing" where user1 can commit some bogus code and set user2 as username. Then we'll blame user2. I'm looking for a way to check or force the username to be consistent with the committer's identity. 回答1: You can sign your commits using: git commit -S (only available since git 1.7.9) You can then use a server-side git hook

Git post-receive hook not working properly

时光总嘲笑我的痴心妄想 提交于 2019-12-23 02:36:30
问题 I have a server with a git repository. Each time I make a push to that server I would like to regenerate my gitstats documentation for that repository. In that machine if I execute the following command, the gitstats documentation it's refreshed properly: gitstats /home/<username>/<proyect-name>/htdocs/ /home/<username>/gitstats And here it's my post-receive hook in the repository in that server: #!/bin/sh gitstats /home/<username>/<proyect-name>/htdocs/ /home/<username>/gitstats So when I

Setting environment variable through SSH git push

泄露秘密 提交于 2019-12-23 01:36:22
问题 I'm reading Scott Chacon's Git book, and just wanted to confirm something. This part: You also have access to the user doing the pushing if the push is being run over SSH. If you’ve allowed everyone to connect with a single user (like “git”) via public-key authentication, you may have to give that user a shell wrapper that determines which user is connecting based on the public key, and set an environment variable accordingly. Here we’ll assume the connecting user is in the $USER environment

Git post-receive - how to check if pushed branch is merged with master

倾然丶 夕夏残阳落幕 提交于 2019-12-22 14:51:53
问题 In our team we are usually pushing all tasks into separate branches, and after that release-manager review those branches and merge them into 'master' branch Sometimes team-members forget to merge their branches with master branch(before pushing) - so what I'm trying to do is - output a message "Please merge with master" after user push - I assume I need to check something on post-receive hook on remote.. is there some examples?.. or what I should basically do ? update: main reason for this -