Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #71903
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <fomcl@yahoo.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'repository': 0.05; 'url:bitbucket': 0.05; '-*-': 0.07; 'error:': 0.07; 'linux,': 0.07; 'reject': 0.07; 'revision': 0.07; 'sys': 0.07; 'users,': 0.07; '"__main__":': 0.09; '__name__': 0.09; 'exceeds': 0.09; 'git': 0.09; 'mode:': 0.09; 'python': 0.11; 'def': 0.12; 'wrote': 0.14; 'windows': 0.15; '#####': 0.16; '(should': 0.16; '*must*': 0.16; '.py': 0.16; '100644': 0.16; '8bit%:1': 0.16; 'cmd': 0.16; 'fetches': 0.16; 'item:': 0.16; 'lambda': 0.16; 'os.getcwd()': 0.16; 'skip:~ 20': 0.16; 'skip:\xa0 70': 0.16; 'specifying': 0.16; 'subject:skip:e 10': 0.16; 'subject:windows': 0.16; 'url:peps': 0.16; 'windows?': 0.16; '(0)': 0.16; 'url:)': 0.16; 'commit': 0.19; 'addition,': 0.20; 'import': 0.22; 'print': 0.22; 'error': 0.23; 'bytes': 0.24; 'config': 0.24; 'url:dev': 0.24; 'header:Received:8': 0.24; 'script': 0.25; 'least': 0.26; 'tried': 0.27; 'mode': 0.30; 'skip:g 30': 0.30; "skip:' 10": 0.31; 'initialized': 0.31; 'pipe': 0.31; 'file': 0.32; 'supposed': 0.32; 'thanks!': 0.32; 'option': 0.32; 'url:python': 0.33; '(e.g.': 0.33; 'skip:# 10': 0.33; 'skip:s 30': 0.35; 'but': 0.35; 'add': 0.35; 'version': 0.36; 'really': 0.36; '8bit%:9': 0.36; 'otherwise.': 0.36; 'skip:~ 10': 0.36; 'done': 0.36; 'hi,': 0.36; 'url:org': 0.36; 'should': 0.36; 'feedback': 0.38; 'system,': 0.38; 'skip:. 20': 0.38; 'to:addr:python-list': 0.38; 'files': 0.38; 'does': 0.39; '\xa0\xa0\xa0': 0.39; 'to:addr:python.org': 0.39; 'changed': 0.39; 'how': 0.40; 'read': 0.60; '8bit%:29': 0.60; 'received:98.137': 0.60; 'name': 0.63; 'maximum': 0.63; 'total': 0.65; 'header:Reply-To:1': 0.67; 'received:gq1.yahoo.com': 0.68; 'received:mail.gq1.yahoo.com': 0.68; 'subject: & ': 0.68; 'received:98.136': 0.69; 'below.': 0.71; '8bit%:100': 0.72; 'apart': 0.72; 'touch': 0.74; 'received:bullet.mail.gq1.yahoo.com': 0.84; 'skip:/ 30': 0.84; 'us?': 0.84; 'medicine,': 0.91; 'education,': 0.96 |
| X-Yahoo-Newman-Property | ymail-4 |
| X-Yahoo-Newman-Id | 171078.1746.bm@omp1009.mail.gq1.yahoo.com |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1400777938; bh=15laefDNQRbkWLvQXSejoWBhXkv5fneAnK/bFNrltes=; h=Message-ID:Date:From:Reply-To:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=D3ITUDRyWTjZzGl7W540lcDwkRGEQUzbx7N35aMm0ZCtvk3diyXZfCeS/oVjKIQn99Wibxc7Gt42DDXxr8UBog4yz7nBc7PJ0OGrFjRoGb3UDTKukLe7Zs9G4Kvc8ehFw6tm3oWXRJcZMI29cp8F89InQfOVdlcWL4TmBx3tk3c= |
| X-YMail-OSG | e8xQyx8VM1ljecL8MnSHevWbq9CzgRVRqWfgZCbxwFOtgBZ ndUSBqj3iXu5zy45odlExA3r.Th.CZDb.dvffCI5ljlmJ.wXyV5Fr0njfPVM FkWfTLRslYIgHKEjDV90leAxzy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WebService/0.8.188.663 |
| Date | Thu, 22 May 2014 09:58:57 -0700 (PDT) |
| From | Albert-Jan Roskam <fomcl@yahoo.com> |
| Subject | shebang & windows: call an extensionless git hook |
| To | Python <python-list@python.org> |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=iso-8859-1 |
| Content-Transfer-Encoding | quoted-printable |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| Reply-To | Albert-Jan Roskam <fomcl@yahoo.com> |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.10227.1400778299.18130.python-list@python.org> (permalink) |
| Lines | 51 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1400778299 news.xs4all.nl 2958 [2001:888:2000:d::a6]:52729 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:71903 |
Show key headers only | View raw
Hi,
I wrote the git pre-commit hook below. It is supposed to reject commits that contain large files (e.g. accidental commits by inexperienced users, think of "git add .")
Anyway, I tried this under Linux, but the target platform is Windows. As per Git design the hook name *must* be "pre-commit" (no .py extension). How will Windows know that Python should be run? And (should it be relevant): how does Windows know which Python version to invoke? I read about custom shebangs with Pylauncher. Is that my only option? (see: https://bitbucket.org/vinay.sajip/pylauncher, http://legacy.python.org/dev/peps/pep-0397/)
In addition, I would really appreciate general feedback on the hook script below.
Thanks!
Albert-Jan
albertjan@debian ~/Desktop/test_repo $ git config --global init.templatedir ~/Desktop/git_template_dir
albertjan@debian ~/Desktop/test_repo $ cd ~/Desktop/git_template_dir
albertjan@debian ~/Desktop/git_template_dir $ cat hooks/pre-commit
#!/usr/bin/python
#-*- mode: python -*-
"""Git pre-commit hook: reject large files"""
import
sys
import os
import re
from subprocess import Popen, PIPE
def git_filesize_hook(megabytes_cutoff=5, verbose=False):
"""Git pre-commit hook: Return error if the maximum file size in the HEAD
revision exceeds <megabytes_cutoff>, succes (0) otherwise. You can bypass
this hook by specifying '--no-verify' as an option in 'git commit'."""
if verbose: print os.getcwd()
cmd = "git ls-tree --full-tree -r -l HEAD"
git = Popen(cmd, shell=True, stdout=PIPE, cwd=os.getcwd())
get_size = lambda item: int(re.split(" +",
item)[3].split("\t")[0])
sizes = map(get_size, git.stdout.readlines())
cut_off_bytes = megabytes_cutoff * 2 ** 20
if max(sizes) > cut_off_bytes:
return ("ERROR: your commit contains at least one file "
"that is larger than %d bytes" % cut_off_bytes)
return 0
if __name__ == "__main__":
sys.exit(git_filesize_hook(0.000001, True))
albertjan@debian ~/Desktop/git_template_dir $ cd -
/home/antonia/Desktop/test_repo
albertjan@debian ~/Desktop/test_repo $ git init ## this also fetches my own pre-commit hook from template_dir
Initialized empty Git repository in /home/antonia/Desktop/test_repo/.git/
albertjan@debian ~/Desktop/test_repo $ touch foo.txt
albertjan@debian ~/Desktop/test_repo $ git add foo.txt
albertjan@debian ~/Desktop/test_repo $ ls -l .git/hooks
total 4
-rw-r--r-- 1 albertjan albertjan 1468 May 22 14:49 pre-commit
albertjan@debian ~/Desktop/test_repo $ git commit -a -m "commit" ##### hook does not yet work
[master (root-commit) dc82f3d] commit
0 files changed
create mode 100644 foo.txt
albertjan@debian
~/Desktop/test_repo $ chmod +x .git/hooks/pre-commit ###### can I avoid this in Linux? What should I do in Windows?
albertjan@debian ~/Desktop/test_repo $ echo "blaah\n" >> foo.txt
albertjan@debian ~/Desktop/test_repo $ git commit -a -m "commit" ##### now the hook does its job
/home/antonia/Desktop/test_repo
ERROR: your commit contains at least one file that is larger than 1 bytes
Regards,
Albert-Jan
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a
fresh water system, and public health, what have the Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
shebang & windows: call an extensionless git hook Albert-Jan Roskam <fomcl@yahoo.com> - 2014-05-22 09:58 -0700
csiph-web