-
Notifications
You must be signed in to change notification settings - Fork 37
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
Support for git push options #79
Comments
@esaborg: what kind of data you want to pass from git push? |
@seletskiy: Here's my use case. With certain criteria I want to lock I know this is likely quite niche use case, but I believe there could be also other cases where which would benefit from the ability to add extra string info to the push. |
Hi, I see now, the use case is pretty simple and reasonable. Unfortunately, I don't see any way to pass any variable with I think you can implement a workaround by adding a git tag on your branch and then pushing it to the remote repository with Or you can push any file with special contents and check that file in your hook. (a dirty way, in my opinion) Please let me know if it is working for you or no. |
@esaborg: another way for your specific case is to create another user and push sensitive changes using key assigned to this username. In the hook itself you can add logic to restrict changes for given username only. |
@kovetskiy As I understand, git push supports Adding a special file or tag would work as a dirty workaround. Creating a special user for this as @seletskiy suggests doesn't work as nicely since I would like any user to be able to push the changes. The trick is that having a hook like this would prevent the accidental pushed when |
I beg your pardon, git push indeed supports push options. I made small research and you even can do it in bitbucket with External Hooks plugin. Let's imagine some simple PreReceive hook: #!/bin/bash
set -euo pipefail
enforced=false
if [[ "${GIT_PUSH_OPTION_COUNT:-}" && "${GIT_PUSH_OPTION_COUNT}" != "0" ]]; then
for (( index=0; index<$GIT_PUSH_OPTION_COUNT; index++ )); do
option_env="GIT_PUSH_OPTION_${index}"
option=${!option_env}
echo "option #${index}: ${option}"
if [[ "$option" == "enforce" ]]; then
enforced=true
fi
done
fi
if $enforced; then
exit 0
fi
echo "Sorry, git push to this repository is temporarily disabled." >&2
exit 1
The script will not allow a user to push unless
The only problem is that by default git push options are not allowed in repositories, so when you push you will receive the following error:
I didn't find any more elegant way to allow it except modifying file in $BITBUCKET_HOME/shared/config/git/system-config and adding following lines at the end of file:
With this configuration it's possible to do what you want. Push without options:
Push with a few but push options:
And finally, push with enforce flag:
Hope it is helpful for you. |
Thank, that's exactly what I was looking for. For some reason that script does not work on my environment. To be more specific, the environment variables remains unset for some reason. Adding the I'm running |
@esaborg did you resolve the issue? |
I would find it very useful to be able to send extra strings to pre receive hook from git push command.
The text was updated successfully, but these errors were encountered: