0

I am stuck since 2 days trying to set up a small automatic deployment script. The thing is: I have been using Git for some months now, but I always used it locally just by myself, just with the purpose of easily saving version of my code. All good until here.

Now I have to find a way to "publish" the code as soon as new functionalities are implemented and I think the code is stable enough. Searching around I've discovered these 'hooks', which are scripts that are executed by Git in certain situations. Basically the idea is to have my master branch sync'd with my published code, so that everytime I merge a branch to the master and 'push', the files are automatically copied into '/my/published/folder'.

That said, I've found this tutorial that explains to do exactly what I want using a 'hooks' post-receive script, which is written in Ruby. Since at my studio I don't have and don't want to use Ruby at this time, I've found a Python version of the same script. I tested and tested, but I couldn't make it work. I keep getting the same error:

remote: GIT_WORK_TREE is not recognized as as internal or external command,

Consider this is based on the tutorial I've shared above. Same prj name, same structure, etc. I even installed Ruby on my personal laptop and tried the original script, but it still doesn't work...

I'm using Windows, and the Git env variable is set and accessible. But nevertheless it seems like it's not recognizing the GIT_WORK_TREE command. If I run it from the Git Bash it works just fine, but if I use the Windows Shell I get the same error message. I suppose that when in my py script use the call() function, it runs the cmd using the Windows Shell. That's my guess, but I don't really know how to solve it. Google didn't help, as if no one ever had this problem before. Maybe I'm just not seeing something obvious here, but I spent the whole day on this and I cannot get out of this bog!

Does anyone know how to solve it, or at least have an idea for a workaround?

Hope someone can help... Thanks a lot!

  • Possible duplicate of ['git' is not recognized as an internal or external command](http://stackoverflow.com/questions/4492979/git-is-not-recognized-as-an-internal-or-external-command) – user6035379 Nov 01 '16 at 11:39
  • http://stackoverflow.com/questions/15449428/does-the-shell-in-shell-true-in-subprocess-means-bash suggests to use the `executable` parameter. I have no insight into whether this actually works on Windows. If it does, perhaps mark this as a duplicate of that question. – tripleee Nov 01 '16 at 11:58
  • It's not clear what is your environment - where are you going to deploy to? To local folder or to another server? Do you have a remote repository? If not - what means "push"? – Ivan Nov 01 '16 at 12:18
  • @ivan The project was created following the tutorial mentioned above [link](http://krisjordan.com/essays/setting-up-push-to-deploy-with-git). Everything is local, and it's pushing to a local "remote" bare repository! – Enrico Losavio Nov 01 '16 at 12:28
  • Please look at my answer, it seems the problem is with GIT_WORK_TREE environment variable definition – Ivan Nov 01 '16 at 12:32

2 Answers2

0

The Ruby script you are talking about generates "bash" command:

GIT_WORK_TREE=/deploy/path git checkout -f ...

It means: define environment variable "GIT_WORK_TREE" with value "/deploy/path" and execute "git checkout -f ...". As I understand it doesn't work for Windows command line. Try to use something like:

set GIT_WORK_TREE=c:\temp\deploy && git checkout -f ...
Ivan
  • 3,084
  • 4
  • 21
  • 22
0

I've had this problem as well - the best solution I've found is to pass the working tree across as one of the parameters

git --work-tree="/deploy/path" checkout -f ...
Jon Allen
  • 335
  • 1
  • 9