diff --git a/test/fixtures/svn/broken/xcrun b/test/fixtures/svn/broken/xcrun new file mode 100755 index 00000000..e69de29b diff --git a/test/fixtures/svn/working/xcrun b/test/fixtures/svn/working/xcrun new file mode 100755 index 00000000..e69de29b diff --git a/test/themes/base.theme.svn.bats b/test/themes/base.theme.svn.bats index f2866c8d..d1c2c311 100644 --- a/test/themes/base.theme.svn.bats +++ b/test/themes/base.theme.svn.bats @@ -7,7 +7,6 @@ load ../../lib/log cite _about _param _example _group _author _version load ../../lib/helpers -load ../../themes/base.theme function local_setup { setup_test_fixture @@ -23,6 +22,8 @@ function local_setup { fi export OLD_PATH="$PATH" + + load ../../themes/base.theme } function local_teardown { @@ -56,8 +57,8 @@ function setup_svn_path { setup_svn_path "$BASH_IT/test/fixtures/svn/working" - # Load the base theme again so that the working SVN script is detected - load ../../themes/base.theme + # Init the base theme again so that the working SVN script is detected + _bash_it_appearance_scm_init scm # Make sure that the SVN command is used @@ -73,8 +74,8 @@ function setup_svn_path { setup_svn_path "$BASH_IT/test/fixtures/svn/working" - # Load the base theme again so that the working SVN script is detected - load ../../themes/base.theme + # init the base theme again so that the working SVN script is detected + _bash_it_appearance_scm_init scm # Make sure that the SVN command is used @@ -89,8 +90,8 @@ function setup_svn_path { setup_svn_path "$BASH_IT/test/fixtures/svn/working" - # Load the base theme again so that the working SVN script is detected - load ../../themes/base.theme + # Init the base theme again so that the working SVN script is detected + _bash_it_appearance_scm_init scm # Make sure that no SVN command is used @@ -103,8 +104,8 @@ function setup_svn_path { setup_svn_path "$BASH_IT/test/fixtures/svn/broken" - # Load the base theme again so that the broken SVN script is detected - load ../../themes/base.theme + # Init the base theme again so that the broken SVN script is detected + _bash_it_appearance_scm_init scm # Make sure that no SVN command is not used @@ -120,8 +121,8 @@ function setup_svn_path { setup_svn_path "$BASH_IT/test/fixtures/svn/broken" - # Load the base theme again so that the broken SVN script is detected - load ../../themes/base.theme + # Init the base theme again so that the broken SVN script is detected + _bash_it_appearance_scm_init scm # Make sure that no SVN command is used diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 4d6a1b7f..5cc791b4 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -85,37 +85,45 @@ RBENV_THEME_PROMPT_SUFFIX='|' RBFU_THEME_PROMPT_PREFIX=' |' RBFU_THEME_PROMPT_SUFFIX='|' -GIT_EXE=$(which git 2> /dev/null || true) -P4_EXE=$(which p4 2> /dev/null || true) -HG_EXE=$(which hg 2> /dev/null || true) -SVN_EXE=$(which svn 2> /dev/null || true) +: "${GIT_EXE:=$SCM_GIT}" +: "${P4_EXE:=$SCM_P4}" +: "${HG_EXE:=$SCM_HG}" +: "${SVN_EXE:=$SCM_SVN}" -# Check for broken SVN exe that is caused by some versions of Xcode. -# See https://github.com/Bash-it/bash-it/issues/1612 for more details. -if [[ -x "$SVN_EXE" ]]; then - if ! "$SVN_EXE" --version > /dev/null 2>&1; then - # Unset the SVN exe variable so that SVN commands are avoided. - SVN_EXE="" +function _bash_it_appearance_scm_init() { + GIT_EXE="$(type -P $SCM_GIT || true)" + P4_EXE="$(type -P $SCM_P4 || true)" + HG_EXE="$(type -P $SCM_HG || true)" + SVN_EXE="$(type -P $SCM_SVN || true)" + + # Check for broken SVN exe that is caused by some versions of Xcode. + # See https://github.com/Bash-it/bash-it/issues/1612 for more details. + if [[ -x "$SVN_EXE" && -x "${SVN_EXE%/*}/xcrun" ]]; then + if ! "$SVN_EXE" --version > /dev/null 2>&1; then + # Unset the SVN exe variable so that SVN commands are avoided. + SVN_EXE="" + fi fi -fi +} +_bash_it_appearance_scm_init function scm { if [[ "$SCM_CHECK" = false ]]; then SCM=$SCM_NONE elif [[ -f .git/HEAD ]] && [[ -x "$GIT_EXE" ]]; then SCM=$SCM_GIT - elif [[ -x "$GIT_EXE" ]] && [[ -n "$(git rev-parse --is-inside-work-tree 2> /dev/null)" ]]; then - SCM=$SCM_GIT - elif [[ -x "$P4_EXE" ]] && [[ -n "$(p4 set P4CLIENT 2> /dev/null)" ]]; then - SCM=$SCM_P4 elif [[ -d .hg ]] && [[ -x "$HG_EXE" ]]; then SCM=$SCM_HG - elif [[ -x "$HG_EXE" ]] && [[ -n "$(hg root 2> /dev/null)" ]]; then - SCM=$SCM_HG elif [[ -d .svn ]] && [[ -x "$SVN_EXE" ]]; then SCM=$SCM_SVN + elif [[ -x "$GIT_EXE" ]] && [[ -n "$(git rev-parse --is-inside-work-tree 2> /dev/null)" ]]; then + SCM=$SCM_GIT + elif [[ -x "$HG_EXE" ]] && [[ -n "$(hg root 2> /dev/null)" ]]; then + SCM=$SCM_HG elif [[ -x "$SVN_EXE" ]] && [[ -n "$(svn info --show-item wc-root 2> /dev/null)" ]]; then SCM=$SCM_SVN + elif [[ -x "$P4_EXE" ]] && [[ -n "$(p4 set P4CLIENT 2> /dev/null)" ]]; then + SCM=$SCM_P4 else SCM=$SCM_NONE fi