1
0
mirror of https://github.com/oskar456/dzonegit.git synced 2024-05-11 05:55:41 +00:00

Stub pre-receive hook

This commit is contained in:
Ondřej Caletka
2018-07-16 13:13:15 +02:00
parent d26d5a8ebb
commit e3abe11448
3 changed files with 48 additions and 0 deletions

View File

@ -316,6 +316,38 @@ def pre_receive(stdin=sys.stdin):
do_commit_checks(against, revision)
def post_receive(stdin=sys.stdin):
"""Checkout the repository to a path specified in the config.
Re-generate config files using defined templates. Issue reload
commands for modified zone files, issue reconfig command if zones were
added or delefed.
"""
suffixes = list(str(n) if n else "" for n in range(10))
for s in suffixes:
d = get_config("dzonegit.checkoutpath{}".format(s))
if d:
print("Checking out repository into {}".format(d))
subprocess.run(
["git", "checkout", "-f", "master"],
check=True,
env=dict(os.environ, GIT_WORK_TREE=d),
)
# TODO config
if stdin.isatty():
raise SystemExit(
"Standard input should be redirected. Not issuing any reload "
"commands.",
)
for line in stdin:
against, revision, refname = line.rstrip().split(" ")
if refname != "refs/heads/master":
continue
if against == "0000000000000000000000000000000000000000":
against = get_head() # Empty commit
# TODO reloads
def main():
name = Path(sys.argv[0]).name
print(name)
@ -325,6 +357,8 @@ def main():
update()
elif name == "pre-receive":
pre_receive()
elif name == "post-receive":
post_receive()
else:
sys.exit("No valid command found")

View File

@ -17,6 +17,7 @@ setup(
"dzonegit = dzonegit:main",
"dzonegit-pre-commit = dzonegit:pre_commit",
"dzonegit-pre-receive = dzonegit:pre_receive",
"dzonegit-post-receive = dzonegit:post_receive",
"dzonegit-update = dzonegit:update",
],
},

View File

@ -267,3 +267,16 @@ def test_pre_receive(git_dir):
dzonegit.pre_receive(stdin)
stdin = StringIO(revisions + "refs/heads/master\n")
dzonegit.pre_receive(stdin)
def test_post_receive(git_dir):
git_dir.chdir()
revisions = "{} {} ".format("0"*40, dzonegit.get_head())
stdin = StringIO(revisions + "refs/heads/master\n")
codir1 = git_dir.mkdir("co1")
codir2 = git_dir.mkdir("co2")
subprocess.call(["git", "config", "dzonegit.checkoutpath", str(codir1)])
subprocess.call(["git", "config", "dzonegit.checkoutpath9", str(codir2)])
dzonegit.post_receive(stdin)
assert codir1.join("dummy.zone").check()
assert codir2.join("dummy.zone").check()