Reputation: 736
I am writing gitosis
post-push hook for central repository
which pulls updates from central repository to testing enviroment
nano /var/git/repositories/holding.git/hooks/post-update
#!/bin/bash
cd /var/vh/holding;
git reset --hard;
git checkout testing;
git pull;
here what I get after push on my client (development VM)
# blah ...
Counting objects: 57, done.
Compressing objects: 100% (24/24), done.
Writing objects: 100% (30/30), 3.42 KiB, done.
Total 30 (delta 18), reused 0 (delta 0)
fatal: Not a git repository: '.'
fatal: Not a git repository: '.'
fatal: Not a git repository: '.'
fatal: Not a git repository: '.'
To [email protected]:holding.git
233b5a2..0f46cd8 testing -> testing
Obviously, my attempt to tell git, where it should do pull, failed.
What is correct way to run git command for a specified working copy in bash script?
Upvotes: 12
Views: 42499
Reputation: 149
We can use the --git-dir
parameter to specify the path to .git
.
For example: we can call git log
like this:
git --git-dir=<path to git cloned dir>/.git log
Upvotes: 0
Reputation: 3187
For me, preceding with env -i
does not work. I always get this error:
*** Please tell me who you are.
Although I've set the global config. This is what works for me by specifying --git-dir
parameter:
#!/bin/sh
GIT='git --git-dir='$PWD'/.git'
$GIT checkout hotfix
$GIT merge --no-ff master -m "Merged master"
$GIT push
I run the script inside the working directory hence I use $PWD
to get current working directory. You may adjust as necessary.
Upvotes: 2
Reputation: 49008
Is /var/vh/holding
a git repository? i.e. have you run git init
on it, set up your remotes, set it to track your holding.git directory, etc.? Also, if you're not pulling from the same repo you're pushing to, you shouldn't need the reset
and checkout
.
Upvotes: 0