From: Hao Wang <billhao@gmail.com>
To: Neal Kreitzinger <nkreitzinger@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: process committed files in post-receive hook
Date: Wed, 14 Dec 2011 18:02:11 -0800 [thread overview]
Message-ID: <4EE95523.9030702@gmail.com> (raw)
In-Reply-To: <4EE94783.1010805@gmail.com>
Thank you all for providing the options. Just so you know I finally went
with Alexey's suggestion. I used 'git show' to get both a list of files
in a directory and the content of each file. It works great on a bare
repository so there is no need to check out a copy on the server.
Below is the python code in my post-receive hook for this task, where
rev is something like 'HEAD:directory_name' for the first function and
'HEAD:directory/filename' for the second function.
# get a list of rule files using git show
def getRuleFileList(rev):
# run git show
p = subprocess.Popen(['git', 'show', rev], stdout=subprocess.PIPE)
p.wait()
if p.returncode != 0: return None # error
# parse output
i = 0
filelist = []
for line in p.stdout.readlines():
filelist.append(line)
p.stdout.close()
return filelist
# read the content of a file
def readfile(rev):
# run git show
p = subprocess.Popen(['git', 'show', rev], stdout=subprocess.PIPE)
p.wait()
if p.returncode != 0: return None # error
return p.stdout.read()
Hao
On 12/14/11 5:04 PM, Neal Kreitzinger wrote:
> On 12/10/2011 4:29 AM, Hao wrote:
>> 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
next prev parent reply other threads:[~2011-12-15 2:02 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-10 10:29 process committed files in post-receive hook Hao
2011-12-10 11:21 ` Michael Schubert
2011-12-10 12:06 ` Ivan Heffner
2011-12-10 21:31 ` Alexey Shumkin
2011-12-15 1:04 ` Neal Kreitzinger
2011-12-15 2:02 ` Hao Wang [this message]
2011-12-15 7:23 ` Jeff King
2011-12-15 8:19 ` Hao Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4EE95523.9030702@gmail.com \
--to=billhao@gmail.com \
--cc=git@vger.kernel.org \
--cc=nkreitzinger@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).