From 72d5cc327d898fd369fbd78da3ce516b9ba4f3fc Mon Sep 17 00:00:00 2001 From: Geoffroy Aubry Date: Sun, 1 Jul 2012 11:33:43 +0200 Subject: [PATCH] Convert ui.inc.sh to an external library with pseudo namespace: coloredUI.inc.sh With unit tests. closes #13 --- conf/phpunit-dist.xml | 4 +- inc/coloredUI.inc.sh | 136 +++++++++++++++++++++++++ inc/common.inc.sh | 136 +++++++++++++------------ inc/options_handler.inc.sh | 2 +- inc/twgit_feature.inc.sh | 128 ++++++++++++------------ inc/twgit_hotfix.inc.sh | 55 +++++----- inc/twgit_release.inc.sh | 92 ++++++++--------- inc/twgit_tag.inc.sh | 20 ++-- inc/ui.inc.sh | 111 --------------------- tests/TwgitCUITest.php | 193 ++++++++++++++++++++++++++++++++++++ tests/inc/TwgitTestCase.php | 34 ++++--- tests/inc/testFunction.sh | 2 +- twgit | 64 ++++++------ 13 files changed, 607 insertions(+), 370 deletions(-) create mode 100644 inc/coloredUI.inc.sh delete mode 100644 inc/ui.inc.sh create mode 100644 tests/TwgitCUITest.php diff --git a/conf/phpunit-dist.xml b/conf/phpunit-dist.xml index 7a6e973..d576074 100644 --- a/conf/phpunit-dist.xml +++ b/conf/phpunit-dist.xml @@ -13,8 +13,8 @@ strict="true" verbose="true" stopOnFailure="false" - timeoutForSmallTests="8" - timeoutForMediumTests="10" + timeoutForSmallTests="20" + timeoutForMediumTests="40" timeoutForLargeTests="60" > diff --git a/inc/coloredUI.inc.sh b/inc/coloredUI.inc.sh new file mode 100644 index 0000000..9e99616 --- /dev/null +++ b/inc/coloredUI.inc.sh @@ -0,0 +1,136 @@ +#!/bin/bash + +## +# Provide an easy way to display colored and decorated messages in Bash: title, question, error, warning, success... +# Just include this script, define colors, bold colors and headers, then call CUI_displayMsg() method. +# +# Generic example: +# CUI_displayMsg type 'Message with bold section.' +# `==> 'message with bold section.\033[0m' +# +# Concrete example: +# . coloredUI.inc.sh +# CUI_COLORS=( +# [error]='\033[1;31m' +# [help]='\033[0;36m' +# [help.bold]='\033[1;36m' +# [help.header]='\033[1;36m(i) ' +# ) +# CUI_displayMsg error 'Invalid number!' +# `==> '\033[1;31mInvalid number!\033[0m' +# CUI_displayMsg help 'This is a valuable information.' +# `==> '\033[1;36m(i) \033[0;36mThis is a \033[1;36mvaluable\033[0;36m information.\033[0m' +# +# Requirements: +# - Bash v4 (2009) and above +# +# Color codes : +# - http://www.tux-planet.fr/les-codes-de-couleurs-en-bash/ +# - http://confignewton.com/wp-content/uploads/2011/07/bash_color_codes.png +# +# +# +# Copyright (c) 2012 Geoffroy Aubry +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed +# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License +# for the specific language governing permissions and limitations under the License. +# +# @copyright 2012 Geoffroy Aubry +# @license http://www.apache.org/licenses/LICENSE-2.0 +# + + + +## +# Default colors +# @var associative array +# +declare -A CUI_COLORS +CUI_COLORS=( + [error]='\033[1;31m' + [error.bold]='\033[1;33m' + [error.header]='\033[1m\033[4;33m/!\\\033[0;37m ' + [feature_subject]='\033[1;34m' + [help]='\033[0;36m' + [help.bold]='\033[1;36m' + [help.header]='\033[1;36m(i) ' + [help_detail]='\033[0;37m' + [help_detail.bold]='\033[1;37m' + [help_detail.header]=' ' + [info]='\033[1;37m' + [normal]='\033[0;37m' + [ok]='\033[0;32m' + [processing]='\033[1;30m' + [question]='\033[1;33m' + [question.bold]='\033[1;37m' + [warning]='\033[0;33m' + [warning.bold]='\033[1;33m' + [warning.header]='\033[1m\033[4;33m/!\\\033[0;37m ' +) + +## +# Check if the specified key exists in $CUI_COLORS associative array. +# +# @param string $1 key to check +# @return int 0 if key exists, else 1 +# @testedby TwgitCUITest +# +function CUI_isSet () { + local key="$1" + return $(echo " ${!CUI_COLORS[*]} " | tr '\n' ' ' | grep " $key " -q) +} + +## +# Display a message of the specified type, using ${CUI_COLORS[$type]}. +# If ${CUI_COLORS[$type.color]} exists, then this will be used as prefix. +# If ${CUI_COLORS[$type.bold]} exists, then this will be used to display text in '...' tags. +# In any case tags will be stripped. +# +# @param string $1 type of the message (error, title, ...) +# @param string $2..$n message +# @see $CUI_COLORS +# @testedby TwgitCUITest +# +function CUI_displayMsg () { + local type=$1; shift + local msg="$*" + local bold_pattern_start bold_pattern_end header + + # Color: + if ! CUI_isSet "$type"; then + echo "Unknown display type '$type'!" >&2 + echo -n 'Available types: ' >&2 + local types=$(echo "${!CUI_COLORS[*]}" | grep -vE "\.bold$" | grep -vE "\.header$" | sort) + local trimmed_types=$(echo $types) + echo "${trimmed_types// /, }." >&2 + exit 1 + fi + + # Header: + if ! CUI_isSet "$type.header"; then + header='' + else + header="${CUI_COLORS[$type'.header']}" + fi + + # Bold pattern: + if ! CUI_isSet "$type.bold"; then + bold_pattern_start='' + bold_pattern_end='' + else + bold_pattern_start="${CUI_COLORS[$type'.bold']}" + bold_pattern_end="${CUI_COLORS[$type]}" + fi + + # Display: + echo -en "$header${CUI_COLORS[$type]}" + echo -en "$msg" | sed "s//$(echo -e $bold_pattern_start | sed -e 's/[\/&]/\\&/g')/g" \ + | sed "s/<\/b>/$(echo -e $bold_pattern_end | sed -e 's/[\/&]/\\&/g')/g" + echo -e '\033[0m' +} diff --git a/inc/common.inc.sh b/inc/common.inc.sh index a019951..9a87c8c 100644 --- a/inc/common.inc.sh +++ b/inc/common.inc.sh @@ -25,7 +25,7 @@ . $TWGIT_INC_DIR/options_handler.inc.sh -. $TWGIT_INC_DIR/ui.inc.sh +. $TWGIT_INC_DIR/coloredUI.inc.sh @@ -406,11 +406,11 @@ function getFeatureSubject () { if [ -z "$subject" ] && [ ! -z "$TWGIT_FEATURE_SUBJECT_CONNECTOR" ]; then local connector="$(printf "$TWGIT_FEATURE_SUBJECT_CONNECTOR_PATH" "$TWGIT_FEATURE_SUBJECT_CONNECTOR")" if [ ! -f "$connector" ]; then - warn "'$TWGIT_FEATURE_SUBJECT_CONNECTOR' connector not found!" + CUI_displayMsg warning "'$TWGIT_FEATURE_SUBJECT_CONNECTOR' connector not found!" else subject="$(. $connector $short_name 2>/dev/null)" if [ $? -ne 0 ]; then - error "'$TWGIT_FEATURE_SUBJECT_CONNECTOR' connector failed!" + CUI_displayMsg error "'$TWGIT_FEATURE_SUBJECT_CONNECTOR' connector failed!" elif [ ! -z "$subject" ]; then echo "$short_name;$subject" >> "$TWGIT_FEATURES_SUBJECT_PATH" fi @@ -474,7 +474,7 @@ function assert_git_repository () { # @param string $2 nom complet d'une branche distante # function assert_branches_equal () { - processing "Compare branches '$1' with '$2'..." + CUI_displayMsg processing "Compare branches '$1' with '$2'..." if ! has $1 $(get_local_branches); then die "Local branch '$1' does not exist and is required!" elif ! has $2 $(get_remote_branches); then @@ -484,18 +484,18 @@ function assert_branches_equal () { compare_branches "$1" "$2" local status=$? if [ $status -gt 0 ]; then - warn "Branches '$1' and '$2' have diverged." + CUI_displayMsg warning "Branches '$1' and '$2' have diverged." if [ $status -eq 1 ]; then - warn "And local branch '$1' may be fast-forwarded!" + CUI_displayMsg warning "And local branch '$1' may be fast-forwarded!" if ! isset_option 'I'; then - echo -n $(question "Pull '$1'? [Y/N] "); read answer + echo -n $(CUI_displayMsg question "Pull '$1'? [Y/N] "); read answer [ "$answer" != "Y" ] && [ "$answer" != "y" ] && die "Pull aborted! You must make a 'git pull $TWGIT_ORIGIN $1' to continue." fi exec_git_command "git checkout $1" "Checkout '$1' failed!" exec_git_command "git merge $2" "Update '$1' failed!" elif [ $status -eq 2 ]; then # Warn here (not die), since there is no harm in being ahead: - warn "And local branch '$1' is ahead of '$2'." + CUI_displayMsg warning "And local branch '$1' is ahead of '$2'." else die "Branches need merging first!" fi @@ -512,15 +512,15 @@ function assert_branches_equal () { # function assert_new_local_branch () { local branch="$1" - processing 'Check local branches...' + CUI_displayMsg processing 'Check local branches...' if has $branch $(get_local_branches); then - processing "Local branch '$branch' already exists!" + CUI_displayMsg processing "Local branch '$branch' already exists!" if ! has "$TWGIT_ORIGIN/$branch" $(get_remote_branches); then - error "Remote feature '$TWGIT_ORIGIN/$branch' not found while local one exists!" - help 'Perhaps:' - help_detail "- check the name of your branch" - help_detail "- delete this out of process local branch: git branch -D $branch" - help_detail "- or force renewal if feature: twgit feature start -d xxxx" + CUI_displayMsg error "Remote feature '$TWGIT_ORIGIN/$branch' not found while local one exists!" + CUI_displayMsg help 'Perhaps:' + CUI_displayMsg help_detail "- check the name of your branch" + CUI_displayMsg help_detail "- delete this out of process local branch: git branch -D $branch" + CUI_displayMsg help_detail "- or force renewal if feature: twgit feature start -d xxxx" else exec_git_command "git checkout $branch" "Could not checkout '$branch'!" inform_about_branch_status "$branch" @@ -535,9 +535,9 @@ function assert_new_local_branch () { # S'assure que le dépôt git courant est dans le status 'working directory clean'. # function assert_clean_working_tree () { - processing 'Check clean working tree...' + CUI_displayMsg processing 'Check clean working tree...' if [ `git status --porcelain --ignore-submodules=all | wc -l` -ne 0 ]; then - error 'Untracked files or changes to be committed in your working tree!' + CUI_displayMsg error 'Untracked files or changes to be committed in your working tree!' exec_git_command 'git status' 'Git status failed!' exit 1 fi @@ -549,7 +549,7 @@ function assert_clean_working_tree () { # @param string $1 référence de branche # function assert_valid_ref_name () { - processing 'Check valid ref name...' + CUI_displayMsg processing 'Check valid ref name...' git check-ref-format --branch "$1" 1>/dev/null 2>&1 if [ $? -ne 0 ]; then die "'$1' is not a valid reference name!" @@ -574,10 +574,10 @@ function assert_valid_ref_name () { function assert_valid_tag_name () { local tag="$1" assert_valid_ref_name "$tag" - processing 'Check valid tag name...' + CUI_displayMsg processing 'Check valid tag name...' $(echo "$tag" | grep -qP '^'$TWGIT_PREFIX_TAG'[0-9]+\.[0-9]+\.[0-9]+$') || \ die "Unauthorized tag name: '$tag'! Must use major.minor.revision format, e.g. 1.2.3." - processing "Check whether tag '$tag' already exists..." + CUI_displayMsg processing "Check whether tag '$tag' already exists..." has "$tag" $(get_all_tags) && die "Tag '$tag' already exists! Try: twgit tag list" } @@ -589,9 +589,9 @@ function assert_valid_tag_name () { # function assert_working_tree_is_not_on_delete_branch () { local branch="$1" - processing "Check current branch..." + CUI_displayMsg processing "Check current branch..." if [ "$(get_current_branch)" = "$branch" ]; then - processing "Cannot delete the branch '$branch' which you are currently on! So:" + CUI_displayMsg processing "Cannot delete the branch '$branch' which you are currently on! So:" exec_git_command "git checkout $TWGIT_STABLE" "Could not checkout '$TWGIT_STABLE'!" fi } @@ -600,7 +600,7 @@ function assert_working_tree_is_not_on_delete_branch () { # S'assure qu'au moins un tag existe. # function assert_tag_exists () { - processing 'Get last tag...' + CUI_displayMsg processing 'Get last tag...' local last_tag="$(get_last_tag)" [ -z "$last_tag" ] && die 'No tag exists!' || echo "Last tag: $last_tag" } @@ -614,11 +614,11 @@ function assert_recent_git_version () { local needed=$(echo "$1" | awk -F. '{ printf("%d%02d%02d%02d\n", $1,$2,$3,$4); }') local current=$(git --version | sed 's/[^0-9.]//g' | awk -F. '{ printf("%d%02d%02d%02d\n", $1,$2,$3,$4); }') if [ $current -lt $needed ]; then - error "Please update git! Current: $(git --version | sed 's/[^0-9.]//g'). Need $1 or newer." - help 'Try:' - help_detail 'sudo apt-add-repository ppa:git-core/ppa' - help_detail 'sudo apt-get update' - help_detail 'sudo apt-get install git' + CUI_displayMsg error "Please update git! Current: $(git --version | sed 's/[^0-9.]//g'). Need $1 or newer." + CUI_displayMsg help 'Try:' + CUI_displayMsg help_detail 'sudo apt-add-repository ppa:git-core/ppa' + CUI_displayMsg help_detail 'sudo apt-get update' + CUI_displayMsg help_detail 'sudo apt-get install git' echo exit fi @@ -656,7 +656,7 @@ function process_fetch () { # function process_first_commit () { local commit_msg=$(printf "$TWGIT_FIRST_COMMIT_MSG" "$1" "$2" "$3") - processing "${TWGIT_GIT_COMMAND_PROMPT}git commit --allow-empty -m \"$commit_msg\"" + CUI_displayMsg processing "${TWGIT_GIT_COMMAND_PROMPT}git commit --allow-empty -m \"$commit_msg\"" git commit --allow-empty -m "$commit_msg" || die 'Could not make initial commit!' } @@ -681,7 +681,7 @@ function process_push_branch () { function exec_git_command () { local cmd="$1" local error_msg="$2" - processing "$TWGIT_GIT_COMMAND_PROMPT$cmd" + CUI_displayMsg processing "$TWGIT_GIT_COMMAND_PROMPT$cmd" $cmd || die "$error_msg" } @@ -695,7 +695,7 @@ function remove_local_branch () { if has $branch $(get_local_branches); then exec_git_command "git branch -D $branch" "Remove local branch '$branch' failed!" else - processing "Local branch '$branch' not found." + CUI_displayMsg processing "Local branch '$branch' not found." fi } @@ -709,7 +709,7 @@ function remove_remote_branch () { if has "$TWGIT_ORIGIN/$branch" $(get_remote_branches); then exec_git_command "git push $TWGIT_ORIGIN :$branch" "Delete remote branch '$TWGIT_ORIGIN/$branch' failed!" if [ $? -ne 0 ]; then - processing "Remove remote branch '$TWGIT_ORIGIN/$branch' failed! Maybe already deleted... so:" + CUI_displayMsg processing "Remove remote branch '$TWGIT_ORIGIN/$branch' failed! Maybe already deleted... so:" exec_git_command "git remote prune $TWGIT_ORIGIN" "Prune failed!" fi else @@ -746,7 +746,7 @@ function create_and_push_tag () { local commit_msg="$2" # Create tag: - processing "${TWGIT_GIT_COMMAND_PROMPT}git tag -a $tag_fullname -m \"${TWGIT_PREFIX_COMMIT_MSG}$commit_msg\"" + CUI_displayMsg processing "${TWGIT_GIT_COMMAND_PROMPT}git tag -a $tag_fullname -m \"${TWGIT_PREFIX_COMMIT_MSG}$commit_msg\"" git tag -a $tag_fullname -m "${TWGIT_PREFIX_COMMIT_MSG}$commit_msg" || die "Could not create tag '$tag_fullname'!" # Push tags: @@ -759,6 +759,12 @@ function create_and_push_tag () { # Autres fonctions... #-------------------------------------------------------------------- +function die () { + CUI_displayMsg error "$*" >&2 + echo + exit 1 +} + ## # Echappe les caractères '.+$*' d'une chaîne. # @@ -856,7 +862,7 @@ function display_branches () { ) if [ -z "$branches" ]; then - info 'No such branch exists.'; + CUI_displayMsg info 'No such branch exists.'; else local prefix="$TWGIT_ORIGIN/$TWGIT_PREFIX_FEATURE" local add_empty_line=0 @@ -864,7 +870,7 @@ function display_branches () { if ! isset_option 'c'; then [ "$add_empty_line" = "0" ] && add_empty_line=1 || echo fi - echo -n $(info "${titles[$type]}$branch ") + echo -n $(CUI_displayMsg info "${titles[$type]}$branch ") [ "$type" = "feature" ] && displayFeatureSubject "${branch:${#prefix}}" || echo @@ -899,7 +905,7 @@ function alert_old_branch () { [ "$nb_tags_no_merged" -eq "$TWGIT_MAX_RETRIEVE_TAGS_NOT_MERGED" ] && msg="${msg} at least" msg="${msg} $(displayInterval "$tags_not_merged")." [ "$2" = 'with-help' ] && msg="${msg} If need be: git merge --no-ff $(get_last_tag), then: git push $TWGIT_ORIGIN $branch" - warn "$msg" + CUI_displayMsg warning "$msg" fi } @@ -911,13 +917,13 @@ function alert_dissident_branches () { if ! isset_option 'x'; then local dissident_branches="$(get_dissident_remote_branches)" if [ ! -z "$dissident_branches" ]; then - warn "Following branches are out of process: $(displayQuotedEnum $dissident_branches)!" + CUI_displayMsg warning "Following branches are out of process: $(displayQuotedEnum $dissident_branches)!" fi fi local local_ambiguous_branches="$((get_local_branches; git tag) | sort | uniq -d)" if [ ! -z "$local_ambiguous_branches" ]; then - warn "Following local branches are ambiguous: $(displayQuotedEnum $local_ambiguous_branches)!" + CUI_displayMsg warning "Following local branches are ambiguous: $(displayQuotedEnum $local_ambiguous_branches)!" fi if [ ! -z "$dissident_branches" ] || [ ! -z "$local_ambiguous_branches" ]; then @@ -963,7 +969,7 @@ function displayQuotedEnum () { # function displayFeatureSubject () { local subject="$(getFeatureSubject "$1")" - [ ! -z "$subject" ] && displayMsg feature_subject "$subject" || echo + [ ! -z "$subject" ] && CUI_displayMsg feature_subject "$subject" || echo } ## @@ -977,15 +983,15 @@ function inform_about_branch_status () { compare_branches "$branch" "$TWGIT_ORIGIN/$branch" local status=$? if [ $status -eq 0 ]; then - help "Local branch '$branch' up-to-date with remote '$TWGIT_ORIGIN/$branch'." + CUI_displayMsg help "Local branch '$branch' up-to-date with remote '$TWGIT_ORIGIN/$branch'." elif [ $status -eq 1 ]; then - help "If need be: git merge $TWGIT_ORIGIN/$branch" + CUI_displayMsg help "If need be: git merge $TWGIT_ORIGIN/$branch" elif [ $status -eq 2 ]; then - help "If need be: git push $TWGIT_ORIGIN $branch" + CUI_displayMsg help "If need be: git push $TWGIT_ORIGIN $branch" else - warn "Branches '$branch' and '$TWGIT_ORIGIN/$branch' have diverged!" - help "If need be: git merge $TWGIT_ORIGIN/$branch" - help "Then: git push $TWGIT_ORIGIN $branch" + CUI_displayMsg warning "Branches '$branch' and '$TWGIT_ORIGIN/$branch' have diverged!" + CUI_displayMsg help "If need be: git merge $TWGIT_ORIGIN/$branch" + CUI_displayMsg help "Then: git push $TWGIT_ORIGIN $branch" fi } @@ -1012,7 +1018,7 @@ function clean_branches () { local locales="$(get_local_branches)" for branch in $locales; do if ! has $branch $tracked; then - echo -n $(question "Local branch '$branch' is not tracked. Remove? [Y/N] ") + echo -n $(CUI_displayMsg question "Local branch '$branch' is not tracked. Remove? [Y/N] ") read answer if [ "$answer" = "Y" ] || [ "$answer" = "y" ]; then exec_git_command "git branch -D $branch" "Remove local branch '$branch' failed!" @@ -1040,7 +1046,7 @@ function init () { local remote_url="$2" local tag_fullname="$TWGIT_PREFIX_TAG$tag" - processing "Check need for git init..." + CUI_displayMsg processing "Check need for git init..." if [ ! -z "$(git rev-parse --git-dir 2>&1 1>/dev/null)" ]; then exec_git_command 'git init' 'Initialization of git repository failed!' else @@ -1049,21 +1055,21 @@ function init () { assert_valid_tag_name $tag_fullname - processing "Check presence of remote '$TWGIT_ORIGIN' repository..." + CUI_displayMsg processing "Check presence of remote '$TWGIT_ORIGIN' repository..." if [ "$(git remote | grep -R "^$TWGIT_ORIGIN$" | wc -l)" -ne 1 ]; then [ -z "$remote_url" ] && die "Remote '$TWGIT_ORIGIN' repository url required!" exec_git_command "git remote add origin $remote_url" 'Add remote repository failed!' fi process_fetch - processing "Check presence of '$TWGIT_STABLE' branch..." + CUI_displayMsg processing "Check presence of '$TWGIT_STABLE' branch..." if has $TWGIT_STABLE $(get_local_branches); then - processing "Local '$TWGIT_STABLE' detected." + CUI_displayMsg processing "Local '$TWGIT_STABLE' detected." if ! has $TWGIT_ORIGIN/$TWGIT_STABLE $(get_remote_branches); then exec_git_command "git push --set-upstream $TWGIT_ORIGIN $TWGIT_STABLE" 'Git push failed!' fi elif has $TWGIT_ORIGIN/$TWGIT_STABLE $(get_remote_branches); then - processing "Remote '$TWGIT_ORIGIN/$TWGIT_STABLE' detected." + CUI_displayMsg processing "Remote '$TWGIT_ORIGIN/$TWGIT_STABLE' detected." exec_git_command "git checkout --track -b $TWGIT_STABLE $TWGIT_ORIGIN/$TWGIT_STABLE" \ "Could not check out '$TWGIT_ORIGIN/$TWGIT_STABLE'!" else @@ -1095,7 +1101,7 @@ function display_rank_contributors () { local max="$2" [ -z "$max" ] && max=$TWGIT_DEFAULT_NB_COMMITTERS - info "First $max committers into '$TWGIT_ORIGIN/$branch_fullname' remote branch:" + CUI_displayMsg info "First $max committers into '$TWGIT_ORIGIN/$branch_fullname' remote branch:" local contributors="$(get_contributors "$branch_fullname" $max)" [ -z "$contributors" ] && echo 'nobody' || echo $contributors | tr ' ' '\n' echo @@ -1119,9 +1125,9 @@ function displayChangelogSection () { local line while read line; do if [[ "$line" =~ ^## ]]; then - help "${line:3}" + CUI_displayMsg help "${line:3}" elif [[ "$line" =~ ^[^-*\`].*:$ ]]; then - info "$line" + CUI_displayMsg info "$line" else echo " $line" fi; @@ -1149,7 +1155,7 @@ function autoupdate () { if [ "$elapsed_time" -gt "$interval" ] || [ ! -z "$is_forced" ]; then # Update Git : - processing "Fetch twgit repository for auto-update check..." + CUI_displayMsg processing "Fetch twgit repository for auto-update check..." git fetch # Retrieve both current and last tag: @@ -1174,44 +1180,44 @@ function autoupdate () { else question="You are ahead of last tag $last_tag. Would you like to return to it? [Y/N] " fi - echo -n $(question "$question") + echo -n $(CUI_displayMsg question "$question") # Read answer: read answer if [ "$answer" = "Y" ] || [ "$answer" = "y" ]; then - processing 'Update in progress...' + CUI_displayMsg processing 'Update in progress...' exec_git_command 'git reset --hard' 'Hard reset failed!' exec_git_command "git checkout tags/$last_tag" "Could not check out tag '$last_tag'!" > "$TWGIT_FEATURES_SUBJECT_PATH" # Bash autcompletion updated? if ! git diff --quiet "$current_tag" "$last_tag" -- install/bash_completion.sh; then - warn "Bash autocompletion updated. Please restart your Bash session or try: source ~/.bashrc"; + CUI_displayMsg warning "Bash autocompletion updated. Please restart your Bash session or try: source ~/.bashrc"; fi # Config file updated? if ! git diff --quiet "$current_tag" "$last_tag" -- $TWGIT_CONF_DIR/twgit-dist.sh; then - warn "Config file updated! \ + CUI_displayMsg warning "Config file updated! \ Please consider the following diff between old and new version of $TWGIT_CONF_DIR/twgit-dist.sh, \ then consequently update $TWGIT_CONF_DIR/twgit.sh"; git diff "$current_tag" "$last_tag" -- $TWGIT_CONF_DIR/twgit-dist.sh if [ "$(git config --get color.diff)" != 'always' ]; then - help "Try this to get colored diff in this command: git config --global color.diff always" + CUI_displayMsg help "Try this to get colored diff in this command: git config --global color.diff always" fi fi fi else - processing 'Twgit already up-to-date.' + CUI_displayMsg processing 'Twgit already up-to-date.' fi # Prochain update : - processing "Next auto-update check in $TWGIT_UPDATE_NB_DAYS days." + CUI_displayMsg processing "Next auto-update check in $TWGIT_UPDATE_NB_DAYS days." touch "$TWGIT_UPDATE_PATH" # MAJ du système d'update d'autocomplétion : if [ ! -h "/etc/bash_completion.d/twgit" ]; then - warn "New autocompletion update system request you execute just once this line (to adapt):" - help_detail "sudo rm /etc/bash_completion.d/twgit && sudo ln -s ~/twgit/install/.bash_completion /etc/bash_completion.d/twgit && source ~/.bashrc" + CUI_displayMsg warning "New autocompletion update system request you execute just once this line (to adapt):" + CUI_displayMsg help_detail "sudo rm /etc/bash_completion.d/twgit && sudo ln -s ~/twgit/install/.bash_completion /etc/bash_completion.d/twgit && source ~/.bashrc" fi # Invite : @@ -1221,7 +1227,7 @@ then consequently update $TWGIT_CONF_DIR/twgit.sh"; fi fi elif [ ! -z "$is_forced" ]; then - warn 'Git repositoy not found!' + CUI_displayMsg warning 'Git repositoy not found!' fi cd - 1>/dev/null } diff --git a/inc/options_handler.inc.sh b/inc/options_handler.inc.sh index d9bafe0..910154a 100644 --- a/inc/options_handler.inc.sh +++ b/inc/options_handler.inc.sh @@ -101,7 +101,7 @@ function require_parameter () { elif [ "$name" = '-' ]; then RETVAL='' else - error "Missing argument <$name>!" + CUI_displayMsg error "Missing argument <$name>!" usage exit 1 fi diff --git a/inc/twgit_feature.inc.sh b/inc/twgit_feature.inc.sh index 2dc36c7..00506d2 100644 --- a/inc/twgit_feature.inc.sh +++ b/inc/twgit_feature.inc.sh @@ -30,40 +30,40 @@ # @testedby TwgitHelpTest # function usage () { - echo; help 'Usage:' - help_detail 'twgit feature ' - echo; help 'Available actions are:' - help_detail 'committers [] [-F]' - help_detail ' List first committers into the specified remote feature.' - help_detail " Default value of : $TWGIT_DEFAULT_NB_COMMITTERS. Add -F to do not make fetch."; echo - help_detail 'list [-c|-F|-x]' - help_detail ' List remote features. Add -F to do not make fetch, -c to compact display' - help_detail ' and -x (eXtremely compact) to CSV display.'; echo - help_detail 'merge-into-release []' - help_detail ' Try to merge specified feature into current release.' - help_detail ' If no is specified, then ask to use current feature.'; echo - help_detail 'migrate ' - help_detail ' Migrate old branch to new process.' - help_detail ' For example: "twgit feature migrate rm7880 7880"'; echo - help_detail 'remove ' - help_detail ' Remove both local and remote specified feature branch.'; echo - help_detail 'show-modified-files []' - help_detail ' List created/modified/deleted files of the specified feature branch since' - help_detail ' its creation (from commits). If no is specified, then use' - help_detail ' current feature.'; echo - help_detail 'start [-d]' - help_detail ' Create both a new local and remote feature, or fetch the remote feature,' - help_detail ' or checkout the local feature. Add -d to delete beforehand local feature' - help_detail ' if exists.'; echo - help_detail 'status []' - help_detail ' Display information about specified feature: long name if a connector is' - help_detail ' setted, last commit, status between local and remote feature and execute' - help_detail ' a git status if specified feature is the current branch.' - help_detail ' If no is specified, then use current feature.'; echo - help_detail "Prefix '$TWGIT_PREFIX_FEATURE' will be added to and " - help_detail "parameters."; echo - help_detail '[help]' - help_detail ' Display this help.'; echo + echo; CUI_displayMsg help 'Usage:' + CUI_displayMsg help_detail 'twgit feature ' + echo; CUI_displayMsg help 'Available actions are:' + CUI_displayMsg help_detail 'committers [] [-F]' + CUI_displayMsg help_detail ' List first committers into the specified remote feature.' + CUI_displayMsg help_detail " Default value of : $TWGIT_DEFAULT_NB_COMMITTERS. Add -F to do not make fetch."; echo + CUI_displayMsg help_detail 'list [-c|-F|-x]' + CUI_displayMsg help_detail ' List remote features. Add -F to do not make fetch, -c to compact display' + CUI_displayMsg help_detail ' and -x (eXtremely compact) to CSV display.'; echo + CUI_displayMsg help_detail 'merge-into-release []' + CUI_displayMsg help_detail ' Try to merge specified feature into current release.' + CUI_displayMsg help_detail ' If no is specified, then ask to use current feature.'; echo + CUI_displayMsg help_detail 'migrate ' + CUI_displayMsg help_detail ' Migrate old branch to new process.' + CUI_displayMsg help_detail ' For example: "twgit feature migrate rm7880 7880"'; echo + CUI_displayMsg help_detail 'remove ' + CUI_displayMsg help_detail ' Remove both local and remote specified feature branch.'; echo + CUI_displayMsg help_detail 'show-modified-files []' + CUI_displayMsg help_detail ' List created/modified/deleted files of the specified feature branch since' + CUI_displayMsg help_detail ' its creation (from commits). If no is specified, then use' + CUI_displayMsg help_detail ' current feature.'; echo + CUI_displayMsg help_detail 'start [-d]' + CUI_displayMsg help_detail ' Create both a new local and remote feature, or fetch the remote feature,' + CUI_displayMsg help_detail ' or checkout the local feature. Add -d to delete beforehand local feature' + CUI_displayMsg help_detail ' if exists.'; echo + CUI_displayMsg help_detail 'status []' + CUI_displayMsg help_detail ' Display information about specified feature: long name if a connector is' + CUI_displayMsg help_detail ' setted, last commit, status between local and remote feature and execute' + CUI_displayMsg help_detail ' a git status if specified feature is the current branch.' + CUI_displayMsg help_detail ' If no is specified, then use current feature.'; echo + CUI_displayMsg help_detail "Prefix '$TWGIT_PREFIX_FEATURE' will be added to and " + CUI_displayMsg help_detail "parameters."; echo + CUI_displayMsg help_detail '[help]' + CUI_displayMsg help_detail ' Display this help.'; echo } ## @@ -121,16 +121,16 @@ function cmd_list () { if isset_option 'x'; then display_csv_branches "$features" "merged into stable" elif [ ! -z "$features" ]; then - help "Remote features merged into '$TWGIT_STABLE' via releases:" - warn 'They would not exists!' + CUI_displayMsg help "Remote features merged into '$TWGIT_STABLE' via releases:" + CUI_displayMsg warning 'They would not exists!' display_branches 'feature' "$features"; echo fi local release="$(get_current_release_in_progress)" if [ -z "$release" ]; then if ! isset_option 'x'; then - help "Remote delivered features merged into release in progress:" - info 'No such branch exists.'; echo + CUI_displayMsg help "Remote delivered features merged into release in progress:" + CUI_displayMsg info 'No such branch exists.'; echo fi else get_merged_features $release @@ -143,9 +143,9 @@ function cmd_list () { display_csv_branches "$features_merged" "merged into release" display_csv_branches "$features_in_progress" "merged into release, then in progress" else - help "Remote delivered features merged into release in progress '$TWGIT_ORIGIN/$release':" + CUI_displayMsg help "Remote delivered features merged into release in progress '$TWGIT_ORIGIN/$release':" display_branches 'feature' "$features_merged"; echo - help "Remote features in progress, previously merged into '$TWGIT_ORIGIN/$release':" + CUI_displayMsg help "Remote features in progress, previously merged into '$TWGIT_ORIGIN/$release':" display_branches 'feature' "$features_in_progress"; echo fi fi @@ -156,7 +156,7 @@ function cmd_list () { if isset_option 'x'; then display_csv_branches "$features" "free" else - help "Remote free features:" + CUI_displayMsg help "Remote free features:" display_branches 'feature' "$features"; echo alert_dissident_branches fi @@ -180,23 +180,23 @@ function cmd_migrate () { assert_valid_ref_name $feature assert_clean_working_tree - processing 'Check local features...' + CUI_displayMsg processing 'Check local features...' if has $feature_fullname $(get_local_branches); then die "Local branch '$feature_fullname' already exists!" fi process_fetch - processing 'Check remote features...' + CUI_displayMsg processing 'Check remote features...' if ! has "$TWGIT_ORIGIN/$oldfeature_fullname" $(get_remote_branches); then die "Remote branch '$TWGIT_ORIGIN/$oldfeature_fullname' does not exist!" elif has "$TWGIT_ORIGIN/$feature_fullname" $(get_remote_branches); then die "Remote feature '$feature_fullname' already exists!" fi - echo -n $(question "Are you sure to migrate '$oldfeature_fullname' to '$feature_fullname'? Branch '$oldfeature_fullname' will be deleted. [Y/N] "); read answer + echo -n $(CUI_displayMsg question "Are you sure to migrate '$oldfeature_fullname' to '$feature_fullname'? Branch '$oldfeature_fullname' will be deleted. [Y/N] "); read answer [ "$answer" != "Y" ] && [ "$answer" != "y" ] && die 'Branch migration aborted!' - processing "Migrate '$oldfeature_fullname' to '$feature_fullname'..." + CUI_displayMsg processing "Migrate '$oldfeature_fullname' to '$feature_fullname'..." exec_git_command "git checkout --track -b $feature_fullname $TWGIT_ORIGIN/$oldfeature_fullname" "Could not check out feature '$TWGIT_ORIGIN/$oldfeature_fullname'!" remove_local_branch "$oldfeature_fullname" remove_remote_branch "$oldfeature_fullname" @@ -229,9 +229,9 @@ function cmd_start () { assert_new_local_branch $feature_fullname fi - processing 'Check remote features...' + CUI_displayMsg processing 'Check remote features...' if has "$TWGIT_ORIGIN/$feature_fullname" $(get_remote_branches); then - processing "Remote feature '$feature_fullname' detected." + CUI_displayMsg processing "Remote feature '$feature_fullname' detected." exec_git_command "git checkout --track -b $feature_fullname $TWGIT_ORIGIN/$feature_fullname" "Could not check out feature '$TWGIT_ORIGIN/$feature_fullname'!" else assert_tag_exists @@ -288,7 +288,7 @@ function cmd_status () { exec_git_command "git status" "Error while git status!" if [ "$(git config --get color.status)" != 'always' ]; then echo - help "Try this to get colored status in this command: git config --global color.status always" + CUI_displayMsg help "Try this to get colored status in this command: git config --global color.status always" fi fi echo @@ -311,7 +311,7 @@ function cmd_merge-into-release () { # Tests préliminaires : assert_clean_working_tree process_fetch - processing 'Check remote release...' + CUI_displayMsg processing 'Check remote release...' [ -z "$release" ] && die 'No release in progress!' # Si feature non spécifiée, récupérer la courante : @@ -322,7 +322,7 @@ function cmd_merge-into-release () { if ! has "$TWGIT_ORIGIN/$current_branch" $all_features; then die "You must be in a feature if you didn't specify one!" else - echo -n $(question "Are you sure to merge '$TWGIT_ORIGIN/$current_branch' into '$TWGIT_ORIGIN/$release_fullname'? [Y/N] "); read answer + echo -n $(CUI_displayMsg question "Are you sure to merge '$TWGIT_ORIGIN/$current_branch' into '$TWGIT_ORIGIN/$release_fullname'? [Y/N] "); read answer [ "$answer" != "Y" ] && [ "$answer" != "y" ] && die 'Merge into current release aborted!' fi feature_fullname="$current_branch" @@ -332,9 +332,9 @@ function cmd_merge-into-release () { fi # Autres tests : - processing 'Check remote feature...' + CUI_displayMsg processing 'Check remote feature...' if ! has "$TWGIT_ORIGIN/$feature_fullname" $(get_remote_branches); then - die "Remote feature '$TWGIT_ORIGIN/$feature_fullname' not found!" + die "Remote feature '$TWGIT_ORIGIN/$feature_fullname' not found!" fi # Merge : @@ -349,19 +349,19 @@ git push $TWGIT_ORIGIN $release_fullname" local prefix for cmd in $cmds; do if [ "$error" -ne 0 ]; then - help_detail "$cmd" + CUI_displayMsg help_detail "$cmd" else [ "${cmd:0:${#TWGIT_EXEC}+1}" = "$TWGIT_EXEC " ] && msg="shell# twgit ${cmd:${#TWGIT_EXEC}+1}" || msg="${TWGIT_GIT_COMMAND_PROMPT}$cmd" - processing "$msg" + CUI_displayMsg processing "$msg" if ! eval $cmd; then error=1 - error "Merge '$feature_fullname' into '$release_fullname' aborted!" - help 'Commands not executed:' - help_detail "$cmd" + CUI_displayMsg error "Merge '$feature_fullname' into '$release_fullname' aborted!" + CUI_displayMsg help 'Commands not executed:' + CUI_displayMsg help_detail "$cmd" if [ "${cmd:0:10}" = "git merge " ]; then - help_detail " - resolve conflicts" - help_detail " - git add..." - help_detail " - git commit..." + CUI_displayMsg help_detail " - resolve conflicts" + CUI_displayMsg help_detail " - git add..." + CUI_displayMsg help_detail " - git commit..." fi fi fi @@ -396,7 +396,7 @@ function cmd_show-modified-files () { if [ ! -z "$feature" ]; then feature_fullname="$TWGIT_PREFIX_FEATURE$feature" - processing 'Check remote feature...' + CUI_displayMsg processing 'Check remote feature...' if ! has "$TWGIT_ORIGIN/$feature_fullname" $(get_remote_branches); then die "Remote feature '$TWGIT_ORIGIN/$feature_fullname' not found!" fi @@ -416,14 +416,14 @@ function cmd_show-modified-files () { local modified_files="$(git show --pretty="format:" --name-only $start_sha1..HEAD | sort | uniq | sed '/^$/d')" local count="$(echo "$modified_files" | sed '/^$/d' | wc -l)" - info "SHA1 of creation of '$feature_fullname':" + CUI_displayMsg info "SHA1 of creation of '$feature_fullname':" echo $start_sha1; echo - info "Number of created/modified/deleted files of '$feature_fullname' since its creation:" + CUI_displayMsg info "Number of created/modified/deleted files of '$feature_fullname' since its creation:" echo "$count"; echo if [ "$count" != '0' ]; then - info "List of these files:" + CUI_displayMsg info "List of these files:" echo "$modified_files"; echo fi } diff --git a/inc/twgit_hotfix.inc.sh b/inc/twgit_hotfix.inc.sh index 7b6c313..5229ba8 100644 --- a/inc/twgit_hotfix.inc.sh +++ b/inc/twgit_hotfix.inc.sh @@ -30,26 +30,26 @@ # @testedby TwgitHelpTest # function usage () { - echo; help 'Usage:' - help_detail 'twgit hotfix ' - echo; help 'Available actions are:' - help_detail 'finish [-I]' - help_detail " Merge current hotfix branch into '$TWGIT_STABLE', create a new tag and push." - help_detail ' Add -I to run in non-interactive mode (always say yes).'; echo - help_detail 'list [-F]' - help_detail ' List current hotfix. Add -F to do not make fetch.'; echo - help_detail 'remove ' - help_detail ' Remove both local and remote specified hotfix branch.' - help_detail ' Despite that, create the same tag as finish action to clearly distinguish' - help_detail ' the next hotfix from this one.' - help_detail " Prefix '$TWGIT_PREFIX_HOTFIX' will be added to the specified ."; echo - help_detail 'start' - help_detail ' Create both a new local and remote hotfix, or fetch the remote hotfix,' - help_detail ' or checkout the local hotfix.' - help_detail ' Hotfix name will be generated by incrementing revision of the last tag:' - help_detail " v1.2.3 > ${TWGIT_PREFIX_HOTFIX}1.2.4"; echo - help_detail '[help]' - help_detail ' Display this help.'; echo + echo; CUI_displayMsg help 'Usage:' + CUI_displayMsg help_detail 'twgit hotfix ' + echo; CUI_displayMsg help 'Available actions are:' + CUI_displayMsg help_detail 'finish [-I]' + CUI_displayMsg help_detail " Merge current hotfix branch into '$TWGIT_STABLE', create a new tag and push." + CUI_displayMsg help_detail ' Add -I to run in non-interactive mode (always say yes).'; echo + CUI_displayMsg help_detail 'list [-F]' + CUI_displayMsg help_detail ' List current hotfix. Add -F to do not make fetch.'; echo + CUI_displayMsg help_detail 'remove ' + CUI_displayMsg help_detail ' Remove both local and remote specified hotfix branch.' + CUI_displayMsg help_detail ' Despite that, create the same tag as finish action to clearly distinguish' + CUI_displayMsg help_detail ' the next hotfix from this one.' + CUI_displayMsg help_detail " Prefix '$TWGIT_PREFIX_HOTFIX' will be added to the specified ."; echo + CUI_displayMsg help_detail 'start' + CUI_displayMsg help_detail ' Create both a new local and remote hotfix, or fetch the remote hotfix,' + CUI_displayMsg help_detail ' or checkout the local hotfix.' + CUI_displayMsg help_detail ' Hotfix name will be generated by incrementing revision of the last tag:' + CUI_displayMsg help_detail " v1.2.3 > ${TWGIT_PREFIX_HOTFIX}1.2.4"; echo + CUI_displayMsg help_detail '[help]' + CUI_displayMsg help_detail ' Display this help.'; echo } ## @@ -70,7 +70,7 @@ function cmd_list () { process_fetch 'F' local hotfixes=$(get_last_hotfixes 1) - help "Remote current hotfix:" + CUI_displayMsg help "Remote current hotfix:" display_branches 'hotfix' "$hotfixes"; echo alert_dissident_branches @@ -84,7 +84,7 @@ function cmd_start () { assert_clean_working_tree process_fetch - processing 'Check remote hotfixes...' + CUI_displayMsg processing 'Check remote hotfixes...' local remote_hotfix="$(get_hotfixes_in_progress)" local hotfix if [ -z "$remote_hotfix" ]; then @@ -98,7 +98,7 @@ function cmd_start () { else local prefix="$TWGIT_ORIGIN/$TWGIT_PREFIX_HOTFIX" hotfix="${remote_hotfix:${#prefix}}" - processing "Remote hotfix '$TWGIT_PREFIX_HOTFIX$hotfix' detected." + CUI_displayMsg processing "Remote hotfix '$TWGIT_PREFIX_HOTFIX$hotfix' detected." assert_valid_ref_name $hotfix local hotfix_fullname="$TWGIT_PREFIX_HOTFIX$hotfix" assert_new_local_branch $hotfix_fullname @@ -148,16 +148,16 @@ function cmd_finish () { assert_clean_working_tree process_fetch - processing 'Check remote hotfix...' + CUI_displayMsg processing 'Check remote hotfix...' local remote_hotfix="$(get_hotfixes_in_progress)" [ -z "$remote_hotfix" ] && die 'No hotfix in progress!' local prefix="$TWGIT_ORIGIN/$TWGIT_PREFIX_HOTFIX" hotfix="${remote_hotfix:${#prefix}}" local hotfix_fullname="$TWGIT_PREFIX_HOTFIX$hotfix" - processing "Remote hotfix '$hotfix_fullname' detected." + CUI_displayMsg processing "Remote hotfix '$hotfix_fullname' detected." - processing "Check local branch '$hotfix_fullname'..." + CUI_displayMsg processing "Check local branch '$hotfix_fullname'..." if has $hotfix_fullname $(get_local_branches); then assert_branches_equal "$hotfix_fullname" "$TWGIT_ORIGIN/$hotfix_fullname" else @@ -179,7 +179,8 @@ function cmd_finish () { remove_remote_branch $hotfix_fullname local current_release="$(get_current_release_in_progress)" - [ ! -z "$current_release" ] && warn "Do not forget to merge '$tag_fullname' tag into '$TWGIT_ORIGIN/$current_release' release before close it! Try on release: git merge --no-ff $tag_fullname" + [ ! -z "$current_release" ] \ + && CUI_displayMsg warning "Do not forget to merge '$tag_fullname' tag into '$TWGIT_ORIGIN/$current_release' release before close it! Try on release: git merge --no-ff $tag_fullname" echo } diff --git a/inc/twgit_release.inc.sh b/inc/twgit_release.inc.sh index 7d4fb30..95b6da8 100644 --- a/inc/twgit_release.inc.sh +++ b/inc/twgit_release.inc.sh @@ -30,36 +30,36 @@ # @testedby TwgitHelpTest # function usage () { - echo; help 'Usage:' - help_detail 'twgit release ' - echo; help 'Available actions are:' - help_detail 'committers [] [-F]' - help_detail ' List first committers into the current release.' - help_detail " Default value of : $TWGIT_DEFAULT_NB_COMMITTERS. Add -F to do not make fetch."; echo - help_detail 'list [-F]' - help_detail ' List remote releases. Add -F to do not make fetch.'; echo - help_detail 'finish [] [-I]' - help_detail " Merge current release branch into '$TWGIT_STABLE', create a new tag and push." - help_detail ' If no is specified then current release name will be used.' - help_detail ' Add -I to run in non-interactive mode (always say yes).'; echo - help_detail 'remove ' - help_detail ' Remove both local and remote specified release branch.' - help_detail ' Despite that, create the same tag as finish action to clearly distinguish' - help_detail ' the next release from this one.'; echo - help_detail 'reset [-I|-M|-m]' - help_detail ' Call twgit remove , then twgit start [-I|-M|-m].' - help_detail ' Handle options of twgit start.'; echo - help_detail 'start [] [-I|-M|-m]' - help_detail ' Create both a new local and remote release, or fetch the remote release,' - help_detail ' or checkout the local release. Add -I to run in non-interactive mode' - help_detail ' (always say yes). If no is specified, a name will be' - help_detail ' generated by incrementing the last tag (e.g. v1.2.3):' - help_detail " -M for a new major version (> ${TWGIT_PREFIX_RELEASE}2.0.0)" - help_detail " -m for a new minor version (default, > ${TWGIT_PREFIX_RELEASE}1.3.0)"; echo - help_detail "Prefix '$TWGIT_PREFIX_RELEASE' will be added to parameters." - help_detail "Prefix '$TWGIT_PREFIX_TAG' will be added to parameters."; echo - help_detail '[help]' - help_detail ' Display this help.'; echo + echo; CUI_displayMsg help 'Usage:' + CUI_displayMsg help_detail 'twgit release ' + echo; CUI_displayMsg help 'Available actions are:' + CUI_displayMsg help_detail 'committers [] [-F]' + CUI_displayMsg help_detail ' List first committers into the current release.' + CUI_displayMsg help_detail " Default value of : $TWGIT_DEFAULT_NB_COMMITTERS. Add -F to do not make fetch."; echo + CUI_displayMsg help_detail 'list [-F]' + CUI_displayMsg help_detail ' List remote releases. Add -F to do not make fetch.'; echo + CUI_displayMsg help_detail 'finish [] [-I]' + CUI_displayMsg help_detail " Merge current release branch into '$TWGIT_STABLE', create a new tag and push." + CUI_displayMsg help_detail ' If no is specified then current release name will be used.' + CUI_displayMsg help_detail ' Add -I to run in non-interactive mode (always say yes).'; echo + CUI_displayMsg help_detail 'remove ' + CUI_displayMsg help_detail ' Remove both local and remote specified release branch.' + CUI_displayMsg help_detail ' Despite that, create the same tag as finish action to clearly distinguish' + CUI_displayMsg help_detail ' the next release from this one.'; echo + CUI_displayMsg help_detail 'reset [-I|-M|-m]' + CUI_displayMsg help_detail ' Call twgit remove , then twgit start [-I|-M|-m].' + CUI_displayMsg help_detail ' Handle options of twgit start.'; echo + CUI_displayMsg help_detail 'start [] [-I|-M|-m]' + CUI_displayMsg help_detail ' Create both a new local and remote release, or fetch the remote release,' + CUI_displayMsg help_detail ' or checkout the local release. Add -I to run in non-interactive mode' + CUI_displayMsg help_detail ' (always say yes). If no is specified, a name will be' + CUI_displayMsg help_detail ' generated by incrementing the last tag (e.g. v1.2.3):' + CUI_displayMsg help_detail " -M for a new major version (> ${TWGIT_PREFIX_RELEASE}2.0.0)" + CUI_displayMsg help_detail " -m for a new minor version (default, > ${TWGIT_PREFIX_RELEASE}1.3.0)"; echo + CUI_displayMsg help_detail "Prefix '$TWGIT_PREFIX_RELEASE' will be added to parameters." + CUI_displayMsg help_detail "Prefix '$TWGIT_PREFIX_TAG' will be added to parameters."; echo + CUI_displayMsg help_detail '[help]' + CUI_displayMsg help_detail ' Display this help.'; echo } ## @@ -99,17 +99,17 @@ function cmd_list () { local releases=$(git branch -r --merged $TWGIT_ORIGIN/$TWGIT_STABLE | grep "$TWGIT_ORIGIN/$TWGIT_PREFIX_RELEASE" | sed 's/^[* ]*//') if [ ! -z "$releases" ]; then - help "Remote releases merged into '$TWGIT_STABLE':" - warn "A release must be deleted after merge into '$TWGIT_STABLE'! Following releases should not exists!" + CUI_displayMsg help "Remote releases merged into '$TWGIT_STABLE':" + CUI_displayMsg warning "A release must be deleted after merge into '$TWGIT_STABLE'! Following releases should not exists!" display_branches 'release' "$releases" echo fi local release="$(get_current_release_in_progress)" - help "Remote release NOT merged into '$TWGIT_STABLE':" + CUI_displayMsg help "Remote release NOT merged into '$TWGIT_STABLE':" if [ ! -z "$release" ]; then display_branches 'release' "$TWGIT_ORIGIN/$release" # | head -n -1 - info 'Features:' + CUI_displayMsg info 'Features:' get_merged_features $release local merged_features="$GET_MERGED_FEATURES_RETURN_VALUE" @@ -117,7 +117,7 @@ function cmd_list () { local prefix="$TWGIT_ORIGIN/$TWGIT_PREFIX_FEATURE" for f in $merged_features; do echo -n " - $f " - echo -n $(displayMsg ok '[merged]')' ' + echo -n $(CUI_displayMsg ok '[merged]')' ' displayFeatureSubject "${f:${#prefix}}" done @@ -126,10 +126,12 @@ function cmd_list () { for f in $merged_in_progress_features; do echo -n " - $f "; - echo -n $(displayMsg warning 'merged, then in progress.')' ' + echo -n $(CUI_displayMsg warning 'merged, then in progress.')' ' displayFeatureSubject "${f:${#prefix}}" done - [ -z "$merged_features" ] && [ -z "$merged_in_progress_features" ] && info ' - No such branch exists.' + if [ -z "$merged_features" ] && [ -z "$merged_in_progress_features" ]; then + CUI_displayMsg info ' - No such branch exists.' + fi else display_branches 'release' '' fi @@ -170,7 +172,7 @@ function cmd_start () { release=$(get_next_version $type) echo "Release: $TWGIT_PREFIX_RELEASE$release" if ! isset_option 'I'; then - echo -n $(question 'Do you want to continue? [Y/N] '); read answer + echo -n $(CUI_displayMsg question 'Do you want to continue? [Y/N] '); read answer [ "$answer" != "Y" ] && [ "$answer" != "y" ] && die 'New release aborted!' fi fi @@ -214,11 +216,11 @@ function cmd_finish () { process_fetch # Récupération de la release en cours : - processing 'Check remote release...' + CUI_displayMsg processing 'Check remote release...' local release_fullname="$(get_current_release_in_progress)" [ -z "$release_fullname" ] && die 'No release in progress!' local release="${release_fullname:${#TWGIT_PREFIX_RELEASE}}" - processing "Remote release '$release_fullname' detected." + CUI_displayMsg processing "Remote release '$release_fullname' detected." # Gestion du tag : [ -z "$tag" ] && tag="$release" @@ -226,24 +228,24 @@ function cmd_finish () { assert_valid_tag_name $tag_fullname # Détection hotfixes en cours : - processing 'Check hotfix in progress...' + CUI_displayMsg processing 'Check hotfix in progress...' local hotfix="$(get_hotfixes_in_progress)" [ ! -z "$hotfix" ] && die "Close a release while hotfix in progress is forbidden! Hotfix '$hotfix' must be treated first." # Détection tags (via hotfixes) réalisés entre temps : - processing 'Check tags not merged...' + CUI_displayMsg processing 'Check tags not merged...' get_tags_not_merged_into_branch "$TWGIT_ORIGIN/$release_fullname" tags_not_merged="$(echo "$GET_TAGS_NOT_MERGED_INTO_BRANCH_RETURN_VALUE" | sed 's/ /, /g')" [ ! -z "$tags_not_merged" ] && die "You must merge following tag(s) into this release before close it: $tags_not_merged" - processing 'Check remote features...' + CUI_displayMsg processing 'Check remote features...' get_features merged_in_progress $release_fullname local features="$GET_FEATURES_RETURN_VALUE" [ ! -z "$features" ] && die "Features exists that are merged into this release but yet in development: $(echo $features | sed 's/ /, /g')!" - processing "Check local branch '$release_fullname'..." + CUI_displayMsg processing "Check local branch '$release_fullname'..." if has $release_fullname $(get_local_branches); then assert_branches_equal "$release_fullname" "$TWGIT_ORIGIN/$release_fullname" else @@ -261,7 +263,7 @@ function cmd_finish () { local prefix="$TWGIT_ORIGIN/$TWGIT_PREFIX_RELEASE" for feature in $features; do - processing "Delete '$feature' feature..." + CUI_displayMsg processing "Delete '$feature' feature..." remove_feature "${feature:${#prefix}}" done diff --git a/inc/twgit_tag.inc.sh b/inc/twgit_tag.inc.sh index 6881972..fda473e 100644 --- a/inc/twgit_tag.inc.sh +++ b/inc/twgit_tag.inc.sh @@ -30,13 +30,13 @@ # @testedby TwgitHelpTest # function usage () { - echo; help 'Usage:' - help_detail 'twgit tag ' - echo; help 'Available actions are:' - help_detail 'list [-F]' - help_detail ' List 5 last tags. Add -F to do not make fetch.'; echo - help_detail '[help]' - help_detail ' Display this help.'; echo + echo; CUI_displayMsg help 'Usage:' + CUI_displayMsg help_detail 'twgit tag ' + echo; CUI_displayMsg help 'Available actions are:' + CUI_displayMsg help_detail 'list [-F]' + CUI_displayMsg help_detail ' List 5 last tags. Add -F to do not make fetch.'; echo + CUI_displayMsg help_detail '[help]' + CUI_displayMsg help_detail ' Display this help.'; echo } ## @@ -58,12 +58,12 @@ function cmd_list () { local max='5' local tags=$(get_all_tags $max) - help "List $max last tags:" + CUI_displayMsg help "List $max last tags:" if [ -z "$tags" ]; then - info 'No tag exists.'; echo + CUI_displayMsg info 'No tag exists.'; echo else for tag in $tags; do - info "Tag: $tag" + CUI_displayMsg info "Tag: $tag" git show tags/$tag --pretty=medium | head -n 4 | tail -n +2 done fi diff --git a/inc/ui.inc.sh b/inc/ui.inc.sh deleted file mode 100644 index cc89ded..0000000 --- a/inc/ui.inc.sh +++ /dev/null @@ -1,111 +0,0 @@ -#!/bin/bash - -## -# User interface. -# -# -# -# Copyright (c) 2011 Twenga SA -# Copyright (c) 2012 Geoffroy Aubry -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed -# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License -# for the specific language governing permissions and limitations under the License. -# -# @copyright 2011 Twenga SA -# @copyright 2012 Geoffroy Aubry -# @license http://www.apache.org/licenses/LICENSE-2.0 -# - - - -# Map des colorations et en-têtes des messages : -declare -A UI -UI=( - [error.header]='\033[1m\033[4;33m/!\\\033[0;37m ' - [error.color]='\033[1;31m' - [error.bold.color]='\033[1;33m' - [info.color]='\033[1;37m' - [feature_subject.color]='\033[1;34m' - [help.header]='\033[1;36m(i) ' - [help.color]='\033[0;36m' - [help.bold.color]='\033[1;36m' - [help_detail.header]=' ' - [help_detail.color]='\033[0;37m' - [help_detail.bold.color]='\033[1;37m' - [normal.color]='\033[0;37m' - [warning.header]='\033[1m\033[4;33m/!\\\033[0;37m ' - [warning.color]='\033[0;33m' - [warning.bold.color]='\033[1;33m' - [question.color]='\033[1;33m' - [question.bold.color]='\033[1;37m' - [processing.color]='\033[1;30m' - [ok.color]='\033[0;32m' -) - -function processing () { - displayMsg processing "$1" -} - -function info () { - displayMsg info "$1" -} - -function help () { - displayMsg help "$1" -} - -function help_detail () { - displayMsg help_detail "$1" -} - -function warn () { - displayMsg warning "$1" -} - -function question () { - displayMsg question "$1" -} - -function error () { - displayMsg error "$1" -} - -function die () { - error "$1" >&2 - echo - exit 1 -} - -## -# Affiche un message dans la couleur du type spécifié ("$type.color"). -# S'il existe un en-tête "$type.header" dans la map UI, alors il viendra préfixer le message spécifié. -# Enfin s'il existe un en-tête "$type.bold.color" dans la map UI, alors le texte encadré de balises et sera -# dans cette couleur. Dans tous les cas ces balises seront supprimées de la sortie. -# -# @param string $1 type de message à afficher : conditionne l'éventuelle en-tête et la couleur -# @param string $2 message à afficher -# -function displayMsg () { - local type=$1 - local msg=$2 - local header - - local is_defined=`echo ${!UI[*]} | grep "\b$type\b" | wc -l` - [ $is_defined = 0 ] && echo "Unknown display type '$type'!" >&2 && exit 1 - local escape_color=$(echo ${UI[$type'.color']} | sed 's/\\/\\\\/g') - local escape_bold_color=$(echo ${UI[$type'.bold.color']} | sed 's/\\/\\\\/g') - - if [ ! -z "${UI[$type'.header']}" ]; then - header="${UI[$type'.header']}" - else - header='' - fi - msg=$(echo "$msg" | sed "s//$escape_bold_color/g" | sed "s##$escape_color#g") - echo -e "$header${UI[$type'.color']}$msg${UI['normal.color']}" -} diff --git a/tests/TwgitCUITest.php b/tests/TwgitCUITest.php new file mode 100644 index 0000000..4361437 --- /dev/null +++ b/tests/TwgitCUITest.php @@ -0,0 +1,193 @@ + + */ +class TwgitCUITest extends TwgitTestCase +{ + + /** + * Sets up the fixture, for example, open a network connection. + * This method is called before a test is executed. + */ + public function setUp () + { + $o = self::_getShellInstance(); + $o->remove(TWGIT_REPOSITORY_ORIGIN_DIR); + $o->remove(TWGIT_REPOSITORY_LOCAL_DIR); + $o->mkdir(TWGIT_REPOSITORY_ORIGIN_DIR, '0777'); + $o->mkdir(TWGIT_REPOSITORY_LOCAL_DIR, '0777'); + } + + /** + * @shcovers inc/coloredUI.inc.sh::CUI_isSet + * @shcovers inc/coloredUI.inc.sh::CUI_displayMsg + */ + public function testDisplayMsg_ThrowExceptionWhenUnknownTypeAndNoDefinedType () + { + $this->setExpectedException('RuntimeException', "Unknown display type 'info'!\nAvailable types: ."); + $sMsg = $this->_localShellCodeCall('CUI_COLORS=(); CUI_displayMsg info', false); + } + + /** + * @shcovers inc/coloredUI.inc.sh::CUI_isSet + * @shcovers inc/coloredUI.inc.sh::CUI_displayMsg + */ + public function testDisplayMsg_ThrowExceptionWhenUnknownTypeAndOneDefinedType () + { + $this->setExpectedException('RuntimeException', "Unknown display type 'info'!\nAvailable types: a."); + $sMsg = $this->_localShellCodeCall('CUI_COLORS=([a]=b); CUI_displayMsg info', false); + } + + /** + * @shcovers inc/coloredUI.inc.sh::CUI_isSet + * @shcovers inc/coloredUI.inc.sh::CUI_displayMsg + */ + public function testDisplayMsg_ThrowExceptionWhenUnknownTypeAndSeveralDefinedTypes () + { + $this->setExpectedException('RuntimeException', "Unknown display type 'info'!\nAvailable types: a, c."); + $sMsg = $this->_localShellCodeCall('CUI_COLORS=([a]=b [c]=d); CUI_displayMsg info', false); + } + + /** + * @shcovers inc/coloredUI.inc.sh::CUI_isSet + * @shcovers inc/coloredUI.inc.sh::CUI_displayMsg + */ + public function testDisplayMsg_ThrowExceptionWhenUnknownTypeWithMsg () + { + $this->setExpectedException('RuntimeException', "Unknown display type 'info'!\nAvailable types: ."); + $sMsg = $this->_localShellCodeCall('CUI_COLORS=(); CUI_displayMsg info blabla', false); + } + + /** + * @shcovers inc/coloredUI.inc.sh::CUI_isSet + * @shcovers inc/coloredUI.inc.sh::CUI_displayMsg + */ + public function testDisplayMsg_Simple () + { + $sMsg = $this->_localShellCodeCall('CUI_COLORS=([info]=\'\033[0;36m\'); CUI_displayMsg info bla', false); + $this->assertEquals('\033[0;36mbla\033[0m', $sMsg); + } + + /** + * @shcovers inc/coloredUI.inc.sh::CUI_isSet + * @shcovers inc/coloredUI.inc.sh::CUI_displayMsg + */ + public function testDisplayMsg_SimpleWithMultipleMsg () + { + $sMsg = $this->_localShellCodeCall('CUI_COLORS=([info]=\'\033[0;36m\'); CUI_displayMsg info bla bla bla', false); + $this->assertEquals('\033[0;36mbla bla bla\033[0m', $sMsg); + } + + /** + * @shcovers inc/coloredUI.inc.sh::CUI_isSet + * @shcovers inc/coloredUI.inc.sh::CUI_displayMsg + */ + public function testDisplayMsg_ThrowExceptionWhenOnlyHeader () + { + $this->setExpectedException('RuntimeException', "Unknown display type 'info'!\nAvailable types: ."); + $sMsg = $this->_localShellCodeCall('CUI_COLORS=([info.header]=\'\033[0;36m\'); CUI_displayMsg info bla', false); + } + + /** + * @shcovers inc/coloredUI.inc.sh::CUI_isSet + * @shcovers inc/coloredUI.inc.sh::CUI_displayMsg + */ + public function testDisplayMsg_WithHeader () + { + $sMsg = $this->_localShellCodeCall( + 'CUI_COLORS=([info]=\'\033[0;36m\' [info.header]=\'\033[1;36m(i) \'); ' + . 'CUI_displayMsg info bla bla', false + ); + $this->assertEquals('\033[1;36m(i) \033[0;36mbla bla\033[0m', $sMsg); + } + + /** + * @shcovers inc/coloredUI.inc.sh::CUI_isSet + * @shcovers inc/coloredUI.inc.sh::CUI_displayMsg + */ + public function testDisplayMsg_ThrowExceptionWhenOnlyBold () + { + $this->setExpectedException('RuntimeException', "Unknown display type 'info'!\nAvailable types: ."); + $sMsg = $this->_localShellCodeCall('CUI_COLORS=([info.bold]=\'\033[0;36m\'); CUI_displayMsg info bla', false); + } + + /** + * @shcovers inc/coloredUI.inc.sh::CUI_isSet + * @shcovers inc/coloredUI.inc.sh::CUI_displayMsg + */ + public function testDisplayMsg_WithBold () + { + $sMsg = $this->_localShellCodeCall( + 'CUI_COLORS=([info]=\'\033[0;36m\' [info.bold]=\'\033[1;36m\'); ' + . 'CUI_displayMsg info \"blahahabla\"', false + ); + $this->assertEquals('\033[0;36mbla\033[1;36mhaha\033[0;36mbla\033[0m', $sMsg); + } + + /** + * @shcovers inc/coloredUI.inc.sh::CUI_isSet + * @shcovers inc/coloredUI.inc.sh::CUI_displayMsg + */ + public function testDisplayMsg_WithMultipleBoldTags () + { + $sMsg = $this->_localShellCodeCall( + 'CUI_COLORS=([info]=\'\033[0;36m\' [info.bold]=\'\033[1;36m\'); ' + . 'CUI_displayMsg info \"blahaha-Hello!bla\"', false + ); + $this->assertEquals('\033[0;36mbla\033[1;36mhaha\033[0;36m-\033[1;36mHello!\033[0;36mbla\033[1;36m\033[0;36m\033[0m', $sMsg); + } + + /** + * @shcovers inc/coloredUI.inc.sh::CUI_isSet + * @shcovers inc/coloredUI.inc.sh::CUI_displayMsg + */ + public function testDisplayMsg_WithBoldTagsButWithoutBold () + { + $sMsg = $this->_localShellCodeCall( + 'CUI_COLORS=([info]=\'\033[0;36m\'); ' + . 'CUI_displayMsg info \"blahahabla\"', false + ); + $this->assertEquals('\033[0;36mblahahabla\033[0m', $sMsg); + } + + /** + * @shcovers inc/coloredUI.inc.sh::CUI_isSet + * @shcovers inc/coloredUI.inc.sh::CUI_displayMsg + */ + public function testDisplayMsg_WithMultipleBoldTagsButWithoutBold () + { + $sMsg = $this->_localShellCodeCall( + 'CUI_COLORS=([info]=\'\033[0;36m\'); ' + . 'CUI_displayMsg info \"blahaha-Hello!bla\"', false + ); + $this->assertEquals('\033[0;36mblahaha-Hello!bla\033[0m', $sMsg); + } + + /** + * @shcovers inc/coloredUI.inc.sh::CUI_isSet + * @shcovers inc/coloredUI.inc.sh::CUI_displayMsg + */ + public function testDisplayMsg_WithBoldAndHeader () + { + $sMsg = $this->_localShellCodeCall( + 'CUI_COLORS=([info]=\'\033[0;36m\' [info.bold]=\'\033[1;36m\' [info.header]=\'\033[1;36m(i) \'); ' + . 'CUI_displayMsg info \"blahahabla\"', false + ); + $this->assertEquals('\033[1;36m(i) \033[0;36mbla\033[1;36mhaha\033[0;36mbla\033[0m', $sMsg); + } + + /** + * @shcovers inc/coloredUI.inc.sh::CUI_isSet + * @shcovers inc/coloredUI.inc.sh::CUI_displayMsg + */ + public function testDisplayMsg_WithBoldAndHeaderAndBackslashes () + { + $sMsg = $this->_localShellCodeCall( + 'CUI_COLORS=([info]=\'\033[0;36m\' [info.bold]=\'/&\\\' [info.header]=\'/i\\ \'); ' + . 'CUI_displayMsg info \"blahahabla\"', false + ); + $this->assertEquals('/i\ \033[0;36mbla/&\haha\033[0;36mbla\033[0m', $sMsg); + } +} diff --git a/tests/inc/TwgitTestCase.php b/tests/inc/TwgitTestCase.php index 27dbae0..501d521 100644 --- a/tests/inc/TwgitTestCase.php +++ b/tests/inc/TwgitTestCase.php @@ -47,9 +47,9 @@ protected static function _rawExec ($sCmd) * @param array $data * @param string $dataName */ - public function __construct($name=NULL, array $data=array(), $dataName='') + public function __construct($sName=NULL, array $aData=array(), $sDataName='') { - parent::__construct($name, $data, $dataName); + parent::__construct($sName, $aData, $sDataName); } /** @@ -69,10 +69,11 @@ protected static function stripColors ($sMsg) * En cas d'erreur shell (code d'erreur <> 0), lance une exception incluant le message d'erreur. * * @param string $sCmd + * @param bool $bStripBashColors Supprime ou non la coloration Bash de la chaîne retournée * @return string sortie d'exécution sous forme d'une chaîne de caractères. * @throws RuntimeException en cas d'erreur shell */ - protected function _exec ($sCmd) + protected function _exec ($sCmd, $bStripBashColors=true) { try { $aResult = self::_rawExec($sCmd); @@ -83,7 +84,12 @@ protected function _exec ($sCmd) $oException ); } - $sMsg = preg_replace('/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]/', '', implode("\n", $aResult)); + $sMsg = implode("\n", $aResult); + if ($bStripBashColors) { + $sMsg = preg_replace('/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]/', '', $sMsg); + } else { + $sMsg = str_replace("\033", '\033', $sMsg); + } return $sMsg; } @@ -95,13 +101,14 @@ protected function _exec ($sCmd) * En cas d'erreur shell (code d'erreur <> 0), lance une exception incluant le message d'erreur. * * @param string $sCmd + * @param bool $bStripBashColors Supprime ou non la coloration Bash de la chaîne retournée * @return string sortie d'exécution sous forme d'une chaîne de caractères. * @throws RuntimeException en cas d'erreur shell */ - protected function _localExec ($sCmd) + protected function _localExec ($sCmd, $bStripBashColors=true) { $sLocalCmd = 'cd ' . TWGIT_REPOSITORY_LOCAL_DIR . ' && ' . $sCmd; - return $this->_exec($sLocalCmd); + return $this->_exec($sLocalCmd, $bStripBashColors); } /** @@ -115,13 +122,14 @@ protected function _localExec ($sCmd) * Par exemple : $this->_localFunctionCall('process_fetch x'); * * @param string $sCmd + * @param bool $bStripBashColors Supprime ou non la coloration Bash de la chaîne retournée * @return string sortie d'exécution sous forme d'une chaîne de caractères. * @throws RuntimeException en cas d'erreur shell */ - protected function _localFunctionCall ($sCmd) + protected function _localFunctionCall ($sCmd, $bStripBashColors=true) { $sFunctionCall = '/bin/bash ' . TWGIT_TESTS_INC_DIR . '/testFunction.sh ' . $sCmd; - return $this->_localExec($sFunctionCall); + return $this->_localExec($sFunctionCall, $bStripBashColors); } /** @@ -136,13 +144,14 @@ protected function _localFunctionCall ($sCmd) * Attention à l'échappement des dollars ($). * * @param string $sCmd + * @param bool $bStripBashColors Supprime ou non la coloration Bash de la chaîne retournée * @return string sortie d'exécution sous forme d'une chaîne de caractères. * @throws RuntimeException en cas d'erreur shell */ - protected function _localShellCodeCall ($sCmd) + protected function _localShellCodeCall ($sCmd, $bStripBashColors=true) { $sShellCodeCall = '/bin/bash ' . TWGIT_TESTS_INC_DIR . '/testShellCode.sh "' . $sCmd . '"'; - return $this->_localExec($sShellCodeCall); + return $this->_localExec($sShellCodeCall, $bStripBashColors); } /** @@ -152,12 +161,13 @@ protected function _localShellCodeCall ($sCmd) * En cas d'erreur shell (code d'erreur <> 0), lance une exception incluant le message d'erreur. * * @param string $sCmd + * @param bool $bStripBashColors Supprime ou non la coloration Bash de la chaîne retournée * @return string sortie d'exécution sous forme d'une chaîne de caractères. * @throws RuntimeException en cas d'erreur shell */ - protected function _remoteExec ($sCmd) + protected function _remoteExec ($sCmd, $bStripBashColors=true) { $sRemoteCmd = 'cd ' . TWGIT_REPOSITORY_ORIGIN_DIR . ' && ' . $sCmd; - return $this->_exec($sRemoteCmd); + return $this->_exec($sRemoteCmd, $bStripBashColors); } } diff --git a/tests/inc/testFunction.sh b/tests/inc/testFunction.sh index ca8c027..1048529 100644 --- a/tests/inc/testFunction.sh +++ b/tests/inc/testFunction.sh @@ -13,7 +13,7 @@ sCommonFunction="$1"; shift # Includes: -. `dirname $0`/../../conf/twgit.sh +. $(dirname $0)/../../conf/twgit.sh . $TWGIT_INC_DIR/common.inc.sh # Execution: diff --git a/twgit b/twgit index 846e93a..af7d517 100644 --- a/twgit +++ b/twgit @@ -67,44 +67,44 @@ exec > >(printf -- "$TWGIT_HISTORY_SEPARATOR" "$log_date" "$log_call" >> $TWGIT_ # @tested_by TwgitHelpTest # function usage () { - echo; help 'Usage:' - help_detail 'twgit []' - help_detail ' Always provide branch names without any prefix:' - help_detail " - '$TWGIT_PREFIX_FEATURE', '$TWGIT_PREFIX_RELEASE', '$TWGIT_PREFIX_HOTFIX', (tag) '$TWGIT_PREFIX_TAG'" + echo; CUI_displayMsg help 'Usage:' + CUI_displayMsg help_detail 'twgit []' + CUI_displayMsg help_detail ' Always provide branch names without any prefix:' + CUI_displayMsg help_detail " - '$TWGIT_PREFIX_FEATURE', '$TWGIT_PREFIX_RELEASE', '$TWGIT_PREFIX_HOTFIX', (tag) '$TWGIT_PREFIX_TAG'" - echo; help 'Available commands are:' - help_detail 'feature Manage your feature branches.' - help_detail 'release Manage your release branches.' - help_detail 'hotfix Manage your hotfix branches.' - help_detail 'tag Manage your tags.' + echo; CUI_displayMsg help 'Available commands are:' + CUI_displayMsg help_detail 'feature Manage your feature branches.' + CUI_displayMsg help_detail 'release Manage your release branches.' + CUI_displayMsg help_detail 'hotfix Manage your hotfix branches.' + CUI_displayMsg help_detail 'tag Manage your tags.' echo - help_detail 'clean Help to remove branches no longer tracked.' - help_detail 'init []' - help_detail ' Initialize git repository for twgit:' - help_detail ' - git init if necessary' - help_detail " - add remote $TWGIT_ORIGIN if necessary" - help_detail " - create '$TWGIT_STABLE' branch if not exists, or pull '$TWGIT_ORIGIN/$TWGIT_STABLE'" - help_detail " branch if exists" - help_detail ' - create tag on HEAD of stable, e.g. 1.2.3, using' - help_detail ' major.minor.revision format. ' - help_detail " Prefix '$TWGIT_PREFIX_TAG' will be added to the specified ." - help_detail ' A remote repository must exists.' - help_detail 'update Force update twgit check.' - help_detail '[help] Display this help.' - echo; help 'See also:' - help_detail "Try 'twgit [help]' for more details." + CUI_displayMsg help_detail 'clean Help to remove branches no longer tracked.' + CUI_displayMsg help_detail 'init []' + CUI_displayMsg help_detail ' Initialize git repository for twgit:' + CUI_displayMsg help_detail ' - git init if necessary' + CUI_displayMsg help_detail " - add remote $TWGIT_ORIGIN if necessary" + CUI_displayMsg help_detail " - create '$TWGIT_STABLE' branch if not exists, or pull '$TWGIT_ORIGIN/$TWGIT_STABLE'" + CUI_displayMsg help_detail " branch if exists" + CUI_displayMsg help_detail ' - create tag on HEAD of stable, e.g. 1.2.3, using' + CUI_displayMsg help_detail ' major.minor.revision format. ' + CUI_displayMsg help_detail " Prefix '$TWGIT_PREFIX_TAG' will be added to the specified ." + CUI_displayMsg help_detail ' A remote repository must exists.' + CUI_displayMsg help_detail 'update Force update twgit check.' + CUI_displayMsg help_detail '[help] Display this help.' + echo; CUI_displayMsg help 'See also:' + CUI_displayMsg help_detail "Try 'twgit [help]' for more details." - echo; help 'About:' - help_detail "Contact https://github.com/Twenga/twgit" - help_detail "Git repository git@github.com:Twenga/twgit.git" + echo; CUI_displayMsg help 'About:' + CUI_displayMsg help_detail "Contact https://github.com/Twenga/twgit" + CUI_displayMsg help_detail "Git repository git@github.com:Twenga/twgit.git" local version=$(cd $TWGIT_ROOT_DIR && git describe) - help_detail "Version $version" + CUI_displayMsg help_detail "Version $version" local last_update_timestamp=$(date -r "$TWGIT_UPDATE_PATH" +%s) local last_update_date="$(date --date "1970-01-01 $last_update_timestamp sec" "+%Y-%m-%d %T")" local next_update_timestamp=$(( $last_update_timestamp + $TWGIT_UPDATE_NB_DAYS * 86400 )) local next_update_date="$(date --date "1970-01-01 $next_update_timestamp sec" "+%Y-%m-%d %T")" - help_detail "Last update $last_update_date" - help_detail "Next update $next_update_date" + CUI_displayMsg help_detail "Last update $last_update_date" + CUI_displayMsg help_detail "Next update $next_update_date" echo } @@ -138,7 +138,7 @@ function main () { elif [ "$command" = 'init' ]; then init "$@"; exit 0 elif [ ! -e "$command_file" ]; then - error "Command not found: '$command'" + CUI_displayMsg error "Command not found: '$command'" usage exit 1 else @@ -153,7 +153,7 @@ function main () { fi local action_func_name="cmd_$action" if ! type "$action_func_name" >/dev/null 2>&1; then - error "Unknown action: '$action'" + CUI_displayMsg error "Unknown action: '$action'" usage exit 1 else