I've written a very simple 'deploy' script running as my post-update
hook inside my bare git repo.
The variables are as follows
live domain = ~/mydomain.com
staging domain = ~/stage.mydomain.com
git repo location = ~/git.mydomain.com/thisrepo.git (bare)
core = ~/git.mydomain.com/thisrepo.git
core == added remote into each live & stage gits
both live
& stage
have initialized git repos (non-bare) and I have added my bare repo as a remote to each of them (named core
) so that git pull core stage
or git pull core live
would pull the updated files from the respective branch
of the core
repo.
The script is as follows:
#!/usr/bin/env ruby
# Loop over each passed in argument
ARGV.each do |branch|
# If it matches the stage then 'update' the staging files
if branch == "refs/heads/stage"
puts ""
puts "Looks like the staging branch was updated."
puts "Running a tree checkout now…"
puts ""
`cd ~/stage.mydomain.com`
`unset GIT_DIR` # <= breaks!
`git pull core stage`
puts ""
puts "Tree pull completed on staging branch."
puts ""
# If it's a live site update, update those files
elsif branch == "refs/heads/live"
puts ""
puts "Looks like the live branch was updated."
puts "Running a tree checkout now…"
puts ""
`cd ~/mydomain.com`
`unset GIT_DIR` # <= breaks!
`git pull core live`
puts ""
puts "Tree checkout completed on live branch."
puts ""
end
end
I have tried adapting the 'updating' of files from this bash script here which uses the unset GIT_DIR
to run the next git command git pull core stage
for example. core
is the added remote
of my bare
repo in a different folder on the server.
However when executing the script above I'm getting the following errors:
remote: hooks/post-update:35: command not found: unset GIT_DIR
remote: fatal: /usr/lib/git-core/git-pull cannot be used without a working tree.
Is there any way to do the same thing as unset GIT_DIR
in a bash script within my ruby script?
Many thanks,
Jannis