From f632659563acb7b8d481fdff9acd8305acf29b98 Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Tue, 26 Sep 2023 22:09:41 +0200 Subject: fix(clone): ssh connection may require user input (key unlocking etc) Anything that requires user input (such as a key unlock or hostkey verify) will block the terminal and wait for input which will never come. When cloning or configuring a repo via ssh we therefore initially connect to gitlab to warm the connection. Afterwards users are expected to either have setup a ssh ControlMaster or use something like a ssh agent. Fixes #148 Component: pkgctl repo clone/configure Co-Authored-by: Christian Heusel Signed-off-by: Christian Heusel Signed-off-by: Levente Polyak --- src/lib/repo/clone.sh | 11 +++++++++++ src/lib/repo/configure.sh | 8 ++++++++ 2 files changed, 19 insertions(+) (limited to 'src/lib/repo') diff --git a/src/lib/repo/clone.sh b/src/lib/repo/clone.sh index 08bded4..fb927d2 100644 --- a/src/lib/repo/clone.sh +++ b/src/lib/repo/clone.sh @@ -12,6 +12,8 @@ source "${_DEVTOOLS_LIBRARY_DIR}"/lib/common.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/api/gitlab.sh # shellcheck source=src/lib/repo/configure.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/repo/configure.sh +# shellcheck source=src/lib/util/git.sh +source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/git.sh source /usr/share/makepkg/util/message.sh @@ -52,6 +54,7 @@ pkgctl_repo_clone() { fi # options + local protocol=ssh local GIT_REPO_BASE_URL=${GIT_PACKAGING_URL_SSH} local CLONE_ALL=0 local MAINTAINER= @@ -72,6 +75,7 @@ pkgctl_repo_clone() { ;; --protocol=https) GIT_REPO_BASE_URL=${GIT_PACKAGING_URL_HTTPS} + protocol=https CONFIGURE_OPTIONS+=("$1") shift ;; @@ -82,6 +86,7 @@ pkgctl_repo_clone() { else die "unsupported protocol: %s" "$2" fi + protocol="$2" CONFIGURE_OPTIONS+=("$1" "$2") shift 2 ;; @@ -171,6 +176,12 @@ pkgctl_repo_clone() { if [[ -n "${VERSION}" ]]; then command+=" --switch '${VERSION}'" fi + + # warm up ssh connection as it may require user input (key unlock, hostkey verification etc) + if [[ ${protocol} == ssh ]]; then + git_warmup_ssh_connection + fi + if ! parallel --bar --jobs "${jobs}" "${command}" ::: "${pkgbases[@]}"; then die 'Failed to clone some packages, please check the output' exit 1 diff --git a/src/lib/repo/configure.sh b/src/lib/repo/configure.sh index 73300ae..1ddb1b8 100644 --- a/src/lib/repo/configure.sh +++ b/src/lib/repo/configure.sh @@ -10,6 +10,8 @@ _DEVTOOLS_LIBRARY_DIR=${_DEVTOOLS_LIBRARY_DIR:-@pkgdatadir@} source "${_DEVTOOLS_LIBRARY_DIR}"/lib/common.sh # shellcheck source=src/lib/api/gitlab.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/api/gitlab.sh +# shellcheck source=src/lib/util/git.sh +source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/git.sh source /usr/share/makepkg/util/config.sh source /usr/share/makepkg/util/message.sh @@ -188,6 +190,12 @@ pkgctl_repo_configure() { if [[ -n ${BOLD} ]]; then export DEVTOOLS_COLOR=always fi + + # warm up ssh connection as it may require user input (key unlock, hostkey verification etc) + if [[ ${proto} == ssh ]]; then + git_warmup_ssh_connection + fi + if ! parallel --bar --jobs "${jobs}" "${command}" ::: "${paths[@]}"; then die 'Failed to configure some packages, please check the output' exit 1 -- cgit v1.2.3-54-g00ecf From 9a356eae828ce0e75d49e3efdb42bac089eb528a Mon Sep 17 00:00:00 2001 From: Christian Heusel Date: Sat, 2 Sep 2023 12:31:12 +0200 Subject: feat(web): implement option to print the URL instead of opening it In certain situations, users may encounter limitations when unable to utilize xdg-open (e.g., when connected to an Arch machine via SSH). Consequently, this commit introduces the option to simply print the repository link to copy or click on it. Signed-off-by: Christian Heusel Signed-off-by: Levente Polyak --- contrib/completion/bash/devtools.in | 1 + contrib/completion/zsh/_devtools.in | 1 + doc/man/pkgctl-repo-web.1.asciidoc | 3 +++ src/lib/repo/web.sh | 23 ++++++++++++++++++++--- 4 files changed, 25 insertions(+), 3 deletions(-) (limited to 'src/lib/repo') diff --git a/contrib/completion/bash/devtools.in b/contrib/completion/bash/devtools.in index 78f0741..83264ce 100644 --- a/contrib/completion/bash/devtools.in +++ b/contrib/completion/bash/devtools.in @@ -325,6 +325,7 @@ _pkgctl_repo_switch_opts() { _pkgctl_repo_web_args=( + --print -h --help ) _pkgctl_repo_web_opts() { _filedir -d; } diff --git a/contrib/completion/zsh/_devtools.in b/contrib/completion/zsh/_devtools.in index 372f07b..b82ece4 100644 --- a/contrib/completion/zsh/_devtools.in +++ b/contrib/completion/zsh/_devtools.in @@ -134,6 +134,7 @@ _pkgctl_repo_create_args=( ) _pkgctl_repo_web_args=( + '--print[Print the url instead of opening it with xdg-open]' '(-h --help)'{-h,--help}'[Display usage]' '*:git_dir:_files -/' ) diff --git a/doc/man/pkgctl-repo-web.1.asciidoc b/doc/man/pkgctl-repo-web.1.asciidoc index 8769be7..ba7106a 100644 --- a/doc/man/pkgctl-repo-web.1.asciidoc +++ b/doc/man/pkgctl-repo-web.1.asciidoc @@ -18,6 +18,9 @@ no arguments, open the package cloned in the current working directory. Options ------- +*--print*:: + Print the url instead of opening it with xdg-open + *-h, --help*:: Show a help text diff --git a/src/lib/repo/web.sh b/src/lib/repo/web.sh index 45ea53b..ab3d8c7 100644 --- a/src/lib/repo/web.sh +++ b/src/lib/repo/web.sh @@ -23,6 +23,7 @@ pkgctl_repo_web_usage() { no arguments, open the package cloned in the current working directory. OPTIONS + --print Print the url instead of opening it with xdg-open -h, --help Show this help text EXAMPLES @@ -32,7 +33,8 @@ _EOF_ pkgctl_repo_web() { local pkgbases=() - local path giturl pkgbase + local path giturl pkgbase url + local mode=open # option checking while (( $# )); do @@ -41,6 +43,10 @@ pkgctl_repo_web() { pkgctl_repo_web_usage exit 0 ;; + --print) + mode=print + shift + ;; --) shift break @@ -56,7 +62,7 @@ pkgctl_repo_web() { done # Check if web mode has xdg-open - if ! command -v xdg-open &>/dev/null; then + if [[ ${mode} == open ]] && ! command -v xdg-open &>/dev/null; then die "The web command requires 'xdg-open'" fi @@ -78,7 +84,18 @@ pkgctl_repo_web() { fi for pkgbase in "${pkgbases[@]}"; do + pkgbase=$(basename "${pkgbase}") path=$(gitlab_project_name_to_path "${pkgbase}") - xdg-open "${GIT_PACKAGING_URL_HTTPS}/${path}" + url="${GIT_PACKAGING_URL_HTTPS}/${path}" + case ${mode} in + open) + xdg-open "${url}" + ;; + print) + printf "%s\n" "${url}" + ;; + *) + die "Unknown mode: ${mode}" + esac done } -- cgit v1.2.3-54-g00ecf From f2cafa3cb0941be8235025434620adbf5849a432 Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Sun, 3 Dec 2023 19:46:09 +0100 Subject: feat(clone): speedup maintainer and universe clone query There is a single endpoint now to list all pkgbases and their current maintainers. Use this endpoint for speeding up the clone of all packages of a maintainer by only issuing a single API call. Component: pkgctl repo clone Signed-off-by: Levente Polyak --- src/lib/api/archweb.sh | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/lib/common.sh | 15 +++++++++++++ src/lib/repo/clone.sh | 30 ++++++++------------------ src/pkgctl.in | 2 ++ 4 files changed, 83 insertions(+), 21 deletions(-) create mode 100644 src/lib/api/archweb.sh (limited to 'src/lib/repo') diff --git a/src/lib/api/archweb.sh b/src/lib/api/archweb.sh new file mode 100644 index 0000000..34c7a9c --- /dev/null +++ b/src/lib/api/archweb.sh @@ -0,0 +1,57 @@ +#!/hint/bash +# +# SPDX-License-Identifier: GPL-3.0-or-later + +[[ -z ${DEVTOOLS_INCLUDE_API_ARCHWEB_SH:-} ]] || return 0 +DEVTOOLS_INCLUDE_API_ARCHWEB_SH=1 + +_DEVTOOLS_LIBRARY_DIR=${_DEVTOOLS_LIBRARY_DIR:-@pkgdatadir@} +# shellcheck source=src/lib/common.sh +source "${_DEVTOOLS_LIBRARY_DIR}"/lib/common.sh + +set -e +set -o pipefail + + +archweb_query_all_packages() { + [[ -z ${WORKDIR:-} ]] && setup_workdir + + stat_busy "Query all released packages" + mapfile -t pkgbases < <( + curl --location --show-error --no-progress-meter --fail --retry 3 --retry-delay 3 \ + "${PKGBASE_MAINTAINER_URL}" 2> "${WORKDIR}/error" \ + | jq --raw-output --exit-status 'keys[]' 2> "${WORKDIR}/error" + ) + if ! wait $!; then + stat_failed + print_workdir_error + return 1 + fi + stat_done + + printf "%s\n" "${pkgbases[@]}" + return 0 +} + + +archweb_query_maintainer_packages() { + local maintainer=$1 + + [[ -z ${WORKDIR:-} ]] && setup_workdir + + stat_busy "Query maintainer packages" + mapfile -t pkgbases < <( + curl --location --show-error --no-progress-meter --fail --retry 3 --retry-delay 3 \ + "${PKGBASE_MAINTAINER_URL}" 2> "${WORKDIR}/error" \ + | jq --raw-output --exit-status '. as $parent | keys[] | select(. as $key | $parent[$key] | index("'"${maintainer}"'"))' 2> "${WORKDIR}/error" + ) + if ! wait $!; then + stat_failed + print_workdir_error + return 1 + fi + stat_done + + printf "%s\n" "${pkgbases[@]}" + return 0 +} diff --git a/src/lib/common.sh b/src/lib/common.sh index 3d1ee56..7589120 100644 --- a/src/lib/common.sh +++ b/src/lib/common.sh @@ -28,6 +28,7 @@ export GIT_PACKAGING_NAMESPACE_ID=11323 export GIT_PACKAGING_URL_SSH="git@${GITLAB_HOST}:${GIT_PACKAGING_NAMESPACE}" export GIT_PACKAGING_URL_HTTPS="https://${GITLAB_HOST}/${GIT_PACKAGING_NAMESPACE}" export PACKAGING_REPO_RELEASE_HOST=repos.archlinux.org +export PKGBASE_MAINTAINER_URL=https://archlinux.org/packages/pkgbase-maintainer # check if messages are to be printed using color if [[ -t 2 && "$TERM" != dumb ]] || [[ ${DEVTOOLS_COLOR} == always ]]; then @@ -53,6 +54,11 @@ stat_done() { printf "${BOLD}done${ALL_OFF}\n" >&2 } +stat_failed() { + # shellcheck disable=2059 + printf "${BOLD}${RED}failed${ALL_OFF}\n" >&2 +} + msg_success() { local msg=$1 local padding @@ -77,6 +83,15 @@ msg_warn() { printf "%s %s\n" "${padding}${YELLOW}!${ALL_OFF}" "${msg}" >&2 } +print_workdir_error() { + if [[ ! -f "${WORKDIR}"/error ]]; then + return + fi + while read -r LINE; do + error '%s' "${LINE}" + done < "${WORKDIR}/error" +} + _setup_workdir=false setup_workdir() { [[ -z ${WORKDIR:-} ]] && WORKDIR=$(mktemp -d --tmpdir "${0##*/}.XXXXXXXXXX") diff --git a/src/lib/repo/clone.sh b/src/lib/repo/clone.sh index fb927d2..ef6a0e2 100644 --- a/src/lib/repo/clone.sh +++ b/src/lib/repo/clone.sh @@ -8,6 +8,8 @@ DEVTOOLS_INCLUDE_REPO_CLONE_SH=1 _DEVTOOLS_LIBRARY_DIR=${_DEVTOOLS_LIBRARY_DIR:-@pkgdatadir@} # shellcheck source=src/lib/common.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/common.sh +# shellcheck source=src/lib/api/archweb.sh +source "${_DEVTOOLS_LIBRARY_DIR}"/lib/api/archweb.sh # shellcheck source=src/lib/api/gitlab.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/api/gitlab.sh # shellcheck source=src/lib/repo/configure.sh @@ -18,6 +20,7 @@ source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/git.sh source /usr/share/makepkg/util/message.sh set -e +set -o pipefail pkgctl_repo_clone_usage() { @@ -137,33 +140,18 @@ pkgctl_repo_clone() { # Query packages of a maintainer if [[ -n ${MAINTAINER} ]]; then - stat_busy "Query packages" - max_pages=$(curl --silent --location --fail --retry 3 --retry-delay 3 "https://archlinux.org/packages/search/json/?sort=name&maintainer=${MAINTAINER}" | jq -r '.num_pages') - if [[ ! ${max_pages} =~ ([[:digit:]]) ]]; then - stat_done - warning "found no packages for maintainer ${MAINTAINER}" - exit 0 + mapfile -t pkgbases < <(archweb_query_maintainer_packages "${MAINTAINER}") + if ! wait $!; then + die "Failed to query maintainer packages" fi - mapfile -t pkgbases < <(for page in $(seq "${max_pages}"); do - curl --silent --location --fail --retry 3 --retry-delay 3 "https://archlinux.org/packages/search/json/?sort=name&maintainer=${MAINTAINER}&page=${page}" | jq -r '.results[].pkgbase' - stat_progress - done | sort --unique) - stat_done fi # Query all released packages if (( CLONE_ALL )); then - stat_busy "Query all released packages" - max_pages=$(curl --silent --location --fail --retry 3 --retry-delay 3 "https://archlinux.org/packages/search/json/?sort=name" | jq -r '.num_pages') - if [[ ! ${max_pages} =~ ([[:digit:]]) ]]; then - stat_done - die "failed to query packages" + mapfile -t pkgbases < <(archweb_query_all_packages) + if ! wait $!; then + die "Failed to query all packages" fi - mapfile -t pkgbases < <(for page in $(seq "${max_pages}"); do - curl --silent --location --fail --retry 3 --retry-delay 3 "https://archlinux.org/packages/search/json/?sort=name&page=${page}" | jq -r '.results[].pkgbase' - stat_progress - done | sort --unique) - stat_done fi # parallelization diff --git a/src/pkgctl.in b/src/pkgctl.in index 07242a3..ad215ac 100644 --- a/src/pkgctl.in +++ b/src/pkgctl.in @@ -39,6 +39,8 @@ fi export _DEVTOOLS_COMMAND='pkgctl' +setup_workdir + load_devtools_config # command checking -- cgit v1.2.3-54-g00ecf From d00a2b989044fe452792e108a15b6c901a1a1d4c Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Sun, 11 Jun 2023 23:31:18 +0200 Subject: feat(configure): ship default ignore via exclude BREAKING CHANGE: Increments the repo spec version which requires to reconfigure all existing packaging repo clones. Fixes #129 Component: pkgctl repo configure Signed-off-by: Levente Polyak --- Makefile | 8 +++++++- config/git/template/hooks/applypatch-msg | 1 + config/git/template/hooks/commit-msg | 1 + config/git/template/hooks/post-applypatch | 1 + config/git/template/hooks/post-checkout | 1 + config/git/template/hooks/post-commit | 1 + config/git/template/hooks/post-merge | 1 + config/git/template/hooks/pre-applypatch | 1 + config/git/template/hooks/pre-commit | 1 + config/git/template/hooks/pre-merge-commit | 1 + config/git/template/hooks/pre-push | 1 + config/git/template/hooks/pre-rebase | 1 + config/git/template/hooks/prepare-commit-msg | 1 + config/git/template/info/exclude | 28 ++++++++++++++++++++++++++++ doc/man/pkgctl-repo-configure.1.asciidoc | 2 ++ src/commitpkg.in | 6 ++++++ src/lib/common.sh | 2 +- src/lib/repo/configure.sh | 25 ++++++++++++++++++++++++- 18 files changed, 80 insertions(+), 3 deletions(-) create mode 100755 config/git/template/hooks/applypatch-msg create mode 100755 config/git/template/hooks/commit-msg create mode 100755 config/git/template/hooks/post-applypatch create mode 100755 config/git/template/hooks/post-checkout create mode 100755 config/git/template/hooks/post-commit create mode 100755 config/git/template/hooks/post-merge create mode 100755 config/git/template/hooks/pre-applypatch create mode 100755 config/git/template/hooks/pre-commit create mode 100755 config/git/template/hooks/pre-merge-commit create mode 100755 config/git/template/hooks/pre-push create mode 100755 config/git/template/hooks/pre-rebase create mode 100755 config/git/template/hooks/prepare-commit-msg create mode 100644 config/git/template/info/exclude (limited to 'src/lib/repo') diff --git a/Makefile b/Makefile index 36f1b9b..afdb602 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,7 @@ LIBRARY_SRC = $(call rwildcard,src/lib,*.sh) LIBRARY = $(addprefix $(BUILDDIR)/,$(patsubst src/%,%,$(patsubst %.in,%,$(LIBRARY_SRC)))) MAKEPKG_CONFIGS=$(wildcard config/makepkg/*) PACMAN_CONFIGS=$(wildcard config/pacman/*) +GIT_CONFIGS = $(wildcard config/git/*) SETARCH_ALIASES = $(wildcard config/setarch-aliases.d/*) MANS = $(addprefix $(BUILDDIR)/,$(patsubst %.asciidoc,%,$(wildcard doc/man/*.asciidoc))) @@ -97,9 +98,12 @@ $(BUILDDIR)/doc/man/%: doc/man/%.asciidoc doc/asciidoc.conf doc/man/include/foot @a2x --no-xmllint --asciidoc-opts="-f doc/asciidoc.conf" -d manpage -f manpage --destination-dir=$(BUILDDIR)/doc/man -a pkgdatadir=$(DATADIR) $< conf: - @install -d $(BUILDDIR)/makepkg.conf.d $(BUILDDIR)/pacman.conf.d + @install -d $(BUILDDIR)/makepkg.conf.d @cp -a $(MAKEPKG_CONFIGS) $(BUILDDIR)/makepkg.conf.d + @install -d $(BUILDDIR)/pacman.conf.d @cp -a $(PACMAN_CONFIGS) $(BUILDDIR)/pacman.conf.d + @install -d $(BUILDDIR)/git.conf.d + cp -a $(GIT_CONFIGS) $(BUILDDIR)/git.conf.d clean: rm -rf $(BUILDDIR) @@ -112,6 +116,7 @@ install: all install -m0755 ${BINPROGS} $(DESTDIR)$(PREFIX)/bin install -dm0755 $(DESTDIR)$(DATADIR)/lib cp -ra $(BUILDDIR)/lib/* $(DESTDIR)$(DATADIR)/lib + cp -a $(BUILDDIR)/git.conf.d -t $(DESTDIR)$(DATADIR) for conf in $(notdir $(MAKEPKG_CONFIGS)); do install -Dm0644 $(BUILDDIR)/makepkg.conf.d/$$conf $(DESTDIR)$(DATADIR)/makepkg.conf.d/$${conf##*/}; done for conf in $(notdir $(PACMAN_CONFIGS)); do install -Dm0644 $(BUILDDIR)/pacman.conf.d/$$conf $(DESTDIR)$(DATADIR)/pacman.conf.d/$${conf##*/}; done for a in ${SETARCH_ALIASES}; do install -m0644 $$a -t $(DESTDIR)$(DATADIR)/setarch-aliases.d; done @@ -129,6 +134,7 @@ uninstall: for f in $(notdir $(BINPROGS)); do rm -f $(DESTDIR)$(PREFIX)/bin/$$f; done for f in $(notdir $(LIBRARY)); do rm -f $(DESTDIR)$(DATADIR)/lib/$$f; done rm -rf $(DESTDIR)$(DATADIR)/lib + rm -rf $(DESTDIR)$(DATADIR)/git.conf.d for conf in $(notdir $(MAKEPKG_CONFIGS)); do rm -f $(DESTDIR)$(DATADIR)/makepkg.conf.d/$${conf##*/}; done for conf in $(notdir $(PACMAN_CONFIGS)); do rm -f $(DESTDIR)$(DATADIR)/pacman.conf.d/$${conf##*/}; done for f in $(notdir $(SETARCH_ALIASES)); do rm -f $(DESTDIR)$(DATADIR)/setarch-aliases.d/$$f; done diff --git a/config/git/template/hooks/applypatch-msg b/config/git/template/hooks/applypatch-msg new file mode 100755 index 0000000..1a24852 --- /dev/null +++ b/config/git/template/hooks/applypatch-msg @@ -0,0 +1 @@ +#!/bin/sh diff --git a/config/git/template/hooks/commit-msg b/config/git/template/hooks/commit-msg new file mode 100755 index 0000000..1a24852 --- /dev/null +++ b/config/git/template/hooks/commit-msg @@ -0,0 +1 @@ +#!/bin/sh diff --git a/config/git/template/hooks/post-applypatch b/config/git/template/hooks/post-applypatch new file mode 100755 index 0000000..1a24852 --- /dev/null +++ b/config/git/template/hooks/post-applypatch @@ -0,0 +1 @@ +#!/bin/sh diff --git a/config/git/template/hooks/post-checkout b/config/git/template/hooks/post-checkout new file mode 100755 index 0000000..1a24852 --- /dev/null +++ b/config/git/template/hooks/post-checkout @@ -0,0 +1 @@ +#!/bin/sh diff --git a/config/git/template/hooks/post-commit b/config/git/template/hooks/post-commit new file mode 100755 index 0000000..1a24852 --- /dev/null +++ b/config/git/template/hooks/post-commit @@ -0,0 +1 @@ +#!/bin/sh diff --git a/config/git/template/hooks/post-merge b/config/git/template/hooks/post-merge new file mode 100755 index 0000000..1a24852 --- /dev/null +++ b/config/git/template/hooks/post-merge @@ -0,0 +1 @@ +#!/bin/sh diff --git a/config/git/template/hooks/pre-applypatch b/config/git/template/hooks/pre-applypatch new file mode 100755 index 0000000..1a24852 --- /dev/null +++ b/config/git/template/hooks/pre-applypatch @@ -0,0 +1 @@ +#!/bin/sh diff --git a/config/git/template/hooks/pre-commit b/config/git/template/hooks/pre-commit new file mode 100755 index 0000000..1a24852 --- /dev/null +++ b/config/git/template/hooks/pre-commit @@ -0,0 +1 @@ +#!/bin/sh diff --git a/config/git/template/hooks/pre-merge-commit b/config/git/template/hooks/pre-merge-commit new file mode 100755 index 0000000..1a24852 --- /dev/null +++ b/config/git/template/hooks/pre-merge-commit @@ -0,0 +1 @@ +#!/bin/sh diff --git a/config/git/template/hooks/pre-push b/config/git/template/hooks/pre-push new file mode 100755 index 0000000..1a24852 --- /dev/null +++ b/config/git/template/hooks/pre-push @@ -0,0 +1 @@ +#!/bin/sh diff --git a/config/git/template/hooks/pre-rebase b/config/git/template/hooks/pre-rebase new file mode 100755 index 0000000..1a24852 --- /dev/null +++ b/config/git/template/hooks/pre-rebase @@ -0,0 +1 @@ +#!/bin/sh diff --git a/config/git/template/hooks/prepare-commit-msg b/config/git/template/hooks/prepare-commit-msg new file mode 100755 index 0000000..1a24852 --- /dev/null +++ b/config/git/template/hooks/prepare-commit-msg @@ -0,0 +1 @@ +#!/bin/sh diff --git a/config/git/template/info/exclude b/config/git/template/info/exclude new file mode 100644 index 0000000..ba46529 --- /dev/null +++ b/config/git/template/info/exclude @@ -0,0 +1,28 @@ +/pkg +/src +/*/ +!/keys/ + +/*.log +/*.tar.* +/*.tar +/*.tgz +/*.zst +/*.gz +/*.xz +/*.bz2 +/*.zip +/*.xpi +/*.jar +/*.whl +/*.war +/*.deb +/*.ttf +/*.dat +/*.iso +/*.asc +/*.sig +/*.signature +/*.sign +/*.SHA256SUMS +/*.sha256 diff --git a/doc/man/pkgctl-repo-configure.1.asciidoc b/doc/man/pkgctl-repo-configure.1.asciidoc index 6bdea93..12d879c 100644 --- a/doc/man/pkgctl-repo-configure.1.asciidoc +++ b/doc/man/pkgctl-repo-configure.1.asciidoc @@ -22,6 +22,8 @@ The remote protocol is automatically determined from the author email address by choosing SSH for all official packager identities and read-only HTTPS otherwise. +Git default excludes and hooks are applied to the configured repo. + Options ------- diff --git a/src/commitpkg.in b/src/commitpkg.in index 6d4b014..016ab22 100644 --- a/src/commitpkg.in +++ b/src/commitpkg.in @@ -71,6 +71,12 @@ if ! repo_spec=$(git config --local devtools.version) || [[ ${repo_spec} != "${G exit 1 fi +if ! repo_variant=$(git config --local devtools.variant) || [[ ${repo_variant} != canonical ]]; then + error "cannot release from a repository with none canonical specs (%s), try:" "${repo_variant:-development}" + msg2 'pkgctl repo configure' + exit 1 +fi + if [[ "$(git symbolic-ref --short HEAD)" != main ]]; then die 'must be run from the main branch' fi diff --git a/src/lib/common.sh b/src/lib/common.sh index 7589120..82fdd2e 100644 --- a/src/lib/common.sh +++ b/src/lib/common.sh @@ -22,7 +22,7 @@ export BUILDTOOLVER=@buildtoolver@ # Set common properties export PACMAN_KEYRING_DIR=/etc/pacman.d/gnupg export GITLAB_HOST=gitlab.archlinux.org -export GIT_REPO_SPEC_VERSION=1 +export GIT_REPO_SPEC_VERSION=2 export GIT_PACKAGING_NAMESPACE=archlinux/packaging/packages export GIT_PACKAGING_NAMESPACE_ID=11323 export GIT_PACKAGING_URL_SSH="git@${GITLAB_HOST}:${GIT_PACKAGING_NAMESPACE}" diff --git a/src/lib/repo/configure.sh b/src/lib/repo/configure.sh index 1ddb1b8..b3c188c 100644 --- a/src/lib/repo/configure.sh +++ b/src/lib/repo/configure.sh @@ -17,6 +17,7 @@ source /usr/share/makepkg/util/config.sh source /usr/share/makepkg/util/message.sh set -e +shopt -s nullglob pkgctl_repo_configure_usage() { @@ -34,6 +35,8 @@ pkgctl_repo_configure_usage() { address by choosing SSH for all official packager identities and read-only HTTPS otherwise. + Git default excludes and hooks are applied to the configured repo. + OPTIONS --protocol https Configure remote url to use https -j, --jobs N Run up to N jobs in parallel (default: $(nproc)) @@ -104,7 +107,7 @@ pkgctl_repo_configure() { # variables local -r command=${_DEVTOOLS_COMMAND:-${BASH_SOURCE[0]##*/}} - local path realpath pkgbase remote_url project_path + local path realpath pkgbase remote_url project_path hook local PACKAGER GPGKEY packager_name packager_email while (( $# )); do @@ -230,7 +233,15 @@ pkgctl_repo_configure() { git config branch.main.merge refs/heads/main fi + # configure spec version and variant to avoid using development hooks in production git config devtools.version "${GIT_REPO_SPEC_VERSION}" + if [[ ${_DEVTOOLS_LIBRARY_DIR} == /usr/share/devtools ]]; then + git config devtools.variant canonical + else + warning "Configuring with development version of pkgctl, do not use this repo in production" + git config devtools.variant development + fi + git config pull.rebase true git config branch.autoSetupRebase always git config branch.main.remote origin @@ -257,6 +268,18 @@ pkgctl_repo_configure() { git config user.signingKey "${GPGKEY}" fi + # set default git exclude + mkdir -p .git/info + ln -sf "${_DEVTOOLS_LIBRARY_DIR}/git.conf.d/template/info/exclude" \ + .git/info/exclude + + # set default git hooks + mkdir -p .git/hooks + rm -f .git/hooks/*.sample + for hook in "${_DEVTOOLS_LIBRARY_DIR}"/git.conf.d/template/hooks/*; do + ln -sf "${hook}" ".git/hooks/$(basename "${hook}")" + done + if ! git ls-remote origin &>/dev/null; then warning "configured remote origin may not exist, run:" msg2 "pkgctl repo create ${pkgbase}" -- cgit v1.2.3-54-g00ecf