diff options
Diffstat (limited to 'git')
-rw-r--r-- | git/Makefile | 89 | ||||
-rwxr-xr-x | git/bin/git-checkout-branches | 43 | ||||
-rwxr-xr-x | git/bin/git-hook | 32 | ||||
-rwxr-xr-x | git/bin/git-pull-branches | 49 | ||||
-rwxr-xr-x | git/bin/git-remove-origin-branches | 29 | ||||
-rwxr-xr-x | git/bin/git-remove-origin-tags | 29 | ||||
-rwxr-xr-x | git/bin/git-repo-repack | 71 | ||||
-rwxr-xr-x | git/bin/git-whoami | 33 | ||||
-rwxr-xr-x | git/share/hooks/post-update.d/cgit-agefile | 27 | ||||
-rwxr-xr-x | git/share/hooks/post-update.d/git-update-server-info | 24 | ||||
-rwxr-xr-x | git/share/hooks/post-update.d/irker-notification | 34 |
11 files changed, 460 insertions, 0 deletions
diff --git a/git/Makefile b/git/Makefile new file mode 100644 index 0000000..d3c7921 --- /dev/null +++ b/git/Makefile @@ -0,0 +1,89 @@ +# Open Infrastructure: service-tools + +# Copyright (C) 2014-2022 Daniel Baumann <daniel.baumann@open-infrastructure.net> +# +# SPDX-License-Identifier: GPL-3.0+ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +SHELL := sh -e + +SCRIPTS = bin/* share/hooks/* share/hooks/*/* + +all: build + +test: + @echo -n "Checking for syntax errors with sh... " + @for SCRIPT in $(SCRIPTS); \ + do \ + sh -n $${SCRIPT}; \ + echo -n "."; \ + done + @echo " done." + + @echo -n "Checking for bashisms... " + @if [ -x /usr/bin/checkbashisms ]; \ + then \ + for SCRIPT in $(SCRIPTS); \ + do \ + checkbashisms -f -x $${SCRIPT}; \ + echo -n "."; \ + done; \ + else \ + echo "Note: devscripts not installed, skipping checkbashisms."; \ + fi + @echo " done." + + @echo -n "Checking with shellcheck... " + @if [ -x /usr/bin/shellcheck ]; \ + then \ + for SCRIPT in $(SCRIPTS); \ + do \ + if [ ! -d $${SCRIPT} ]; \ + then \ + shellcheck -e SC2039 $${SCRIPT} || true; \ + echo -n "."; \ + fi; \ + done; \ + else \ + echo "Note: shellcheck not installed, skipping shellcheck."; \ + fi + @echo " done." + +build: + +install: build + mkdir -p $(DESTDIR)/usr/bin + cp -r bin/* $(DESTDIR)/usr/bin + + mkdir -p $(DESTDIR)/usr/share/git/hooks + cp -r share/hooks/* $(DESTDIR)/usr/share/git/hooks + +uninstall: + rm -rf $(DESTDIR)/usr/share/git/hooks + rmdir --ignore-fail-on-non-empty --parents $(DESTDIR)/usr/share/git || true + + for FILE in bin/*; \ + do \ + rm -f $(DESTDIR)/usr/bin/$$(basename $${FILE}); \ + done + rmdir --ignore-fail-on-non-empty --parents $(DESTDIR)/usr/bin || true + + rmdir --ignore-fail-on-non-empty --parents $(DESTDIR) || true + +clean: + +distclean: + +reinstall: uninstall install diff --git a/git/bin/git-checkout-branches b/git/bin/git-checkout-branches new file mode 100755 index 0000000..220386f --- /dev/null +++ b/git/bin/git-checkout-branches @@ -0,0 +1,43 @@ +#!/bin/sh + +# Open Infrastructure: service-tools + +# Copyright (C) 2014-2022 Daniel Baumann <daniel.baumann@open-infrastructure.net> +# +# SPDX-License-Identifier: GPL-3.0+ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +set -e + +CURRENT_BRANCH="$(git branch --show-current)" +REMOTE_BRANCHES="$(git branch -r | awk '{ print $1 }')" + +for REMOTE_BRANCH in ${REMOTE_BRANCHES} +do + BRANCH="$(echo "${REMOTE_BRANCH}" | cut -d/ -f 2-)" + + case "${BRANCH}" in + HEAD|"${CURRENT_BRANCH}") + continue + ;; + esac + + git checkout -b "${BRANCH}" "${REMOTE_BRANCH}" +done + +if [ "$(git branch --show-current)" != "${CURRENT_BRANCH}" ] +then + git checkout "${CURRENT_BRANCH}" +fi diff --git a/git/bin/git-hook b/git/bin/git-hook new file mode 100755 index 0000000..218ef00 --- /dev/null +++ b/git/bin/git-hook @@ -0,0 +1,32 @@ +#!/bin/sh + +# Open Infrastructure: service-tools + +# Copyright (C) 2014-2022 Daniel Baumann <daniel.baumann@open-infrastructure.net> +# +# SPDX-License-Identifier: GPL-3.0+ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +set -e + +HOOKS="${0}.d" + +for HOOK in "${HOOKS}"/* +do + if [ -x "${HOOK}" ] + then + "${HOOK}" "${@}" || true + fi +done diff --git a/git/bin/git-pull-branches b/git/bin/git-pull-branches new file mode 100755 index 0000000..9effa17 --- /dev/null +++ b/git/bin/git-pull-branches @@ -0,0 +1,49 @@ +#!/bin/sh + +# Open Infrastructure: service-tools + +# Copyright (C) 2014-2022 Daniel Baumann <daniel.baumann@open-infrastructure.net> +# +# SPDX-License-Identifier: GPL-3.0+ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +set -e + +CURRENT_BRANCH="$(git branch --show-current)" +REMOTE_BRANCHES="$(git branch -r | awk '{ print $1 }')" + +for REMOTE_BRANCH in ${REMOTE_BRANCHES} +do + BRANCH="$(echo "${REMOTE_BRANCH}" | cut -d/ -f 2-)" + + case "${BRANCH}" in + HEAD|"${CURRENT_BRANCH}") + continue + ;; + esac + + if git branch | sed -e 's|\*||' | grep -qs " ${BRANCH}$" + then + git checkout "${BRANCH}" + git pull + else + git checkout -b "${BRANCH}" "${REMOTE_BRANCH}" + fi +done + +if [ "$(git branch --show-current)" != "${CURRENT_BRANCH}" ] +then + git checkout "${CURRENT_BRANCH}" +fi diff --git a/git/bin/git-remove-origin-branches b/git/bin/git-remove-origin-branches new file mode 100755 index 0000000..be65a1f --- /dev/null +++ b/git/bin/git-remove-origin-branches @@ -0,0 +1,29 @@ +#!/bin/sh + +# Open Infrastructure: service-tools + +# Copyright (C) 2014-2022 Daniel Baumann <daniel.baumann@open-infrastructure.net> +# +# SPDX-License-Identifier: GPL-3.0+ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +set -e + +BRANCHES="${*}" + +for BRANCH in ${BRANCHES} +do + git push origin :"${BRANCH}" +done diff --git a/git/bin/git-remove-origin-tags b/git/bin/git-remove-origin-tags new file mode 100755 index 0000000..8246ec2 --- /dev/null +++ b/git/bin/git-remove-origin-tags @@ -0,0 +1,29 @@ +#!/bin/sh + +# Open Infrastructure: service-tools + +# Copyright (C) 2014-2022 Daniel Baumann <daniel.baumann@open-infrastructure.net> +# +# SPDX-License-Identifier: GPL-3.0+ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +set -e + +TAGS="${*}" + +for TAG in ${TAGS} +do + git push origin :refs/tags/"${TAG}" +done diff --git a/git/bin/git-repo-repack b/git/bin/git-repo-repack new file mode 100755 index 0000000..cf5a30c --- /dev/null +++ b/git/bin/git-repo-repack @@ -0,0 +1,71 @@ +#!/bin/sh + +# Open Infrastructure: service-tools + +# Copyright (C) 2014-2022 Daniel Baumann <daniel.baumann@open-infrastructure.net> +# +# SPDX-License-Identifier: GPL-3.0+ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +set -e + +case "${1}" in + --quiet) + QUIET="true" + shift + + GIT_REPACK_OPTIONS="-q" + GIT_GC_OPTIONS="--quiet" + ;; +esac + +REPOSITORIES="${*}" + +if [ -z "${REPOSITORIES}" ] +then + if [ ! -e HEAD ] + then + REPOSITORIES="*.git" + else + REPOSITORIES="$(pwd)" + fi +fi + +for REPOSITORY in ${REPOSITORIES} +do + if [ "${QUIET}" != "true" ] + then + +cat << EOF +================================================================================ +${REPOSITORY} +================================================================================ +EOF + + fi + + cd "${REPOSITORY}" + git repack "${GIT_REPACK_OPTIONS}" -a -b -d -f -F + git gc --aggressive --prune ${GIT_GC_OPTIONS} + cd "${OLDPWD}" + + if [ "$(id -u)" -eq "0" ] + then + USER_ID="$(stat -c %u "${REPOSITORY}")" + GROUP_ID="$(stat -c %g "${REPOSITORY}")" + + chown "${USER_ID}":"${GROUP_ID}" "${REPOSITORY}" -R + fi +done diff --git a/git/bin/git-whoami b/git/bin/git-whoami new file mode 100755 index 0000000..50f432a --- /dev/null +++ b/git/bin/git-whoami @@ -0,0 +1,33 @@ +#!/bin/sh + +# git-whoami +# Author: Peter Eisentraut <peter@eisentraut.org> +# Created: 2011-10-27 +# License: WTFPL; see http://sam.zoy.org/wtfpl/ + +# exact logic in ident.c in git source tree + +set -e + +get_email() { + git config user.email || ( [ -n "${EMAIL}" ] && echo "${EMAIL}" ) || echo "$(id -nu)@$(hostname --fqdn)" +} + +get_name() { + git config user.name || getent passwd "$(id -un)" | cut -d : -f 5 | cut -d , -f 1 +} + +GIT_AUTHOR_NAME="${GIT_AUTHOR_NAME:-$(get_name)}" +GIT_AUTHOR_EMAIL="${GIT_AUTHOR_EMAIL:-$(get_email)}" +GIT_COMMITTER_NAME="${GIT_COMMITER_NAME:-$(get_name)}" +GIT_COMMITTER_EMAIL="${GIT_COMMITER_EMAIL:-$(get_email)}" + +author="$GIT_AUTHOR_NAME <${GIT_AUTHOR_EMAIL}>" +commit="$GIT_COMMITTER_NAME <${GIT_COMMITTER_EMAIL}>" + +if [ "${author}" = "${commit}" ]; then + echo "${author}" +else + echo "Author: ${author}" + echo "Commit: ${commit}" +fi diff --git a/git/share/hooks/post-update.d/cgit-agefile b/git/share/hooks/post-update.d/cgit-agefile new file mode 100755 index 0000000..a00b038 --- /dev/null +++ b/git/share/hooks/post-update.d/cgit-agefile @@ -0,0 +1,27 @@ +#!/bin/sh + +# Open Infrastructure: service-tools + +# Copyright (C) 2014-2022 Daniel Baumann <daniel.baumann@open-infrastructure.net> +# +# SPDX-License-Identifier: GPL-3.0+ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +set -e + +agefile="$(git rev-parse --git-dir)"/info/web/last-modified + +mkdir -p "$(dirname "$agefile")" +git for-each-ref --sort=-authordate --count=1 --format='%(authordate:iso8601)' >"$agefile" diff --git a/git/share/hooks/post-update.d/git-update-server-info b/git/share/hooks/post-update.d/git-update-server-info new file mode 100755 index 0000000..1b21b51 --- /dev/null +++ b/git/share/hooks/post-update.d/git-update-server-info @@ -0,0 +1,24 @@ +#!/bin/sh + +# Open Infrastructure: service-tools + +# Copyright (C) 2014-2022 Daniel Baumann <daniel.baumann@open-infrastructure.net> +# +# SPDX-License-Identifier: GPL-3.0+ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +set -e + +git update-server-info diff --git a/git/share/hooks/post-update.d/irker-notification b/git/share/hooks/post-update.d/irker-notification new file mode 100755 index 0000000..7c712db --- /dev/null +++ b/git/share/hooks/post-update.d/irker-notification @@ -0,0 +1,34 @@ +#!/bin/sh + +# Open Infrastructure: service-tools + +# Copyright (C) 2014-2022 Daniel Baumann <daniel.baumann@open-infrastructure.net> +# +# SPDX-License-Identifier: GPL-3.0+ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +set -e + +if [ -z "$(git config --get irker.project)" ] +then + exit 0 +fi + +echo "sending IRC notification" + +while read -r OLD NEW REFNAME +do + irkerhook --refname="${REFNAME}" "$(git rev-list --reverse "${OLD}".."${NEW}")" +done |