diff --git a/.gitignore b/.gitignore index f2766041..6eda6a8b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ doc/tags .netrwhist +*.swp diff --git a/README.md b/README.md index defb7520..afb8b6bb 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,8 @@ Plugin 'rstacruz/sparkup', {'rtp': 'vim/'} " Avoid a name conflict with L9 Plugin 'user/L9', {'name': 'newL9'} + " Specific a plugin version (works with releases and tags) + Plugin 'kien/ctrlp.vim', {'version': '1.79'} " All of your Plugins must be added before the following line call vundle#end() " required diff --git a/autoload/vundle/installer.vim b/autoload/vundle/installer.vim index 472271a3..ab7e5f3e 100644 --- a/autoload/vundle/installer.vim +++ b/autoload/vundle/installer.vim @@ -405,17 +405,41 @@ func! s:make_sync_command(bang, bundle) abort return ['', ''] endif - let cmd_parts = [ - \ 'cd '.vundle#installer#shellesc(a:bundle.path()), - \ 'git pull', - \ 'git submodule update --init --recursive', - \ ] + let cmd_parts = ['cd '.vundle#installer#shellesc(a:bundle.path())] + if (has_key(a:bundle, 'version')) + echo "Processing '".a:bundle.name."' version ".a:bundle.version + call extend(cmd_parts, [ + \ 'git fetch', + \ 'git checkout tags/'.vundle#installer#shellesc(a:bundle.version), + \ ]) + else + call extend(cmd_parts, [ + \ 'git checkout master', + \ 'git pull', + \ ]) + endif + call add(cmd_parts, 'git submodule update --init --recursive') + let cmd = join(cmd_parts, ' && ') let cmd = vundle#installer#shellesc_cd(cmd) let initial_sha = s:get_current_sha(a:bundle) else - let cmd = 'git clone --recursive '.vundle#installer#shellesc(a:bundle.uri).' '.vundle#installer#shellesc(a:bundle.path()) + let cmd_parts = [ + \ 'git clone --recursive '.vundle#installer#shellesc(a:bundle.uri).' '.vundle#installer#shellesc(a:bundle.path()), + \ ] + + if (has_key(a:bundle, 'version')) + echo "Processing '".a:bundle.name."' version ".a:bundle.version + call extend(cmd_parts, [ + \ 'cd '.vundle#installer#shellesc(a:bundle.path()), + \ 'git checkout tags/'.vundle#installer#shellesc(a:bundle.version), + \ ]) + endif + + let cmd = join(cmd_parts, ' && ') + let cmd = vundle#installer#shellesc_cd(cmd) + let initial_sha = '' endif return [cmd, initial_sha] diff --git a/test/end2end/.gitignore b/test/end2end/.gitignore new file mode 100644 index 00000000..55d00c56 --- /dev/null +++ b/test/end2end/.gitignore @@ -0,0 +1 @@ +.vim diff --git a/test/end2end/README.md b/test/end2end/README.md new file mode 100644 index 00000000..f57b1639 --- /dev/null +++ b/test/end2end/README.md @@ -0,0 +1,10 @@ +# End To End Tests + +#### What is this?!? +These are end to end tests written in bash. They need bash, vim and git to be run. +They use real internet connection to download plugins from github, so you cannot run them without it. + +#### To run a specific test: +```bash +$ bash test/end2end/nameOfTest.sh +``` diff --git a/test/end2end/installSpecificPluginTagVersionTest.sh b/test/end2end/installSpecificPluginTagVersionTest.sh new file mode 100644 index 00000000..8bfacc35 --- /dev/null +++ b/test/end2end/installSpecificPluginTagVersionTest.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +source "${SCRIPT_DIR}/testUtils.sh" +cd $SCRIPT_DIR + +# SOME CONSTANTS TO CONSTANTLY BE UPDATED +VIM_FUGITIVE_CURRENT_VERSION="v2.2-71-gaac85a2" +VIM_SURROUND_CURRENT_VERSION="v2.1-9-ge49d6c2" + +# 0. CLEAN +clean + +# 1. INSTALL VUNDLE LOCALLY +deployThisVundle + +# 2.1 INSTALL BUNDLES FROM FIRST LOCAL vimrc +bundlesInstallUsing ${SCRIPT_DIR}/vimrc1 + +# 2.2 CHECK PLUGINS +checkPluginPresenceAndVersion "vim-surround" "v2.1" # custom specified tag +checkPluginPresenceAndVersion "vim-fugitive" $VIM_FUGITIVE_CURRENT_VERSION # actual master version +checkPluginPresenceAndVersion "customFolderName" "1.79" # custom name and specified tag +checkPluginPresenceAndVersion "vim-javascript" "v0.9.0" # another custom specified tag + +# 3.1. INSTALL BUNDLES FROM SECOND LOCAL vimrc +bundlesInstallUsing ${SCRIPT_DIR}/vimrc2 + +# 3.2 CHECK PLUGINS +checkPluginPresenceAndVersion "vim-surround" $VIM_SURROUND_CURRENT_VERSION # removed specified version +checkPluginPresenceAndVersion "vim-fugitive" "v1.2" # added custom specified version +checkPluginPresenceAndVersion "ctrlp.vim" "1.78" # removed custom name and changed tag version +checkPluginPresenceAndVersion "vim-javascript" "v0.9.0" # nothing changed here + +# 4 GREEN BAR AND CLEAN +successPrintAndClean diff --git a/test/end2end/testUtils.sh b/test/end2end/testUtils.sh new file mode 100644 index 00000000..b4a26c21 --- /dev/null +++ b/test/end2end/testUtils.sh @@ -0,0 +1,48 @@ +NC='\033[0m' # No Color +BUNDLES_FOLDER="${SCRIPT_DIR}/.vim/bundle/" + +function successPrintAndClean { + GREEN='\033[42m' + printf "${GREEN} Green bar!! :-) ${NC}\n" + clean +} + +function errorPrintAndClean { + RED='\033[41m' + printf "${RED} $1 :-( ${NC}\n" + clean +} + +function clean { + rm -rf ${SCRIPT_DIR}/.vim +} + +function deployThisVundle { + mkdir -p ${SCRIPT_DIR}/.vim/bundle/vundle + cp -r ${SCRIPT_DIR}/../../* ./.vim/bundle/vundle/ 2> /dev/null +} + +function bundlesInstallUsing { + vim -u $1 +BundleInstall! +qall +} + +function checkPluginPresenceAndVersion { + name=$1 + expectedVersion=$2 + pluginFolder=${BUNDLES_FOLDER}${name} + + if [ ! -d $pluginFolder ]; then + errorPrintAndClean "No plugin folder for ${name}!!" + exit + fi + + cd $pluginFolder + gitDescribe=$(git describe --tags) + + if [ "$gitDescribe" != "$expectedVersion" ]; then + errorPrintAndClean "Wrong plugin version for ${name} (${gitDescribe})!" + exit + fi + + cd $SCRIPT_DIR +} diff --git a/test/end2end/vimrc1 b/test/end2end/vimrc1 new file mode 100644 index 00000000..66aab584 --- /dev/null +++ b/test/end2end/vimrc1 @@ -0,0 +1,14 @@ +set nocompatible +filetype off + +set rtp=./.vim/ +set rtp+=./.vim/bundle/vundle/ +call vundle#begin('./.vim/bundle') + +Plugin 'tpope/vim-fugitive' +Plugin 'tpope/vim-surround', {'version': 'v2.1'} +Plugin 'kien/ctrlp.vim', {'name': 'customFolderName', 'version': '1.79'} +Plugin 'pangloss/vim-javascript', {'version': 'v0.9.0'} + + +call vundle#end() diff --git a/test/end2end/vimrc2 b/test/end2end/vimrc2 new file mode 100644 index 00000000..e6966a4d --- /dev/null +++ b/test/end2end/vimrc2 @@ -0,0 +1,13 @@ +set nocompatible +filetype off + +set rtp=./.vim/ +set rtp+=./.vim/bundle/vundle/ +call vundle#begin('./.vim/bundle') + +Plugin 'tpope/vim-fugitive', {'version': 'v1.2'} +Plugin 'tpope/vim-surround' +Plugin 'kien/ctrlp.vim', {'version': '1.78'} +Plugin 'pangloss/vim-javascript', {'version': 'v0.9.0'} + +call vundle#end()