2 # aur-fetch - retrieve build files from the AUR
3 [[ -v AUR_DEBUG
]] && set -o xtrace
6 XDG_CACHE_HOME
=${XDG_CACHE_HOME:-$HOME/.cache}
7 XDG_CONFIG_HOME
=${XDG_CONFIG_HOME:-$HOME/.config}
8 AUR_FETCH_USE_MIRROR
=${AUR_FETCH_USE_MIRROR:-0}
9 AUR_LOCATION
=${AUR_LOCATION:-https://aur.archlinux.org}
10 PS4
='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[1]}(): }'
12 # Author information for merge commits
13 export GIT_AUTHOR_NAME
=aurutils
14 export GIT_AUTHOR_EMAIL
=aurutils@localhost
15 export GIT_COMMITTER_NAME
=aurutils
16 export GIT_COMMITTER_EMAIL
=aurutils@localhost
18 # Placeholder for repositories without commits
19 git_empty_object
=$
(git hash-object
-t tree
/dev
/null
)
22 existing
=0 recurse
=0 discard
=0 sync
=fetch
25 local mode
=$1 prev
=$2 current
=$3 path
=$4 dest
=$5
27 if [[ -w $dest ]]; then
28 printf >> "$dest" '%s:%s:%s:file://%s\n' "$mode" "$prev" "$current" "$path"
32 sync_package_config
() {
35 if [[ $sync == 'auto' ]] && [[ $
(git config
--get --type bool aurutils.rebase
) == 'true' ]]; then
36 printf >&2 '%s: aurutils.rebase is set for %s\n' "$argv0" "$pkg"
39 elif [[ $sync == 'auto' ]]; then
48 ICAgICAgICAgICAgIC4tLX5
+LF9fCjotLi4uLiwtLS0tLS0tYH5
+Jy5fLicKIGAtLCwsICAs
49 XyAgICAgIDsnflUnCiAgXywtJyAsJ2AtX187ICctLS4KIChfLyd
+fiAgICAgICcnJycoOwoK
51 printf >&2 'usage: %s [-Sefr] [--rebase|--reset|--merge] [--] pkgname...\n' "$argv0"
56 source /usr
/share
/makepkg
/util
/parseopts.sh
59 opt_long
=('auto' 'merge' 'reset' 'rebase' 'discard' 'existing' 'results:' 'ff'
60 'ff-only' 'no-ff' 'no-commit' 'recurse')
61 opt_hidden
=('dump-options' 'sync:')
63 if ! parseopts
"$opt_short" "${opt_long[@]}" "${opt_hidden[@]}" -- "$@"; then
68 unset rebase_args merge_args results_file
85 shift; results_file
=$
(realpath
-- "$1") ;;
90 merge_args
+=(--ff-only) ;;
92 merge_args
+=(--no-commit) ;;
94 merge_args
+=(--no-ff); rebase_args
+=(--no-ff) ;;
95 # Compatibility options
101 printf -- '--%s\n' "${opt_long[@]}" ${AUR_DEBUG+"${opt_hidden[@]}"}
102 printf -- '%s' "${opt_short}" | sed 's/.:\?/-&\n/g'
110 if [[ $sync == !(auto|merge|rebase|reset|fetch) ]]; then
111 printf >&2 '%s: invalid --sync mode\n' "$argv0"
116 printf >&2 '%s: no arguments given\n' "$argv0"
120 # XXX: race with concurrent processes
121 if [[ -v results_file ]]; then
122 : >"$results_file" || exit 1 # truncate file
125 # Default to only allowing fast-forward merges (as git-pull)
126 if (( ! ${#merge_args[@]} )); then
127 merge_args=(--ff-only)
130 if (( recurse )); then
131 mapfile -t packages < <(aur depends --pkgbase "$@
")
134 elif (( $# == 1 )) && [[ $1 == "-" || $1 == "/dev
/stdin
" ]]; then
141 # Update revisions in local AUR mirror
142 declare -A local_clones
144 # With an AUR mirror, updates are retrieved in two steps. First, updates to the
145 # mirror are synchronized with `git-fetch`. Secondly, local clones of the miror
146 # are created and are updated with `git-fetch` and `git-merge` as usual.
147 if (( AUR_FETCH_USE_MIRROR )); then
148 while read -r IFS=':' pkg head; do
149 local_clones[$pkg]=$head
150 done < <(aur fetch--mirror --lclone "${packages[@]}")
155 for pkg in "${packages[@]}"; do
157 if (( AUR_FETCH_USE_MIRROR )); then # branch origin/$pkg -> master
160 upstream=origin/master
163 # Verify if the repository is hosted on AUR (#959)
164 if (( existing )) && ! git ls-remote --exit-code "$AUR_LOCATION/$pkg" >/dev/null; then
165 printf >&2 '%s: warning: package %s is not in AUR, skipping\n' "$argv0" "$pkg"
168 # Clone package if not existing
169 elif [[ ! -d $pkg/.git ]]; then
170 # Differentiate between local (fetch--mirror) and aurweb clones
171 if [[ ! ${local_clones[$pkg]} ]]; then
172 git clone "$AUR_LOCATION/$pkg" || exit 1
173 head=$(git -C "$pkg" rev-parse --verify quiet HEAD)
175 printf "Cloning into
'%s'\n" "$pkg"
176 head=${local_clones[$pkg]}
180 git -C "$pkg" --no-pager log --pretty=reference -1
183 # XXX: race with multiple instances
184 if [[ -v results_file ]]; then
185 results 'clone' "$git_empty_object" "${head:-$git_empty_object}" "$PWD/$pkg" "$results_file"
188 # Update existing git repository
191 exec {fd}< "$pkg"/.git
192 flock --wait 5 "$fd" || exit 1
194 # Avoid issues with filesystem boundaries (#274)
195 git() { command git -C "$pkg" "$@
"; }
197 # Retrieve new upstream commits
198 git fetch origin >&2 || exit
200 # Store original HEAD for --results output
201 orig_head=$(git rev-parse --verify --quiet HEAD)
202 orig_head=${orig_head:-$git_empty_object}
204 # Retrieve per-package configuration (defaults to global setting, #1007)
205 sync_pkg=$(sync_package_config "$sync" "$pkg")
207 # Reset working tree if new commits will be merged (--discard)
209 git merge-base --is-ancestor "$1" HEAD || git checkout ./
212 # Merge in new history
215 (( discard )) && reset_on_update 'master@{u}'
216 ;;& # proceed to merge or rebase
219 git rebase "${rebase_args[@]}" "$upstream" ;;
222 git merge "${merge_args[@]}" "$upstream" ;;
225 git reset --hard 'master@{u}' ;;
227 # Preserve local branch
230 printf >&2 '%s: failed to %s %s\n' "$argv0" "$sync_pkg" "$pkg"
233 head=$(git rev-parse --verify "$dest")
235 if [[ -v results_file ]]; then
236 results "$sync_pkg" "$orig_head" "$head" "$PWD/$pkg" "$results_file"
238 exec {fd}<&- # release lock
242 # vim: set et sw=4 sts=4 ft=sh: