user1482764
user1482764

Reputation: 49

Git pull hook script which executes locally

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

Answers (2)

eckes
eckes

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:

  • use git bord means and call the alias safepush/safepull or something like that
  • set up an alias in your .bashrc for git pull and git push (see this question on SU for setting up multiword aliases which are actually functions)

Upvotes: 2

Frost
Frost

Reputation: 11977

I believe you're looking for Git hooks.

You will have to put the hooks there yourself though. I don't think you can make the user pull the (client-side) hooks along with the rest of the code.

Upvotes: 1

Related Questions