summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2018-08-18 12:28:37 -0400
committerDave Reisner <dreisner@archlinux.org>2018-08-19 07:12:55 -0400
commitbb83e6b56361906ce781a9940ab9bea537f9a0a1 (patch)
tree255e6923d94b5f1800fde8ec55ef2430997a7264
parentf3c8955cd76c6a9caadc7b45fd63137769281dae (diff)
downloadasp32-bb83e6b56361906ce781a9940ab9bea537f9a0a1.tar.xz
Avoid cd, references to $startdir
just set GIT_DIR appropriately and always operate from the original $PWD. As part of this, let's cleanup our error handling in initialize() a fair bit.
-rw-r--r--asp.in28
-rw-r--r--package.inc.sh8
2 files changed, 16 insertions, 20 deletions
diff --git a/asp.in b/asp.in
index 62eea9e..99f69fe 100644
--- a/asp.in
+++ b/asp.in
@@ -126,27 +126,23 @@ initialize() {
local remote
umask 0022
- startdir=$PWD
- if [[ ! -d $ASPROOT ]]; then
- log_info 'Initializing ASPROOT in %s' "$ASPROOT"
- mkdir -p "$ASPROOT"
- fi
+ export GIT_DIR=$ASPROOT/.git
- cd "$ASPROOT" || log_fatal "ASPROOT (%s) does not exist!" "$ASPROOT"
+ if [[ ! -f $ASPROOT/.asp ]]; then
+ git init -q "$ASPROOT" || return 1
+ for remote in "${ARCH_GIT_REPOS[@]}"; do
+ git remote add "$remote" "https://git.archlinux.org/svntogit/$remote.git" || return 1
+ done
- if [[ ! -d $ASPCACHE ]] && ! mkdir -p "$ASPCACHE"; then
- log_fatal 'failed to create ASPCACHE (%s)' "$ASPCACHE"
+ touch "$ASPROOT/.asp" || return 1
fi
- [[ -f .asp ]] && return 0
-
- git init -q || return 1
- for remote in "${ARCH_GIT_REPOS[@]}"; do
- git remote add "$remote" "https://git.archlinux.org/svntogit/$remote.git"
- done
+ if [[ ! -d $ASPCACHE ]]; then
+ mkdir -p "$ASPCACHE" || return 1
+ fi
- touch .asp
+ return 0
}
dump_packages() {
@@ -340,7 +336,7 @@ dispatch_action() {
esac
}
-initialize
+initialize || log_fatal 'failed to initialize asp repository in %s' "$ASPROOT"
while getopts ':a:fhV' flag; do
case $flag in
diff --git a/package.inc.sh b/package.inc.sh
index 3a64912..6fcf8c3 100644
--- a/package.inc.sh
+++ b/package.inc.sh
@@ -147,12 +147,12 @@ package_export() {
if (( ! OPT_FORCE )); then
# shellcheck disable=SC2154
- mkdir "$startdir/$pkgname" || return
+ mkdir "$pkgname" || return
fi
log_info 'exporting %s:%s' "$pkgname" "$subtree"
git archive --format=tar "remotes/$remote/packages/$pkgname" "$subtree/" |
- tar -C "$startdir" --transform "s,^$subtree,$pkgname," -xf - "$subtree/"
+ tar --transform "s,^$subtree,$pkgname," -xf - "$subtree/"
}
package_checkout() {
@@ -165,9 +165,9 @@ package_checkout() {
git branch -qf --no-track {,}"$remote/packages/$pkgname"
quiet_git clone "$ASPROOT" --single-branch --branch "$remote/packages/$pkgname" \
- "$startdir/$pkgname" || return
+ "$pkgname" || return
- git --git-dir="$startdir/$pkgname/.git" config pull.rebase true
+ git --git-dir="$pkgname/.git" config pull.rebase true
}
package_get_repos_with_arch() {