Junaid Qadir Shekhanzai
Junaid Qadir Shekhanzai

Reputation: 1425

Error in post-receive hook

I'm trying to implement a work-flow using git. Here's what I did:

When I push using git push xyz-branch dev --force, I get the following errors:

remote: Checking out /path/to/xyz
remote: Run: checkout dev
remote: fatal: Not a git repository: '.'
remote: Run: git clean -df & git checkout dev
remote: fatal: Not a git repository: '.'
remote: Run: git submodule update --init 
remote: Checking out sumodules
remote: fatal: Not a git repository: '.'
remote: Setting access rights on files and folders
remote: Run: chmod 755 -R /path/to/xyz/

I don't know should I blame the docs or myself for mot understanding the cause of the error.

Update

I was doing many things wrong.Thanks to a twitter friend who pointed out this SO question and I solved my problem. I think it's OK if I explain it as an answer.

Upvotes: 0

Views: 464

Answers (1)

Junaid Qadir Shekhanzai
Junaid Qadir Shekhanzai

Reputation: 1425

Thanks to my twitter friend (dotNet and Azure guru) Ilija for pointing me to the right direction. I was able to achieve my goal after reading through the SO post I've mentioned in the OP.

Here's what I did:

#!/bin/bash
export GIT_WORK_TREE=/path/to/xyz
export GIT_DIR=/path/to/xyz/.git
cd $GIT_WORK_TREE 
echo "Checking out dev"
git checkout dev
git clean -df & git checkout dev
unset GIT_WORK_TREE
unset GIT_DIR
echo "Checking out sumodules"
mkdir "codeigniter"
git submodule update --init 
echo "clean"
echo "Setting access rights on files and folders"
echo "Run: chmod 755 -R $GIT_WORK_TREE"
cd "$GIT_WORK_TREE"
chmod 755 -R "$GIT_WORK_TREE"
echo "Done."

export was the the key to solving my issue.

Please note two unset commands. I ran them as my repo has a submodule. To have the submodule fetch smooth.

Upvotes: 1

Related Questions