~edwargix/git.sr.ht

ae9a7a649f4d061194c693107bbd73c922f3689c — Drew DeVault 8 years ago b5941bc
Move update hook into /usr and add symlinks
4 files changed, 20 insertions(+), 3 deletions(-)

R gitsrht/hooks/update => git-srht-update-hook
M gitsrht/blueprints/manage.py
A scripts/symlink-update-hook.py
M setup.py
R gitsrht/hooks/update => git-srht-update-hook +0 -0
M gitsrht/blueprints/manage.py => gitsrht/blueprints/manage.py +2 -2
@@ 13,6 13,7 @@ import re

manage = Blueprint('manage', __name__)
repos_path = cfg("cgit", "repos")
post_update = cfg("git.sr.ht", "post-update-script")

@manage.route("/create")
@loginrequired


@@ 59,8 60,7 @@ def create():
    db.session.commit()

    subprocess.run(["git", "config", "srht.repo-id", str(repo.id)], cwd=repo.path)
    hook_src = os.path.join(os.path.dirname(__file__), "..", "hooks", "update")
    shutil.copy(hook_src, os.path.join(repo.path, "hooks", "update"))
    subprocess.run(["ln", "-s", post_update, os.path.join(repo.path, "hooks", "update")])

    if another == "on":
        return redirect("/create?another")

A scripts/symlink-update-hook.py => scripts/symlink-update-hook.py +17 -0
@@ 0,0 1,17 @@
#!/usr/bin/env python3
from srht.config import cfg, cfgi, load_config
load_config("git")
from srht.database import DbSession
db = DbSession(cfg("sr.ht", "connection-string"))
from gitsrht.types import Repository
db.init()
import os

post_update = cfg("git.sr.ht", "post-update-script")

for repo in Repository.query.all():
    hook = os.path.join(repo.path, "hooks", "update")
    if not os.path.islink(hook) or os.readlink(hook) != post_update:
        print("Migrating {}".format(repo.name))
        os.remove(hook)
        os.symlink(post_update, hook)

M setup.py => setup.py +1 -1
@@ 30,5 30,5 @@ setup(
          'hooks/*'
      ]
  },
  scripts = ['git-srht-keys']
  scripts = ['git-srht-keys', 'git-srht-update-hook']
)