mirror of
https://gitlab.archlinux.org/archlinux/devtools.git
synced 2025-10-24 05:22:05 +02:00
Compare commits
2 Commits
master
...
4cd8344f90
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4cd8344f90 | ||
|
|
d58a992774 |
@@ -150,7 +150,6 @@ _pkgctl_cmds=(
|
||||
db
|
||||
diff
|
||||
issue
|
||||
license
|
||||
release
|
||||
repo
|
||||
search
|
||||
@@ -306,6 +305,7 @@ _pkgctl_repo_cmds=(
|
||||
clone
|
||||
configure
|
||||
create
|
||||
pull
|
||||
switch
|
||||
web
|
||||
)
|
||||
@@ -335,6 +335,19 @@ _pkgctl_repo_clean_args=(
|
||||
)
|
||||
_pkgctl_repo_clean_opts() { _filedir -d; }
|
||||
|
||||
_pkgctl_repo_pull_args=(
|
||||
--discard-changes
|
||||
--show-diff
|
||||
--quiet
|
||||
--autostash
|
||||
-f --force
|
||||
-j --jobs
|
||||
-h --help
|
||||
)
|
||||
_pkgctl_repo_pull_args__jobs_opts() { :; }
|
||||
_pkgctl_repo_pull_args_j_opts() { _pkgctl_repo_pull_args__jobs_opts; }
|
||||
_pkgctl_repo_pull_opts() { _filedir -d; }
|
||||
|
||||
_pkgctl_repo_configure_args=(
|
||||
--protocol
|
||||
-j --jobs
|
||||
|
||||
@@ -228,6 +228,7 @@ _pkgctl_repo_cmds=(
|
||||
"clone[Clone a package repository]"
|
||||
"configure[Configure a clone according to distro specs]"
|
||||
"create[Create a new GitLab package repository]"
|
||||
"pull[Update package repositories from their git remote]"
|
||||
"switch[Switch a package repository to a specified version]"
|
||||
"web[Open the packaging repository's website]"
|
||||
)
|
||||
@@ -256,6 +257,17 @@ _pkgctl_repo_clone_args=(
|
||||
'*:packages:_devtools_completions_all_packages'
|
||||
)
|
||||
|
||||
_pkgctl_repo_pull_args=(
|
||||
'--discard-changes[Discard changes if index or working tree is dirty]'
|
||||
'--quiet[Disable printing longer terminal output]'
|
||||
'--show-diff[Always enable showing the diff]'
|
||||
'--autostash[Stash before pulling and unstash afterwards]'
|
||||
'(-f --force)'{-f,--force}'[Alias for --discard-changes]'
|
||||
'(-j --jobs)'{-j,--jobs}'[Run up to N jobs in parallel (default: number of processing units)]:jobs:'
|
||||
'(-h --help)'{-h,--help}'[Display usage]'
|
||||
'*:git_dir:_files -/'
|
||||
)
|
||||
|
||||
_pkgctl_repo_configure_args=(
|
||||
'--protocol[Configure remote url to use https]:proto:(https)'
|
||||
'(-j --jobs)'{-j,--jobs}'[Run up to N jobs in parallel (default: number of processing units)]:jobs:'
|
||||
|
||||
@@ -3,7 +3,7 @@ pkgctl-auth(1)
|
||||
|
||||
Name
|
||||
----
|
||||
pkgctl-auth - Authenticate with services like GitLab.
|
||||
pkgctl-auth - Authenticate with serivces like GitLab.
|
||||
|
||||
Synopsis
|
||||
--------
|
||||
|
||||
50
doc/man/pkgctl-repo-pull.1.asciidoc
Normal file
50
doc/man/pkgctl-repo-pull.1.asciidoc
Normal file
@@ -0,0 +1,50 @@
|
||||
pkgctl-repo-pull(1)
|
||||
===================
|
||||
|
||||
Name
|
||||
----
|
||||
pkgctl-repo-pull - Pull in git changes
|
||||
|
||||
Synopsis
|
||||
--------
|
||||
pkgctl repo pull [OPTIONS] [PATH...]
|
||||
|
||||
Description
|
||||
-----------
|
||||
|
||||
Update package repositories from their git remotes.
|
||||
|
||||
If only a single package is given the command also automatically shows a diff
|
||||
of what has changed since the last time the repository was updated.
|
||||
|
||||
Options
|
||||
-------
|
||||
|
||||
*--discard-changes*::
|
||||
Discard changes if the index or working tree was modified. Otherwise abort
|
||||
if anything was modified.
|
||||
|
||||
*--autostash*::
|
||||
Stash before pulling and unstash afterwards
|
||||
|
||||
*--quiet*::
|
||||
Do not show any longer terminal output like diffs.
|
||||
|
||||
*--show-diff*::
|
||||
Show what has changed since the last time the repository was updated. Is
|
||||
automatically set when only one 'PATH' is given.
|
||||
|
||||
*-j, --jobs* 'N'::
|
||||
Run up to N jobs in parallel. By default the number of jobs is equal to the
|
||||
number of available processing units. For sequential processing this option
|
||||
needs to be passed with 1.
|
||||
|
||||
*-h, --help*::
|
||||
Show a help text
|
||||
|
||||
See Also
|
||||
--------
|
||||
|
||||
git-pull(1)
|
||||
|
||||
include::include/footer.asciidoc[]
|
||||
@@ -44,6 +44,9 @@ pkgctl repo configure::
|
||||
pkgctl repo create::
|
||||
Create a new GitLab package repository
|
||||
|
||||
pkgctl repo pull::
|
||||
Update package repositories from their git remotes
|
||||
|
||||
pkgctl repo switch::
|
||||
Switch a package repository to a specified version
|
||||
|
||||
@@ -57,6 +60,7 @@ pkgctl-repo-clean(1)
|
||||
pkgctl-repo-clone(1)
|
||||
pkgctl-repo-configure(1)
|
||||
pkgctl-repo-create(1)
|
||||
pkgctl-repo-pull(1)
|
||||
pkgctl-repo-switch(1)
|
||||
pkgctl-repo-web(1)
|
||||
|
||||
|
||||
@@ -39,17 +39,6 @@ placed in the `$XDG_CONFIG_HOME`/nvchecker` directory. This keyfile is
|
||||
used for providing the necessary authentication tokens required for
|
||||
accessing the GitHub or GitLab API.
|
||||
|
||||
Combiner Source
|
||||
---------------
|
||||
|
||||
To utilize the combiner source, the `pkgbase` section must be declared as the
|
||||
combiner source. Additionally, individual sections should be added using a
|
||||
quoted table key consisting of the `pkgbase` followed by the stage name,
|
||||
separated by double colons. For example: `["sudo:stage1"]`.
|
||||
|
||||
This allows to chain different sources together into one result, or allow
|
||||
multi stage transformation of our source via multiple regex.
|
||||
|
||||
Options
|
||||
-------
|
||||
|
||||
|
||||
@@ -49,9 +49,6 @@ pkgctl diff::
|
||||
pkgctl issue::
|
||||
Work with GitLab packaging issues
|
||||
|
||||
pkgctl license::
|
||||
Check and manage package licenses
|
||||
|
||||
pkgctl release::
|
||||
Release step to commit, tag and upload build artifacts
|
||||
|
||||
@@ -73,7 +70,6 @@ pkgctl-build(1)
|
||||
pkgctl-db(1)
|
||||
pkgctl-diff(1)
|
||||
pkgctl-issue(1)
|
||||
pkgctl-license(1)
|
||||
pkgctl-release(1)
|
||||
pkgctl-repo(1)
|
||||
pkgctl-search(1)
|
||||
|
||||
@@ -54,8 +54,7 @@ export RSYNC_OPTS=(
|
||||
--human-readable
|
||||
--progress
|
||||
--partial
|
||||
# suffix the partial dir with the PID in order to avoid clashes
|
||||
--partial-dir=.partial.$$
|
||||
--partial-dir=.partial
|
||||
--delay-updates
|
||||
)
|
||||
|
||||
@@ -442,10 +441,3 @@ relative_date_unit() {
|
||||
done
|
||||
printf "1 second"
|
||||
}
|
||||
|
||||
|
||||
# escapes regex metacharacters in a given string
|
||||
regex_escape() {
|
||||
# shellcheck disable=SC2001,SC2016
|
||||
sed 's/[\^.\[$()|*+?{\\]/\\&/g' <<<"$1"
|
||||
}
|
||||
|
||||
@@ -94,19 +94,19 @@ pkgctl_license_check() {
|
||||
pushd "${path}" >/dev/null
|
||||
|
||||
if [[ ! -f PKGBUILD ]]; then
|
||||
msg_error "${BOLD}${path}:${ALL_OFF} no PKGBUILD found"
|
||||
msg_error "${BOLD}${pkgbase}:${ALL_OFF} no PKGBUILD found"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ ! -f .SRCINFO ]]; then
|
||||
msg_error "${BOLD}${path}:${ALL_OFF} no .SRCINFO found"
|
||||
return 1
|
||||
fi
|
||||
# reset common PKGBUILD variables
|
||||
unset pkgbase
|
||||
|
||||
if ! pkgbase=$(grep --max-count=1 --extended-regexp "pkgbase = (.+)" .SRCINFO | awk '{print $3}'); then
|
||||
msg_error "${BOLD}${path}:${ALL_OFF} pkgbase not found in .SRCINFO"
|
||||
# shellcheck source=contrib/makepkg/PKGBUILD.proto
|
||||
if ! . ./PKGBUILD; then
|
||||
msg_error "${BOLD}${pkgbase}:${ALL_OFF} failed to source PKGBUILD"
|
||||
return 1
|
||||
fi
|
||||
pkgbase=${pkgbase:-$pkgname}
|
||||
|
||||
if [[ ! -e LICENSE ]]; then
|
||||
msg_error "${BOLD}${pkgbase}:${ALL_OFF} is missing the LICENSE file"
|
||||
|
||||
@@ -188,7 +188,6 @@ path = [
|
||||
"README.md",
|
||||
"keys/**",
|
||||
".SRCINFO",
|
||||
".gitignore",
|
||||
".nvchecker.toml",
|
||||
"*.install",
|
||||
"*.sysusers",
|
||||
|
||||
@@ -31,6 +31,7 @@ pkgctl_repo_usage() {
|
||||
clone Clone a package repository
|
||||
configure Configure a clone according to distro specs
|
||||
create Create a new GitLab package repository
|
||||
pull Update package repositories from their git remote
|
||||
switch Switch a package repository to a specified version
|
||||
web Open the packaging repository's website
|
||||
|
||||
@@ -40,6 +41,7 @@ pkgctl_repo_usage() {
|
||||
EXAMPLES
|
||||
$ ${COMMAND} clean --interactive *
|
||||
$ ${COMMAND} clone libfoo linux libbar
|
||||
$ ${COMMAND} pull libfoo linux libbar
|
||||
$ ${COMMAND} clone --maintainer mynickname
|
||||
$ ${COMMAND} configure *
|
||||
$ ${COMMAND} create libfoo
|
||||
@@ -101,6 +103,14 @@ pkgctl_repo() {
|
||||
pkgctl_repo_switch "$@"
|
||||
exit 0
|
||||
;;
|
||||
pull)
|
||||
_DEVTOOLS_COMMAND+=" $1"
|
||||
shift
|
||||
# shellcheck source=src/lib/repo/pull.sh
|
||||
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/repo/pull.sh
|
||||
pkgctl_repo_pull "$@"
|
||||
exit 0
|
||||
;;
|
||||
web)
|
||||
_DEVTOOLS_COMMAND+=" $1"
|
||||
shift
|
||||
|
||||
195
src/lib/repo/pull.sh
Normal file
195
src/lib/repo/pull.sh
Normal file
@@ -0,0 +1,195 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
[[ -z ${DEVTOOLS_INCLUDE_REPO_PULL_SH:-} ]] || return 0
|
||||
DEVTOOLS_INCLUDE_REPO_PULL_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/util/git.sh
|
||||
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/git.sh
|
||||
|
||||
source /usr/share/makepkg/util/message.sh
|
||||
|
||||
set -eo pipefail
|
||||
|
||||
|
||||
pkgctl_repo_pull_usage() {
|
||||
local -r COMMAND=${_DEVTOOLS_COMMAND:-${BASH_SOURCE[0]##*/}}
|
||||
cat <<- _EOF_
|
||||
Usage: ${COMMAND} [OPTIONS] [PKGBASE]...
|
||||
|
||||
Update package repositories from their git remotes.
|
||||
|
||||
OPTIONS
|
||||
--discard-changes Discard changes if index or working tree is dirty
|
||||
--show-diff Always enable showing the diff
|
||||
--autostash Stash before pulling and unstash afterwards
|
||||
-j, --jobs N Run up to N jobs in parallel (default: $(nproc))
|
||||
--quiet Disable printing longer terminal output
|
||||
-h, --help Show this help text
|
||||
|
||||
EXAMPLES
|
||||
$ ${COMMAND} gopass gopass-jsonapi
|
||||
_EOF_
|
||||
}
|
||||
|
||||
pkgctl_repo_pull() {
|
||||
# options
|
||||
local paths path pkgbase branch jobs remote
|
||||
jobs=$(nproc)
|
||||
local command=${_DEVTOOLS_COMMAND:-${BASH_SOURCE[0]##*/}}
|
||||
local git_rebase_options=()
|
||||
local SHOW_DIFF=0
|
||||
local QUIET=0
|
||||
local DISCARD_CHANGES=0
|
||||
local AUTOSTASH=0
|
||||
|
||||
while (( $# )); do
|
||||
case $1 in
|
||||
-h|--help)
|
||||
pkgctl_repo_pull_usage
|
||||
exit 0
|
||||
;;
|
||||
--discard-changes)
|
||||
DISCARD_CHANGES=1
|
||||
shift
|
||||
;;
|
||||
--show-diff)
|
||||
SHOW_DIFF=1
|
||||
shift
|
||||
;;
|
||||
--quiet)
|
||||
QUIET=1
|
||||
shift
|
||||
;;
|
||||
--autostash)
|
||||
AUTOSTASH=1
|
||||
git_rebase_options+=(--autostash)
|
||||
shift
|
||||
;;
|
||||
-j|--jobs)
|
||||
(( $# <= 1 )) && die "missing argument for %s" "$1"
|
||||
jobs=$2
|
||||
shift 2
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
-*)
|
||||
die "invalid argument: %s" "$1"
|
||||
;;
|
||||
*)
|
||||
paths=("$@")
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# check if invoked without any path from within a packaging repo
|
||||
if (( ${#paths[@]} == 0 )); then
|
||||
paths=(".")
|
||||
fi
|
||||
|
||||
# check if we are only working on one repo and enable
|
||||
if (( ${#paths[@]} == 1 )) && (( ! QUIET )); then
|
||||
SHOW_DIFF=1
|
||||
fi
|
||||
|
||||
# parallelization
|
||||
if [[ ${jobs} != 1 ]] && (( ${#paths[@]} > 1 )); then
|
||||
if [[ -n ${BOLD} ]]; then
|
||||
export DEVTOOLS_COLOR=always
|
||||
fi
|
||||
|
||||
# warm up ssh connection as it may require user input (key unlock, hostkey verification etc)
|
||||
git_warmup_ssh_connection
|
||||
|
||||
# disable diffs if not enabled explicitly
|
||||
if (( ! SHOW_DIFF )); then
|
||||
command+=" --quiet"
|
||||
fi
|
||||
|
||||
if (( DISCARD_CHANGES )); then
|
||||
command+=" --discard-changes"
|
||||
fi
|
||||
|
||||
if (( AUTOSTASH )); then
|
||||
command+=" --autostash"
|
||||
fi
|
||||
|
||||
if ! parallel --bar --jobs "${jobs}" "${command}" ::: "${paths[@]}"; then
|
||||
die 'Failed to pull some packages, please check the previous output'
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
for path in "${paths[@]}"; do
|
||||
# skip paths that are not directories
|
||||
if [[ ! -d "${path}" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
if [[ ! -f "${path}/PKGBUILD" ]]; then
|
||||
msg_error " Not a package repository: ${path}"
|
||||
continue
|
||||
fi
|
||||
|
||||
if [[ ! -d "${path}/.git" ]]; then
|
||||
msg_error " Not a Git repository: ${path}"
|
||||
continue
|
||||
fi
|
||||
|
||||
pkgbase=$(basename "$(realpath "${path}")")
|
||||
pkgbase=${pkgbase%.git}
|
||||
msg "Updating ${pkgbase}"
|
||||
|
||||
branch=$(git -C "${path}" symbolic-ref --quiet --short HEAD)
|
||||
if [[ ${branch} != main ]]; then
|
||||
msg_warn " Current branch is ${branch}, not updating from canonical upstream: ${pkgbase}"
|
||||
fi
|
||||
|
||||
if ! git -C "${path}" diff-files --quiet && (( ! AUTOSTASH )) && (( ! DISCARD_CHANGES )); then
|
||||
msg_error " Index contains unstaged changes, please stash them or pass --autostash before pulling: ${pkgbase}"
|
||||
continue
|
||||
fi
|
||||
|
||||
if ! git -C "${path}" diff-index --cached --quiet HEAD && (( ! AUTOSTASH )) && (( ! DISCARD_CHANGES )); then
|
||||
msg_error " Index contains uncommited changes, please commit or stash them before pulling: ${pkgbase}"
|
||||
continue
|
||||
fi
|
||||
|
||||
remote=$(git -C "${path}" config "branch.${branch}.remote")
|
||||
if [[ -z "${remote}" ]]; then
|
||||
msg_error " No upstream tracking branch configured: ${pkgbase}"
|
||||
continue
|
||||
fi
|
||||
|
||||
if ! git -C "${path}" fetch --quiet "${remote}"; then
|
||||
msg_error " Error while fetching: ${pkgbase}"
|
||||
continue
|
||||
fi
|
||||
|
||||
if [[ $(git -C "${path}" rev-parse HEAD) == $(git -C "${path}" rev-parse FETCH_HEAD) ]]; then
|
||||
msg2 "Repo is up to date, nothing to do"
|
||||
continue
|
||||
fi
|
||||
|
||||
# discard any local modifications
|
||||
if (( DISCARD_CHANGES )); then
|
||||
git -C "${path}" restore --staged --worktree -- .
|
||||
fi
|
||||
|
||||
if (( SHOW_DIFF )) && (( ! QUIET )); then
|
||||
git -C "${path}" --no-pager diff --color --patch-with-stat HEAD..FETCH_HEAD
|
||||
fi
|
||||
|
||||
if ! git -C "${path}" rebase --quiet "${git_rebase_options[@]}" "${remote}/${branch}"; then
|
||||
msg_error " Error while pulling in the changes for ${pkgbase}"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
@@ -6,8 +6,6 @@
|
||||
DEVTOOLS_INCLUDE_UTIL_PKGBUILD_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/util/makepkg.sh
|
||||
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/makepkg.sh
|
||||
|
||||
@@ -23,8 +21,6 @@ pkgbuild_set_pkgver() {
|
||||
local new_pkgver=$1
|
||||
local pkgver=${pkgver}
|
||||
|
||||
pkgver="$(regex_escape "${pkgver}")"
|
||||
|
||||
if [[ $(type -t pkgver) == function ]]; then
|
||||
# TODO: check if die or warn, if we provide _commit _gitcommit setter maybe?
|
||||
warning 'setting pkgver variable has no effect if the PKGBUILD has a pkgver() function'
|
||||
|
||||
@@ -304,11 +304,6 @@ get_upstream_version() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! output=$(jq --raw-output --exit-status 'select(.name == "'"${pkgbase}"'")' <<< "${output}"); then
|
||||
printf "failed to select pkgbase result from output"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! upstream_version=$(jq --raw-output --exit-status '.version' <<< "${output}"); then
|
||||
printf "failed to select version from result"
|
||||
return 1
|
||||
@@ -351,16 +346,10 @@ nvchecker_check_config() {
|
||||
fi
|
||||
|
||||
# check if the config contains any section other than pkgbase
|
||||
if [[ -n ${pkgbase} ]] && property=$(grep --max-count=1 --perl-regexp "^\\[(?!\"?${pkgbase//+/\\+}(:.+)?\"?\\]).+\\]" < "${config}"); then
|
||||
if [[ -n ${pkgbase} ]] && property=$(grep --max-count=1 --perl-regexp "^\\[(?!\"?${pkgbase//+/\\+}\"?\\]).+\\]" < "${config}"); then
|
||||
printf "non-pkgbase section not supported in %s: %s" "${config}" "${property}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# check if the config is using the 'cmd' source
|
||||
if grep --extended-regexp --quiet '^\s*source\s*=\s*["'\'']cmd["'\''].*' "${config}"; then
|
||||
printf "using the 'cmd' source in %s is disallowed" "${config}"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
nvchecker_check_error() {
|
||||
|
||||
Reference in New Issue
Block a user