Fix branch handling (again, again)

Closes coop-cloud/abra#122.
This commit is contained in:
decentral1se 2021-03-25 22:13:08 +01:00
parent 36dd6b5eff
commit c315ebe319
Signed by untrusted user who does not match committer: decentral1se
GPG Key ID: 92DAD76BD9567B8A
2 changed files with 53 additions and 12 deletions

View File

@ -19,6 +19,8 @@
- Search for subcommands in descending order of how many components there are ([#108](https://git.autonomic.zone/coop-cloud/abra/issues/108))
- Add specific app version checking command (`abra app <app> version`) ([#108](https://git.autonomic.zone/coop-cloud/abra/issues/108))
- Add docker version check (guestimating < v20 is a bad idea) ([#15](https://git.autonomic.zone/coop-cloud/abra/issues/15))
- Fix git branch handling when not passing `-b <branch>` ([#122](https://git.autonomic.zone/coop-cloud/abra/issues/122))
- Add work-around to correctly git clone non-master default branch app repositories ([#122](https://git.autonomic.zone/coop-cloud/abra/issues/122))
# abra 0.6.0 (2021-03-17)

63
abra
View File

@ -429,19 +429,63 @@ require_consent_for_update() {
fi
}
require_plugin (){
PLUGIN="$1"
BRANCH="${abra___branch:-master}"
warning "The $PLUGIN plugin was not found, fetching via Git"
if [[ "$BRANCH" != "master" ]]; then
git_extra_args="--branch $BRANCH"
fi
# shellcheck disable=SC2086
if ! git clone ${git_extra_args:-} "$GIT_URL/$APP.git" "$ABRA_DIR/apps/$APP" > /dev/null 2>&1 ; then
error "Could not retrieve the $PLUGIN plugin, does it exist?"
fi
if [[ $(cd "$ABRA_DIR/apps/$APP" && git branch --list | wc -l) == "0" ]]; then
debug "Failed to clone default branch, guessing alternative is 'main'"
(cd "$ABRA_DIR/apps/$APP" && git checkout main > /dev/null 2>&1)
fi
success "Fetched the $PLUGIN plugin via Git"
}
require_app (){
APP="$1"
APP_DIR="$ABRA_DIR/apps/$APP"
BRANCH="${abra___branch:-master}"
warning "The app type '$APP' was not found, fetching via Git"
if [[ "$BRANCH" != "master" ]]; then
git_extra_args="--branch $BRANCH"
fi
# shellcheck disable=SC2086
if ! git clone ${git_extra_args:-} "$GIT_URL/$APP.git" "$ABRA_DIR/apps/$APP" > /dev/null 2>&1 ; then
error "Could not retrieve app type '$APP', this app type doesn't exist?"
fi
if [[ $(cd "$ABRA_DIR/apps/$APP" && git branch --list | wc -l) == "0" ]]; then
debug "Failed to clone default branch, guessing alternative is 'main'"
(cd "$ABRA_DIR/apps/$APP" && git checkout main > /dev/null 2>&1)
fi
success "Fetched app configuration via Git"
}
require_app_latest() {
APP="$1"
APP_DIR="$ABRA_DIR/apps/$APP"
BRANCH="${abra___branch:-master}"
debug "Checking for type '$APP'"
if [ ! -d "$APP_DIR" ]; then
warning "The app type '$APP' was not found, fetching via Git"
if ! git clone --branch "$BRANCH" "$GIT_URL/$APP.git" "$ABRA_DIR/apps/$APP" > /dev/null 2>&1 ; then
error "Could not retrieve app type '$APP', this app type doesn't exist?"
fi
success "Fetched app configuration via Git (branch: $BRANCH)"
require_app "$APP"
fi
debug "Using $APP_DIR"
@ -1712,18 +1756,13 @@ sub_server_new() {
require_abra_dir
PROVIDER="$abra__provider_"
BRANCH="${abra___branch:-master}"
if [ "$PROVIDER" != "hetzner" ]; then
error "Unknown provider plugin 'abra-${PROVIDER}'"
fi
if [ ! -d "$ABRA_DIR/plugins/abra-$PROVIDER" ]; then
warning "The 'abra-$PROVIDER' plugin was not found, fetching via Git"
if ! git clone --branch "$BRANCH" "$GIT_URL/abra-$PROVIDER.git" "$ABRA_DIR/plugins/abra-$PROVIDER" > /dev/null 2>&1 ; then
error "Could not retrieve the abra-$PROVIDER plugin, does it exist?"
fi
success "Fetched abra-$PROVIDER plugin via Git (branch: $BRANCH)"
require_plugin "abra-$PROVIDER"
fi
# shellcheck disable=SC1090