Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/src/lib/repo
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/repo')
-rw-r--r--src/lib/repo/clone.sh41
-rw-r--r--src/lib/repo/configure.sh33
-rw-r--r--src/lib/repo/web.sh23
3 files changed, 72 insertions, 25 deletions
diff --git a/src/lib/repo/clone.sh b/src/lib/repo/clone.sh
index a8cf6f5..33a333f 100644
--- a/src/lib/repo/clone.sh
+++ b/src/lib/repo/clone.sh
@@ -8,16 +8,21 @@ 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
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/repo/configure.sh
+# shellcheck source=src/lib/util/git.sh
+source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/git.sh
# shellcheck source=src/lib/repo/arch32.sh
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/repo/arch32.sh
source /usr/share/makepkg/util/message.sh
set -e
+set -o pipefail
pkgctl_repo_clone_usage() {
@@ -55,6 +60,7 @@ pkgctl_repo_clone() {
fi
# options
+ local protocol=ssh
local GIT_REPO_BASE_URL=${GIT_PACKAGING_URL_SSH}
local CLONE_ALL=0
local MAINTAINER=
@@ -76,6 +82,7 @@ pkgctl_repo_clone() {
;;
--protocol=https)
GIT_REPO_BASE_URL=${GIT_PACKAGING_URL_HTTPS}
+ protocol=https
CONFIGURE_OPTIONS+=("$1")
shift
;;
@@ -86,6 +93,7 @@ pkgctl_repo_clone() {
else
die "unsupported protocol: %s" "$2"
fi
+ protocol="$2"
CONFIGURE_OPTIONS+=("$1" "$2")
shift 2
;;
@@ -140,33 +148,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
@@ -179,6 +172,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..b3c188c 100644
--- a/src/lib/repo/configure.sh
+++ b/src/lib/repo/configure.sh
@@ -10,11 +10,14 @@ _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
set -e
+shopt -s nullglob
pkgctl_repo_configure_usage() {
@@ -32,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))
@@ -102,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
@@ -188,6 +193,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
@@ -222,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
@@ -249,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}"
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
}