Reputation: 49
I want to prompt for the confirmation [yes/no] for every the commands git push and pull which contacts the git server. Is there a way to include any commands/scripts to make this happen? so User can able to given the input, after that only git proceeds for that operation.
Upvotes: 3
Views: 4548
Reputation: 67137
First of all, I don't think that you will make much friends with that change. If someone types in git pull
, he already proved that he's willing to contact the remote server. In my opinion, there's no need to annoy the user with confirm dialogs in that case.
Anyway, if you want to confirm every pull
and push
, hooks are not the right tool since the pull/push hooks only exist on the server side. There are no pre-pull
, post-pull
, pre-push
or post-push
hooks on the client side. So, we have to discard the hook idea.
You could alias the pull
and push
commands instead to surround them with the query whether there should really be pulled/pushed or not.
The query is simple:
echo -n "really push? [y/n] "
read -s -n 1 really
if [[ $really == "y" ]]; then
# PULL/PUSH HERE
else
echo "aborting"
fi
Unfortunately, you can't use the same name for an alias. So, the easy thought of
[alias]
push = "!echo -n \"really push? [y/n]\";read -s -n 1 really;if [[ $really == \"y\" ]];then git push; else echo \"aborting\"; fi"
doesn't work.
But you have two other options to achieve what you want:
safepush
/safepull
or something like that.bashrc
for git pull
and git push
(see this question on SU for setting up multiword aliases which are actually functions)Upvotes: 2