5

I'm deploying an app to Heroku, which means pushing to their git repo. When do git push heroku master (or the equivalent remote alias) I get this warning:

WARNING: You're about to push to master, is that what you intended? [y|n]

Which is kinda annoying but not a big deal. However, I'm now scripting deployments so I don't want to have interact with the script - how I do get my bash script to answer y automatically?

I tried doing yes | git push heroku master but that doesn't work.

Jaco Pretorius
  • 24,380
  • 11
  • 62
  • 94

3 Answers3

5

Agree with @bk2204, I would check if a git hook is being used that you are unaware of.

Git hooks are not version controlled, so make sure you are searching for this at the machine where you get this error.

The git hook may live elsewhere other than the .git directory. Check if git config core.hooksPath is set and if so, it will point to the directory where your git hook is.

The hook file that you are looking for will most likely have the name pre-push. The solution in this case is to remove or rename this hook file, and git won't run it before push.

Petr Gazarov
  • 3,602
  • 2
  • 20
  • 37
0

Nope, no such file

And yet, this is exactly what a .git/hooks/pre-push would do, like this one.

To rule that out, activate (with your local Git 2.25+) trace2.
That will allow you to see what is used on the client side (your PC) by Git:

git config --global trace2.normalTarget ~/log.normal

Try your push, type 'n' (to abort), and check ~/log.normal for clues.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

Just another way to solve the problem of automating responses to the prompts. You can use expect to take care of interactive warnings/ prompts.

After writing the deployment script deploy.sh, you can write a expect script and spawn the deploy script in it, for response to

WARNING: You're about to push to master, is that what you intended? [y|n]

message, you can send 'y' from expect.

The following snippet can be taken as example

#!/usr/bin/expect -f

spawn bash ./deploy.sh

expect "WARNING: You're about to push to master, is that what you intended? [y|n]\r"

send -- "y\r"
CodeTalker
  • 1,683
  • 2
  • 21
  • 31