On 25.07.2019 6:09, Ben Pfaff wrote: > On Wed, Jul 24, 2019 at 08:25:54PM +0300, Ilya Maximets wrote: >> On 24.07.2019 20:05, Ben Pfaff wrote: >>> Signed-off-by: Ben Pfaff <[email protected]> >>> --- >>> Based on an off-lst discussion with Ilya. This is just my first, off-hand >>> thought on the topic. Feedback welcome! >> >> We could also consider suggesting a git hook like that: >> --- >> $ cat .git/hooks/pre-push >> #!/bin/bash >> >> remote=$1 >> protected_remote='upstream' >> >> if [ $protected_remote != $remote ]; then exit 0; fi >> >> echo "You're about to push to $protected_remote." >> >> read -p "Do you want to proceed? [y|n] " reply < /dev/tty >> if echo $reply | grep -E '^[Yy]$' > /dev/null; then exit 0; fi >> >> exit 1 >> --- > > Have you tried this? How does it work for you in practice?
Yes. It works for me. 'exit 1' from the script fails the hook and disallows further push processing. I have a remote named "upstream": $ git remote -v <...> upstream https://github.com/openvswitch/ovs.git (fetch) upstream https://github.com/openvswitch/ovs.git (push) <...> Push to that remote: $ git push upstream HEAD:master --dry-run Username for 'https://github.com': username Password for 'https://[email protected]': You're about to push to upstream. Do you want to proceed? [y|n] y To https://github.com/openvswitch/ovs.git d560bc1ba..959dce495 HEAD -> master $ git push upstream HEAD:master --dry-run Username for 'https://github.com': username Password for 'https://[email protected]': You're about to push to upstream. Do you want to proceed? [y|n] n error: failed to push some refs to 'https://github.com/openvswitch/ovs.git' Push to any other remote: $ git push origin HEAD:master --dry-run To ssh://gerrit:29418/ovs c34a87b6c..959dce495 HEAD -> master Few notes why this hook might not work: * Need to replace: s/upstream/<name of the github.com/openvswitch/ovs.git remote>/ * The hook file should be executable. * I guess, there might be issues accessing /dev/tty, but It's unclear what to do in this case. I also added some colours locally to make the warning more visible: echo -e "You're about to push to \e[91m$protected_remote\e[39m." Best regards, Ilya Maximets. _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
