initial commit

This commit is contained in:
2025-02-19 00:16:57 +01:00
parent 1d9cd91fcd
commit d89698593b
1293 changed files with 55933 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
#!/usr/bin/env python3
# This script appends the current commit hash to the version information in
# `layouts/partials/version.txt`
#
# Call this script from your ".git/hooks/post-commit" file like this (supporting
# Linux, Windows and MacOS)
# #!/bin/sh
# python3 .githooks/post-commit.py
from datetime import datetime
import os
import re
import subprocess
def main():
script_name = "POST-COMMIT"
script_dir = os.path.dirname(os.path.abspath(__file__))
log_file = os.path.join(script_dir, "hooks.log")
time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
repo_root = subprocess.check_output(['git', 'rev-parse', '--show-toplevel'], universal_newlines=True).strip()
repo_name = os.path.basename(repo_root)
file_path = 'layouts/partials/version.txt'
with open(file_path, 'r+') as f:
version = f.read().strip()
new_version = ''
match = re.match(r'(\d+\.\d+\.\d+)(?:\+([^+]+))?', version)
if match:
semver = match.group(1)
old_hash = match.group(2)
new_hash = subprocess.check_output(['git', 'rev-parse', 'HEAD~1']).decode('utf-8').strip()
print(f'{time}: {repo_name} - {script_name} - old hash {old_hash} - new hash {new_hash}', file=open(log_file, "a"))
print(f'{script_name} - old hash {old_hash} - new hash {new_hash}')
if old_hash != new_hash:
new_version = f'{semver}+{new_hash}'
f.seek(0)
f.write(new_version)
f.truncate()
f.close()
subprocess.check_call(['git', 'add', file_path])
subprocess.check_call(['git', 'commit', '--amend', '--no-edit'])
else:
print(f'{time}: {repo_name} - {script_name} - No change in hash, file {file_path} not updated', file=open(log_file, "a"))
print(f'{script_name} - No change in hash, file {file_path} not updated')
exit(0)
else:
print(f'{time}: {repo_name} - {script_name} - Invalid version format in {file_path}', file=open(log_file, "a"))
print(f'{script_name} - Invalid version format in {file_path}')
exit(1)
print(f'{time}: {repo_name} - {script_name} - New version {new_version} was written to {file_path}', file=open(log_file, "a"))
exit(0)
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,49 @@
#!/usr/bin/env python3
# This script avoids to push branches starting with a "#". This is the way
# how I store ticket related feature branches that are work in progress.
# Once a feature branch is finished, it will be rebased to mains HEAD,
# its commits squashed, merged into main and the branch deleted afterwards.
# Call this script from your ".git/hooks/pre-push" file like this (supporting
# Linux, Windows and MacOS)
# #!/bin/sh
# python3 .githooks/pre-push.py
from datetime import datetime
import os
import re
import subprocess
# This hook is called with the following parameters:
# $1 -- Name of the remote to which the push is being done
# $2 -- URL to which the push is being done
# If pushing without using a named remote, those arguments will be equal.
# Information about the commits being pushed is supplied as lines to
# the standard input in the form:
# <local ref> <local sha1> <remote ref> <remote sha1>
# This hook prevents the push of commits that belong to branches starting with
# an "#" (which are work in progress).
def main():
script_name = "PRE-PUSH"
script_dir = os.path.dirname(os.path.abspath(__file__))
log_file = os.path.join(script_dir, "hooks.log")
time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
repo_root = subprocess.check_output(['git', 'rev-parse', '--show-toplevel'], universal_newlines=True).strip()
repo_name = os.path.basename(repo_root)
local_branch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD'], universal_newlines=True).strip()
wip_prefix = '^#\\d+(?:\\b.*)$'
if re.match(wip_prefix, local_branch):
print(f'{time}: {repo_name} - {script_name} - Branch "{local_branch}" was not pushed because its name starts with a "#" which marks it as work in progress', file=open(log_file, "a"))
print(f'{script_name} - Branch "{local_branch}" was not pushed because its name starts with a "#" which marks it as work in progress')
exit(1)
print(f'{time}: {repo_name} - {script_name} - Branch "{local_branch}" was pushed', file=open(log_file, "a"))
exit(0)
if __name__ == "__main__":
main()