Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 627379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:31:19+00:00 2026-05-13T19:31:19+00:00

We’re using git with a central repo (using Gitosis). I’ve created a post-receive hook

  • 0

We’re using git with a central repo (using Gitosis). I’ve created a post-receive hook to generate an email to the dev mailing list whenever changes are pushed to the central repo, and to generate documentation from the documentation folder in the git repo.

Therefore, in ~git/ I’ve got a directory, we’ll call it ‘a’ that contains a clone of the git repo. The post-receive hook looks like:

#!/bin/bash
cd ~git/repositories/a.git
. ~git/post-receive-email &> /dev/null
( cd ~git/a && git pull &> ~git/pull_log.log && php ~git/a/scripts/generate_markdown_documentation.php &> ~git/doc_log.log )

The email script is working, but the documentation generation is not. The content of pull_log.log is:

fatal: Not a git repository: '.'

Which makes me think that it’s not changing to the correct directory in line 5 of the above script. Am I wrong? How can I get this to work?

Edit: I’ve updated the post-receive hook as suggested in the responses. The script is now:

#!/bin/bash
function die {
  echo "$*" >&2; exit 1
}

function checkgit {
  [ -d "$1/.git" ] || die "$1 could not possibly be a git repo; $1/.git is not a dir"
}


cd ~git/repositories/a.git
. ~git/post-receive-email &> /dev/null
( set -x
checkgit ~git/a
cd ~git/a
checkgit .
pwd
git pull
php ~git/a/scripts/generate_markdown_documentation.php )

And I get the following output from git push:

+ checkgit /var/git/a
+ '[' -d /var/git/a/.git ']'
+ cd /var/git/a
+ checkgit .
+ '[' -d ./.git ']'
+ pwd
/var/git/a
+ git pull
fatal: Not a git repository: '.'
+ php /var/git/a/scripts/generate_markdown_documentation.php

Any more help?

Oh, and if I run the script myself, it works (I run it by saying hooks/post-receive)

Discovered the problem, thanks to serverfault — basically, environment variables GIT_DIR and GIT_WORK_TREE are set when the hook runs, and these affect git pull adversely. Unsetting the variables fixes the problem.

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T19:31:19+00:00Added an answer on May 13, 2026 at 7:31 pm

    You need more diagnostics, e.g.,

    function die {
      echo "$*" >&2; exit 1
    }
    
    function checkgit {
      [ -d "$1/.git" ] || die "$1 could not possibly be a git repo; $1/.git is not a dir"
    }
    

    At this point, in the subshell right after the parenthesis, you can try stuff like

    set -x # show exactly what's executed (writes to stderr)
    checkgit ~git/a
    cd ~git/a && checkgit . && git pull ...
    

    You might also consider redirecting the whole stderr of the subshell, e.g.,

    ( ... ) 2>/tmp/mydiagnosis$$.log
    

    (This is a temporary measure and is OK only if there’s no confidential info in the logs.)


    OK Silas, your additional info rules out a lot of awkward possibilities. I’m nearing the end of my git fu, but here are some more things to try:

    1. Go into ~git/a and see if you can make it git pull by hand. This should fail.
    2. Got into ~git/a and run git status. This should also fail. If it doesn’t, then git is giving you a very bad error message.

    If both steps fail, ~git/a is not the clone you thought it was. Rename it, make a new clone, and see if you can get the problem to persist.

    If the first step succeeds by hand, then something strange is going on and I’m baffled.

    If the first step fails but the second succeeds, you may have a problem with branches:

    • Perhaps repo ~git/a is set to the wrong branch, and your repo needs a branch it doesn’t have. Try git branch -a and see if you see something unexpected.

    • Perhaps you have the branch, but it’s not properly associated with a remote repository. At this point you have to dive into ~git/a/.git/config, and I don’t really know how to explain what you should expect to find there. At that point you will need a real git expert; I just play one on TV.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 379k
  • Answers 379k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you are unable to use SSL for some reason… May 14, 2026 at 9:32 pm
  • Editorial Team
    Editorial Team added an answer You have to encode special characters in URLs. See: http://www.w3schools.com/tags/ref_urlencode.asp May 14, 2026 at 9:32 pm
  • Editorial Team
    Editorial Team added an answer You can define one by appending the equals sign to… May 14, 2026 at 9:32 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.