diff --git a/CHANGELOG.md b/CHANGELOG.md index 96319a5..5acce8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 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 ` ([#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) diff --git a/abra b/abra index 9ef7453..8074855 100755 --- a/abra +++ b/abra @@ -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