From b7daff9b8b776eeed34385d8ae2019dc9e113c52 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 26 Apr 2012 15:37:56 -0400 Subject: [PATCH] setup-stage: Optionally reconfigure topic stage When the topic stage has already been configured present the current configuration and prompt for optional reconfiguration. While at it, make the topic stage remote name configurable by the project. --- setup-stage | 48 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/setup-stage b/setup-stage index ef53b99b7..323e47aea 100755 --- a/setup-stage +++ b/setup-stage @@ -37,17 +37,43 @@ die() { cd "${BASH_SOURCE%/*}" && # Load the project configuration. -url=$(git config -f config --get stage.url) && -pushurl=$(git config -f config --get stage.pushurl || echo '') || +fetchurl=$(git config -f config --get stage.url) && +pushurl_=$(git config -f config --get stage.pushurl || echo '') && +remote=$(git config -f config --get stage.remote || echo 'stage') || die 'This project is not configured to use a topic stage.' -# Configure the remote if necessary. -if git config remote.stage.url >/dev/null; then - echo 'Topic stage already configured.' -else - echo 'Setting up the topic stage...' && - git remote add stage "$url" && - if test -n "$pushurl"; then - git config remote.stage.pushurl "$pushurl" +# Get current stage push URL. +pushurl=$(git config --get remote."$remote".pushurl || + git config --get remote."$remote".url || echo '') && + +# Tell user about current configuration. +if test -n "$pushurl"; then + echo 'Remote "'"$remote"'" is currently configured to push to + + '"$pushurl"' +' && + read -ep 'Reconfigure Topic Stage? [y/N]: ' ans && + if [ "$ans" == "y" ] || [ "$ans" == "Y" ]; then + setup=1 + else + setup='' fi -fi || die 'Could not add the topic stage remote.' +else + setup=1 +fi + +# Perform setup if necessary. +if test -n "$setup"; then + echo 'Setting up the topic stage...' && + if test -z "$pushurl"; then + git remote add "$remote" "$fetchurl" + else + git config remote."$remote".url "$fetchurl" + fi && + pushurl="${pushurl_}" && + git config remote."$remote".pushurl "$pushurl" && + echo 'Remote "'"$remote"'" is now configured to push to + + '"$pushurl"' +' +fi || die 'Could not configure the topic stage remote.'