git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: process committed files in post-receive hook

From
NKNeal Kreitzinger <nkreitzinger@gmail.com>
Date
Dec 15, 2011, 01:04 UTC
Message-ID
<4EE94783.1010805@gmail.com>
In-Reply-To
<loom.20111210T111457-837@post.gmane.org>
On 12/10/2011 4:29 AM, Hao wrote:
Show 25 quoted lines
> Hi guys,
>
> I am writing a post-receive hook in Python that examines the content
> of some files (the HEAD rev). Because the repo is a bare one on the
> server. My current approach is to check out a working copy on the
> server and run 'git pull' in post- receive to get the most up-to-date
> version, and then process files in the working copy.
>
> I have two questions. First, is there a way that I can access file
> content in a bare repo without checking out a working copy? If this
> is not possible, my approach would be reasonable. However, when 'git
> pull' was called in the python script post-receive when a commit
> occurs, it gives an error.
>
> remote: fatal: Not a git repository: '.'
>
> The call in python is
>
> subprocess.Popen(["git", "pull"],
> cwd="/Users/git/ts.git.workingcopy")
>
> I read from a post (http://stackoverflow.com/questions/4043609/) that
> GIT_DIR is causing this error. Is it safe to unset GIT_DIR in
> post-receive?
>

The specific processing you intend to perform on the files would determine which of the access techniques is appropriate for you. Generally speaking, I think a checkout in a non-bare repo makes sense. You could limit it to a shallow clone (see git-clone manpage) to save space.

Another way to get the files is git-archive (creates tar file), that you could extract to a dir for processing.

In both cases, you need to consider the default permissions in play with git-checkout and git-archive if permissions are important in your processing.

v/r, neal

Previous: Alexey ShumkinNext: Hao Wang
Message 5 of 8 in “process committed files in post-receive hook”
  1. HaoDec 10, 2011
  2. Michael SchubertDec 10, 2011
  3. Ivan HeffnerDec 10, 2011
  4. Alexey ShumkinDec 10, 2011
  5. Neal KreitzingerDec 15, 2011
  6. Hao WangDec 15, 2011
  7. Jeff KingDec 15, 2011
  8. Hao WangDec 15, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.