vim-update-bundles 0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (6) hide show
  1. data/CHANGES +48 -0
  2. data/README.md +147 -0
  3. data/Rakefile +5 -0
  4. data/test.rb +660 -0
  5. data/vim-update-bundles +471 -0
  6. metadata +74 -0
data/CHANGES ADDED
@@ -0,0 +1,48 @@
1
+ 0.6 29 Jun 2011
2
+ - Added doc/bundle-log.txt. :help bundle-log to see it.
3
+ - Added --no-updates option to make adding/deleting bundles faster.
4
+ - Support single-letter options (-v for --verbose, -n for --no-updates).
5
+ - It's BundleCommand though Bundle-Command and BUNDLE COMMAND still work.
6
+ - Added --help and --version.
7
+ - Cleanups and doc fixes by Sorin Ionescu.
8
+ - bugfix: changing branch name would merge instead of switching branches.
9
+
10
+ 0.4.1 11 May 2011
11
+ - Support vundle-style short repo names thanks to Chris Toomey
12
+
13
+ 0.4.0 06 Mar 2011
14
+ - Greatly simplify path configuration thanks to Sorin Ionescu
15
+ - No longer use Ruby as config file format, it's just key=value now
16
+ ("static=1" still works but it's $HOME instead of "#{ENV['HOME']}")
17
+ - Add the Static: directive thanks to Andreas Marienborg
18
+ - Remove submodule entries from .gitmodules and .git/config (also Sorin)
19
+
20
+ 0.3.1 30 Oct 2010
21
+ - restore Ruby 1.8 compatibility (popen doesn't accept an array)
22
+ - promise to check rvm before releasing
23
+
24
+ 0.3 29 Oct 2010
25
+ - added submodule support thanks to steeef.
26
+ - support putting .vim and .vimrc in custom locations using config options.
27
+ - every repo now automatically ignores doc/tags.
28
+ - BUNDLE and BUNDLE-COMMAND are now case-insensitive.
29
+ - If a BUNDLE-COMMAND fails, vim-update-bundles now exits immediately.
30
+
31
+ 0.2 27 Oct 2010
32
+ - Added a pure ruby configuration file, ~/vim-update-bundles.rb
33
+ - Don't clean ".vim" from repo names. a.vim is "a.vim" and not just "a".
34
+ - Added verbose flag. Run ./vim-update-bundles --verbose=1 to hear everything.
35
+ - bugfix: repos weren't automatically fast-forwarding to the latest commit.
36
+ - added command line args: ./vim-update-bundles vimrc="$HOME/dots/vimrc"
37
+ but they're not very useful in real life, only for testing.
38
+ - added some tests! "rake test" in the git repo to run them.
39
+ - created a changes file.
40
+
41
+ 0.1 20 Sep 2010
42
+ - add ability to create new vim environment from scratch.
43
+ - add BUNDLE-COMMAND directive to run shell commands.
44
+ - remove dashes from directive (it's '" BUNDLE:' now, not '" --- BUNDLE:').
45
+ - don't ever rm -rf, move deleted bundles to ~.vim/Trashed-Bundles.
46
+
47
+ 0.01 14 Aug 2010
48
+ - initial release
data/README.md ADDED
@@ -0,0 +1,147 @@
1
+ # vim-update-bundles
2
+
3
+ Use Pathogen and Git to manage your Vim plugins.
4
+
5
+ [![Travis Build Status](http://travis-ci.org/bronson/vim-update-bundles.png)](http://travis-ci.org/bronson/vim-update-bundles)
6
+
7
+
8
+ ## Description
9
+
10
+ To install a plugin, put lines like this in your ~/.vimrc:
11
+
12
+ " Bundle: jQuery # https://github.com/vim-scripts/jQuery
13
+ " Bundle: scrooloose/nerdtree # https://github.com/scrooloose/nerdtree
14
+ " Bundle: https://github.com/scrooloose/nerdtree.git # Full URL to the repository.
15
+
16
+ Now, run `./vim-update-bundles`. Your plugins are installed and ready for use.
17
+
18
+ Type `:help bundles` from within Vim to show the list of plugins that you have installed.
19
+ Hit Control-] on the bundle's name to jump to its documentation.
20
+ Also make sure to look at the bundle-log.
21
+
22
+
23
+ ## Installation
24
+
25
+ One of:
26
+
27
+ * git clone: `git clone https://github.com/bronson/vim-update-bundles.git`
28
+ * rubygem: `gem install vim-update-bundles`
29
+ * no install: `curl -s https://raw.github.com/bronson/vim-update-bundles/master/vim-update-bundles | ruby`
30
+
31
+
32
+ ## Usage
33
+
34
+ $ ./vim-update-bundles --help
35
+
36
+ If you're not already using Vim, vim-update-bundles will set up a typical vim environment.
37
+ Edit your ~/.vimrc and run vim-update-bundles whenever you want changes to take effect.
38
+
39
+ vim-update-bundles will use ~/.dotfiles if it exists; so, it works seamlessly
40
+ with <http://github.com/ryanb/dotfiles> and friends. It also supports Git
41
+ submodules (see the configuration section below).
42
+
43
+ * _-n -\-no-updates_ Adds and deletes bundles but doesn't update them.
44
+ This prevents vim-update-bundles from laboriously scrubbing through every
45
+ bundle in your .vimrc when you just want to make a quick change.
46
+
47
+ * _-s -\-submodule_ installs bundles as submodules intead of plain Git
48
+ repositories. You must create the parent repository to contain the
49
+ submodules before running vim-update bundles.
50
+
51
+ * _-v -\-verbose_ prints more information about what's happening.
52
+
53
+
54
+ ## Specifying Plugins
55
+
56
+ vim-update-bundles reads the plugins you want installed from your ~/.vimrc.
57
+ Here are the directives it recognizes:
58
+
59
+ #### Bundle:
60
+
61
+ Any line of the format `" Bundle: URL [REV]` (not case sensitive) will be
62
+ interpreted as a bundle to download. _URL_ points to a Git repository and
63
+ _REV_ is an optional refspec (Git branch, tag, or hash). This allows you to
64
+ follow a branch or lock the bundle to a specific tag or commit, i.e.:
65
+
66
+ " Bundle: https://github.com/tpope/vim-endwise.git v1.0
67
+
68
+ If the script lives on vim-scripts or GitHub, the URL can be abbreviated:
69
+
70
+ " Bundle: tpope/vim-endwise -> https://github.com/tpope/vim-endwise.git
71
+ " Bundle: endwise.vim -> https://github.com/vim-scripts/endwise.vim.git
72
+
73
+ vim-update-bundles never deletes files. When you uninstall a plugin, it moves it to the .vim/Trashed-Bundles directory.
74
+
75
+ #### BundleCommand:
76
+
77
+ Some bundles need to be built after they're installed. Place any number of
78
+ `BundleCommand:` directives after `Bundle:` to execute shell commands within
79
+ the bundle's directory. To install Command-T and ensure "rake make" is called
80
+ every time it's updated:
81
+
82
+ " Bundle: https://git.wincent.com/command-t.git
83
+ " BundleCommand: rake make
84
+
85
+ #### Static:
86
+
87
+ If you have directories in ~/.vim/bundle that you'd like vim-update-bundles to
88
+ ignore, mark them as static.
89
+
90
+ " Static: my-plugin
91
+
92
+
93
+ ## Configuration File
94
+
95
+ All configuration options can be passed on the command line or placed in ~/.vim-update-bundles.conf.
96
+ Putting "submodules=1" in the config file is the same as passing -s or --submodules on the command line.
97
+ Blank lines and comments starting with '#' are ignored.
98
+
99
+ String interpolation is performed on all values. First configuration settings
100
+ are tried then environment variables. For instance, this would expand to
101
+ "/home/_username_/.dotfiles/_username_/vim":
102
+
103
+ vimdir_path = $dotfiles_path/$USERNAME/vim
104
+
105
+
106
+ ## Location of .vim and .vimrc
107
+
108
+ Unless you have a custom dotfiles configuration, you can probably skip this
109
+ section.
110
+
111
+ vim-update-bundles tries hard to figure out where you want to store your .vim
112
+ directory and .vimrc file. It first looks for a dotfiles directory (~/.dotfiles
113
+ or specified by dotfiles\_path).
114
+
115
+ * dotfiles\_path = $HOME/.dotfiles
116
+
117
+ If dotfiles\_path exists, then vim-update-bundles will use it; otherwise, it
118
+ will use the default location:
119
+
120
+ * vimdir\_path = $dotfiles\_path/vim
121
+ * vimdir\_path = $HOME/.vim
122
+
123
+ Finally, these are the places that vim-update-bundles will look for a .vimrc:
124
+
125
+ * vimrc\_path = $dotfiles\_path/vim/vimrc
126
+ * vimrc\_path = $dotfiles\_path/vimrc
127
+ * vimrc\_path = $HOME/.vim/vimrc
128
+ * vimrc\_path = $HOME/.vimrc
129
+
130
+ It always updates the ~/.vim and ~/.vimrc symlinks; so, Vim can find the correct
131
+ files.
132
+
133
+
134
+ ## Authors
135
+
136
+ * [Scott Bronson](http://github.com/bronson)
137
+ * [Sorin Ionescu](http://github.com/sorin-ionescu)
138
+ * [steeef](http://github.com/steeef)
139
+ * [Andreas Marienborg](http://github.com/omega)
140
+
141
+
142
+ ## Alternatives
143
+
144
+ [Vundle](http://github.com/gmarik/vundle) by [gmarik](http://github.com/gmarik) is starting to look pretty awesome.
145
+
146
+ Additionally, see vim-scripts.org's [tools page](http://vim-scripts.org/vim/tools.html).
147
+
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ task :default => [:test]
2
+
3
+ task :test do
4
+ ruby "test.rb"
5
+ end
data/test.rb ADDED
@@ -0,0 +1,660 @@
1
+ require 'tempfile'
2
+ require 'tmpdir'
3
+ require 'test/unit'
4
+
5
+ # You can specify where the tests will be run instead of mktmpdir's default:
6
+ # TESTDIR=/ramdisk/test ruby test.rb
7
+ # You can also tell the tester to preserve the test directory after running:
8
+ # PRESERVE=1 ruby test.rb -n test_multiple_removes
9
+ #
10
+ # TODO: test when .vimrc and .vim/vimrc both exist, the former is preferred
11
+ #
12
+ # We shell to the executable; so, this isn't actually unit testing.
13
+ # Has anyone written a functional test framework for executables?
14
+
15
+
16
+ class TestUpdater < Test::Unit::TestCase
17
+ def prepare_test &block
18
+ # Creates a tmp dir to run the test in then yields to the test.
19
+ args = ['vimtest-']
20
+ args.push ENV['TESTDIR'] if ENV['TESTDIR']
21
+ if ENV['PRESERVE']
22
+ tmpdir = Dir.mktmpdir *args
23
+ prepare_test_trampoline tmpdir, block
24
+ else
25
+ Dir.mktmpdir(*args) do |tmpdir|
26
+ prepare_test_trampoline tmpdir, block
27
+ end
28
+ end
29
+ end
30
+
31
+ def prepare_test_trampoline tmpdir, block
32
+ create_mock_files tmpdir
33
+ Dir.mkdir "#{tmpdir}/home"
34
+ ENV['HOME']="#{tmpdir}/home"
35
+ ENV['TESTING']='1'
36
+ block.call "#{tmpdir}/home"
37
+ end
38
+
39
+ def write_file base, path, contents
40
+ File.open(File.join(base, path), 'w') { |f| f.write contents }
41
+ end
42
+
43
+ def create_mock_files tmpdir
44
+ # Creates mock files to download (it saves on bandwidth and test time).
45
+ write_file tmpdir, "pathogen", "\" PATHOGEN SCRIPT"
46
+ write_file tmpdir, "starter-vimrc", "\" STARTER VIMRC"
47
+ @starter_urls = "starter_url='#{tmpdir}/starter-vimrc' pathogen_url='#{tmpdir}/pathogen'"
48
+ end
49
+
50
+ def create_mock_repo name
51
+ Dir.mkdir name
52
+ Dir.chdir name do
53
+ `git init`
54
+ write_file name, "first", "first"
55
+ `git add first`
56
+ `git commit -q -m first`
57
+ end
58
+ end
59
+
60
+ def update_mock_repo dir, name
61
+ Dir.chdir dir do
62
+ write_file dir, name, name
63
+ `git add '#{name}'`
64
+ `git commit -q -m '#{name}'`
65
+ end
66
+ end
67
+
68
+ def update_mock_repo_tagged dir, name, tag
69
+ update_mock_repo dir, name
70
+ Dir.chdir(dir) { `git tag -a #{tag} -m 'tag #{tag}'` }
71
+ end
72
+
73
+ def assert_test cmd, *files
74
+ files.each do |f|
75
+ assert test(?e, f), "#{f} does not exist!"
76
+ assert test(cmd, f), "#{f} is not a '#{cmd}'"
77
+ end
78
+ end
79
+
80
+ def refute_test cmd, *files
81
+ files.each do |f|
82
+ assert !test(cmd, f), "#{f} is a '#{cmd}'"
83
+ end
84
+ end
85
+
86
+ def check_tree base, vimdir='.vim', vimrc='.vimrc'
87
+ # Makes sure .vim, .vimrc, and the symlinks are set up correctly.
88
+
89
+ if vimdir == '.vim'
90
+ # No symlinks are needed.
91
+ assert_test ?d, "#{base}/.vim"
92
+ else
93
+ # it appears Rubinius has a bug https://github.com/rubinius/rubinius/issues/1057
94
+ #assert_test ?l, "#{base}/.vim"
95
+ assert_equal File.readlink("#{base}/.vim"), "#{base}/#{vimdir}"
96
+ end
97
+
98
+ if vimrc == '.vimrc'
99
+ assert_test ?f, "#{base}/.vimrc"
100
+ else
101
+ # it appears Rubinius has a bug https://github.com/rubinius/rubinius/issues/1057
102
+ #assert_test ?l, "#{base}/.vimrc"
103
+ assert_equal File.readlink("#{base}/.vimrc"), "#{base}/#{vimrc}"
104
+ end
105
+
106
+ assert_test ?f, "#{base}/#{vimdir}/autoload/pathogen.vim"
107
+ assert_test ?d, "#{base}/#{vimdir}"
108
+ assert_test ?f, "#{base}/#{vimrc}"
109
+ end
110
+
111
+ def run_vim_update_bundles *args
112
+ `./vim-update-bundles #{@starter_urls} #{args.join(' ')}`
113
+ end
114
+
115
+
116
+ # runs the command under test expecting there will not be an error
117
+ def vim_update_bundles *args
118
+ result = run_vim_update_bundles *args
119
+ raise "vim-update-bundles returned #{$?.exitstatus} RESULT: <<\n#{result}>>" unless $?.exitstatus == 0
120
+ result
121
+ end
122
+
123
+ # runs the command under test expecting that there WILL be an error
124
+ def vim_update_bundles__expect_error *args
125
+ result = run_vim_update_bundles *args + ['2>&1']
126
+ raise "vim-update-bundles returned #{$?.exitstatus} RESULT: <<\n#{result}>>" unless $?.exitstatus != 0
127
+ result
128
+ end
129
+
130
+
131
+ def test_standard_run
132
+ # Creates a starter environment then updates a few times.
133
+ prepare_test do |tmpdir|
134
+ vim_update_bundles
135
+ check_tree tmpdir
136
+ assert_test ?f, "#{tmpdir}/.vim/doc/bundles.txt"
137
+ assert_test ?d, "#{tmpdir}/.vim/bundle"
138
+ assert_equal ['.', '..'], Dir.open("#{tmpdir}/.vim/bundle") { |d| d.sort }
139
+
140
+ # Add a repository.
141
+ create_mock_repo "#{tmpdir}/repo"
142
+ write_file tmpdir, ".vimrc", "\" Bundle: #{tmpdir}/repo"
143
+ vim_update_bundles
144
+ assert_equal ['.', '..', 'repo'], Dir.open("#{tmpdir}/.vim/bundle") { |d| d.sort }
145
+ repo = "#{tmpdir}/.vim/bundle/repo" # The local repository, not the origin.
146
+ assert_test ?f, "#{repo}/first"
147
+ assert_equal 1, File.read("#{repo}/.git/info/exclude").scan("doc/tags").size
148
+
149
+ # Pull upstream changes.
150
+ update_mock_repo "#{tmpdir}/repo", "second"
151
+ vim_update_bundles
152
+ assert_test ?f, "#{tmpdir}/.vim/bundle/repo/second"
153
+ assert_equal 1, File.read("#{repo}/.git/info/exclude").scan("doc/tags").size
154
+
155
+ # Remove the repository.
156
+ write_file tmpdir, ".vimrc", ""
157
+ vim_update_bundles
158
+ refute_test ?d, repo
159
+ end
160
+ end
161
+
162
+
163
+ def test_dont_blow_away_existing_vimrc
164
+ # Do not destroy an existing .vimrc.
165
+ prepare_test do |tmpdir|
166
+ str = "don't tread on me"
167
+ write_file tmpdir, '.vimrc', str
168
+ vim_update_bundles "--vimrc_path='#{tmpdir}/.vimrc'"
169
+ assert_equal str, File.read("#{tmpdir}/.vimrc")
170
+ end
171
+ end
172
+
173
+
174
+ def test_submodule_run
175
+ # Creates a starter environment using submodules.
176
+ prepare_test do |tmpdir|
177
+ Dir.mkdir "#{tmpdir}/.vim"
178
+ Dir.chdir("#{tmpdir}/.vim") { `git init` }
179
+ vim_update_bundles
180
+ check_tree tmpdir, ".vim", ".vimrc"
181
+
182
+ # Add submodule.
183
+ create_mock_repo "#{tmpdir}/repo"
184
+ File.open("#{tmpdir}/.vim-update-bundles.conf", 'w') { |f| f.write "submodule = true" }
185
+ write_file tmpdir, ".vimrc", "\" Bundle: #{tmpdir}/repo"
186
+
187
+ vim_update_bundles
188
+ assert_equal ['.', '..', 'repo'], Dir.open("#{tmpdir}/.vim/bundle") { |d| d.sort }
189
+ repo = "#{tmpdir}/.vim/bundle/repo" # The local repository, not the origin.
190
+ assert_test ?f, "#{repo}/first"
191
+ assert_test ?f, "#{tmpdir}/.vim/.gitmodules"
192
+ assert_equal 1, File.read("#{repo}/.git/info/exclude").scan("doc/tags").size
193
+
194
+ # Pull upstream changes.
195
+ update_mock_repo "#{tmpdir}/repo", "second"
196
+ vim_update_bundles
197
+ assert_test ?f, "#{tmpdir}/.vim/bundle/repo/second"
198
+
199
+ # Remove the repository.
200
+ write_file tmpdir, ".vimrc", ""
201
+ vim_update_bundles
202
+ refute_test ?d, repo
203
+
204
+ ['.gitmodules', '.git/config'].each do |filename|
205
+ text = File.read File.join(tmpdir, '.vim', filename)
206
+ assert_no_match /submodule.*repo/, text
207
+ end
208
+ end
209
+ end
210
+
211
+
212
+ def test_tag_checkout
213
+ # Ensures locking a checkout to a tag and that .vim/vimrc is used if it
214
+ # already exists.
215
+ prepare_test do |tmpdir|
216
+ Dir.mkdir "#{tmpdir}/.vim"
217
+ write_file tmpdir, ".vim/vimrc", ''
218
+ vim_update_bundles
219
+ check_tree tmpdir, ".vim", ".vim/vimrc"
220
+
221
+ # Make a repository with a tagged commit and commits after that.
222
+ create_mock_repo "#{tmpdir}/repo"
223
+ update_mock_repo_tagged "#{tmpdir}/repo", 'second', '0.2'
224
+ update_mock_repo "#{tmpdir}/repo", 'third'
225
+
226
+ # Check out the plugin locked at 0.2
227
+ write_file tmpdir, ".vim/vimrc", "\" Bundle: #{tmpdir}/repo 0.2"
228
+ vim_update_bundles
229
+ assert_equal ['.', '..', 'repo'], Dir.open("#{tmpdir}/.vim/bundle") { |d| d.sort }
230
+ assert_test ?f, "#{tmpdir}/.vim/bundle/repo/first"
231
+ assert_test ?f, "#{tmpdir}/.vim/bundle/repo/second"
232
+ refute_test ?f, "#{tmpdir}/.vim/bundle/repo/third"
233
+
234
+ # Pull upstream changes, make sure we're still locked on 0.2.
235
+ update_mock_repo "#{tmpdir}/repo", "fourth"
236
+ vim_update_bundles
237
+ assert_test ?f, "#{tmpdir}/.vim/bundle/repo/second"
238
+ refute_test ?f, "#{tmpdir}/.vim/bundle/repo/third"
239
+ refute_test ?f, "#{tmpdir}/.vim/bundle/repo/fourth"
240
+
241
+ # Switch to the branch head
242
+ write_file tmpdir, ".vim/vimrc", "\" Bundle: #{tmpdir}/repo"
243
+ vim_update_bundles
244
+ assert_test ?f, "#{tmpdir}/.vim/bundle/repo/first"
245
+ assert_test ?f, "#{tmpdir}/.vim/bundle/repo/second"
246
+ assert_test ?f, "#{tmpdir}/.vim/bundle/repo/third"
247
+
248
+ # Switch back to the tag
249
+ write_file tmpdir, ".vim/vimrc", "\" Bundle: #{tmpdir}/repo 0.2"
250
+ vim_update_bundles
251
+ assert_test ?f, "#{tmpdir}/.vim/bundle/repo/first"
252
+ assert_test ?f, "#{tmpdir}/.vim/bundle/repo/second"
253
+ refute_test ?f, "#{tmpdir}/.vim/bundle/repo/third"
254
+ end
255
+ end
256
+
257
+
258
+ def test_submodule_tag_checkout
259
+ # Ensures locking a checkout to a tag.
260
+ prepare_test do |tmpdir|
261
+ Dir.chdir(tmpdir) { `git init` }
262
+ vim_update_bundles '--submodule=true'
263
+ check_tree tmpdir
264
+
265
+ create_mock_repo "#{tmpdir}/repo"
266
+ update_mock_repo_tagged "#{tmpdir}/repo", 'second', '0.2'
267
+ update_mock_repo "#{tmpdir}/repo", 'third'
268
+
269
+ write_file tmpdir, ".vimrc", "\" Bundle: #{tmpdir}/repo 0.2"
270
+ vim_update_bundles '--submodule=1'
271
+ assert_equal ['.', '..', 'repo'], Dir.open("#{tmpdir}/.vim/bundle") { |d| d.sort }
272
+ assert_test ?f, "#{tmpdir}/.gitmodules"
273
+ repo = "#{tmpdir}/.vim/bundle/repo" # The local repository, not the origin.
274
+ `git ls-files --cached .vim/bundle/repo`
275
+ assert_test ?f, "#{repo}/first"
276
+ assert_test ?f, "#{repo}/second"
277
+ refute_test ?f, "#{repo}/third"
278
+
279
+ # Pull upstream changes.
280
+ update_mock_repo "#{tmpdir}/repo", "third"
281
+ vim_update_bundles '--submodule=1'
282
+ assert_test ?f, "#{repo}/second"
283
+ refute_test ?f, "#{repo}/third"
284
+ refute_test ?f, "#{repo}/fourth"
285
+ end
286
+ end
287
+
288
+
289
+ def test_branch_checkout
290
+ # Ensures new commits on a branch are followed.
291
+ prepare_test do |tmpdir|
292
+ vim_update_bundles
293
+ check_tree tmpdir
294
+
295
+ # Make a repository with another branch.
296
+ create_mock_repo "#{tmpdir}/repo"
297
+ Dir.chdir("#{tmpdir}/repo") { `git checkout -q -b abranch` }
298
+ update_mock_repo "#{tmpdir}/repo", 'b-second'
299
+ Dir.chdir("#{tmpdir}/repo") { `git checkout -q master` }
300
+ update_mock_repo "#{tmpdir}/repo", 'second'
301
+
302
+ # Clone repository on the given branch.
303
+ write_file tmpdir, ".vimrc", "\" Bundle: #{tmpdir}/repo abranch"
304
+ vim_update_bundles
305
+ assert_equal ['.', '..', 'repo'], Dir.open("#{tmpdir}/.vim/bundle") { |d| d.sort }
306
+ repo = "#{tmpdir}/.vim/bundle/repo" # The local repository, not the origin.
307
+ assert_test ?f, "#{repo}/first"
308
+ assert_test ?f, "#{repo}/b-second"
309
+ refute_test ?f, "#{repo}/second"
310
+
311
+ # Pull upstream changes.
312
+ update_mock_repo "#{tmpdir}/repo", "third"
313
+ Dir.chdir("#{tmpdir}/repo") { `git checkout -q abranch` }
314
+ update_mock_repo "#{tmpdir}/repo", "b-third"
315
+ vim_update_bundles
316
+ assert_test ?f, "#{repo}/b-second"
317
+ assert_test ?f, "#{repo}/b-third"
318
+ refute_test ?f, "#{repo}/second"
319
+ refute_test ?f, "#{repo}/third"
320
+
321
+ # Switch to the master branch
322
+ write_file tmpdir, ".vimrc", "\" Bundle: #{tmpdir}/repo"
323
+ vim_update_bundles
324
+ assert_test ?f, "#{repo}/second"
325
+ assert_test ?f, "#{repo}/third"
326
+ refute_test ?f, "#{repo}/b-second"
327
+ refute_test ?f, "#{repo}/b-third"
328
+
329
+ # And switch back to our branch
330
+ write_file tmpdir, ".vimrc", "\" Bundle: #{tmpdir}/repo abranch"
331
+ vim_update_bundles
332
+ assert_test ?f, "#{repo}/b-second"
333
+ assert_test ?f, "#{repo}/b-third"
334
+ refute_test ?f, "#{repo}/second"
335
+ refute_test ?f, "#{repo}/third"
336
+ end
337
+ end
338
+
339
+
340
+ def test_submodule_branch_checkout
341
+ # Ensures locking a checkout to a tag.
342
+ prepare_test do |tmpdir|
343
+ Dir.chdir(tmpdir) { `git init` }
344
+ vim_update_bundles '--submodule=true'
345
+ check_tree tmpdir
346
+
347
+ # Make a repository with another branch.
348
+ create_mock_repo "#{tmpdir}/repo"
349
+ Dir.chdir("#{tmpdir}/repo") { `git checkout -q -b abranch` }
350
+ update_mock_repo "#{tmpdir}/repo", 'b-second'
351
+ Dir.chdir("#{tmpdir}/repo") { `git checkout -q master` }
352
+ update_mock_repo "#{tmpdir}/repo", 'second'
353
+
354
+ write_file tmpdir, ".vimrc", "\" Bundle: #{tmpdir}/repo abranch"
355
+ vim_update_bundles '--submodule=1'
356
+ assert_equal ['.', '..', 'repo'], Dir.open("#{tmpdir}/.vim/bundle") { |d| d.sort }
357
+ assert_test ?f, "#{tmpdir}/.gitmodules"
358
+ repo = "#{tmpdir}/.vim/bundle/repo" # The local repository, not the origin.
359
+ `git ls-files --cached .vim/bundle/repo`
360
+ assert_test ?f, "#{repo}/first"
361
+ assert_test ?f, "#{repo}/b-second"
362
+ refute_test ?f, "#{repo}/second"
363
+
364
+ # Pull upstream changes.
365
+ update_mock_repo "#{tmpdir}/repo", "third"
366
+ Dir.chdir("#{tmpdir}/repo") { `git checkout -q abranch` }
367
+ update_mock_repo "#{tmpdir}/repo", "b-third"
368
+ vim_update_bundles '--submodule=1'
369
+ assert_test ?f, "#{repo}/b-second"
370
+ assert_test ?f, "#{repo}/b-third"
371
+ refute_test ?f, "#{repo}/third"
372
+ end
373
+ end
374
+
375
+
376
+ def test_clone_nonexistent_branch
377
+ # Ensures we error out if we find a nonexistent branch or tag (same code path)
378
+ prepare_test do |tmpdir|
379
+ create_mock_repo "#{tmpdir}/repo1"
380
+ create_mock_repo "#{tmpdir}/repo2"
381
+
382
+ write_file tmpdir, ".vimrc", "\" Bundle: #{tmpdir}/repo1 nobranch\n\" Bundle: #{tmpdir}/repo2"
383
+ vim_update_bundles__expect_error
384
+ refute_test ?d, "#{tmpdir}/.vim/bundle/repo2" # ensure we didn't continue cloning repos
385
+ end
386
+ end
387
+
388
+
389
+ def test_update_to_nonexistent_branch
390
+ prepare_test do |tmpdir|
391
+ create_mock_repo "#{tmpdir}/repo1"
392
+ create_mock_repo "#{tmpdir}/repo2"
393
+
394
+ write_file tmpdir, ".vimrc", "\" Bundle: #{tmpdir}/repo1"
395
+ vim_update_bundles
396
+ assert_test ?f, "#{tmpdir}/.vim/bundle/repo1/first"
397
+
398
+ write_file tmpdir, ".vimrc", "\" Bundle: #{tmpdir}/repo1 v0.2\n\" Bundle: #{tmpdir}/repo2"
399
+ vim_update_bundles__expect_error
400
+ refute_test ?d, "#{tmpdir}/.vim/bundle/repo2" # ensure we didn't continue cloning repos
401
+ end
402
+ end
403
+
404
+
405
+ def test_multiple_removes
406
+ # add and remove a plugin multiple times
407
+ prepare_test do |tmpdir|
408
+ create_mock_repo "#{tmpdir}/plugin1"
409
+ 4.times do
410
+ write_file tmpdir, '.vimrc', "\" Bundle: #{tmpdir}/plugin1"
411
+ vim_update_bundles
412
+ assert_test ?d, "#{tmpdir}/.vim/bundle/plugin1"
413
+
414
+ write_file tmpdir, '.vimrc', ''
415
+ vim_update_bundles
416
+ refute_test ?d, "#{tmpdir}/.vim/bundle/plugin1"
417
+ end
418
+ end
419
+ end
420
+
421
+
422
+ def test_bundle_command # oops, there's some duplication with test_working_bundle_command
423
+ prepare_test do |tmpdir|
424
+ # ensure BundleCommand is called when adding a repo
425
+ create_mock_repo "#{tmpdir}/plugin1"
426
+ write_file tmpdir, ".vimrc", "\" Bundle: #{tmpdir}/plugin1\n\" BundleCommand: touch '#{tmpdir}/sentinel1'"
427
+ vim_update_bundles
428
+ assert_test ?f, "#{tmpdir}/sentinel1"
429
+
430
+ # ensure BundleCommand is called when updating a repo
431
+ update_mock_repo "#{tmpdir}/plugin1", "second"
432
+ write_file tmpdir, ".vimrc", "\" Bundle: #{tmpdir}/plugin1\n\" Bundle-Command: touch '#{tmpdir}/sentinel2'"
433
+ vim_update_bundles
434
+ assert_test ?f, "#{tmpdir}/sentinel2"
435
+
436
+ # ensure BundleCommand is NOT called when updating a repo when --no-updates is on
437
+ update_mock_repo "#{tmpdir}/plugin1", "second"
438
+ write_file tmpdir, ".vimrc", "\" Bundle: #{tmpdir}/plugin1\n\" BundleCommand: touch '#{tmpdir}/sentinel3'"
439
+ vim_update_bundles '--no-updates'
440
+ refute_test ?f, "#{tmpdir}/sentinel3"
441
+ end
442
+ end
443
+
444
+
445
+ def test_working_bundle_command
446
+ prepare_test do |tmpdir|
447
+ vim_update_bundles
448
+ check_tree tmpdir
449
+ create_mock_repo "#{tmpdir}/repo"
450
+ write_file tmpdir, ".vimrc", <<-EOL
451
+ " Bundle: #{tmpdir}/repo
452
+ " Bundle command: echo hiya > #{tmpdir}/output
453
+ EOL
454
+
455
+ vim_update_bundles
456
+ assert_test ?f, "#{tmpdir}/output"
457
+ assert_equal "hiya\n", File.read("#{tmpdir}/output")
458
+ end
459
+ end
460
+
461
+
462
+ def test_failing_bundle_command
463
+ prepare_test do |tmpdir|
464
+ vim_update_bundles '#{@starter_urls}'
465
+ check_tree tmpdir
466
+
467
+ create_mock_repo "#{tmpdir}/repo"
468
+ write_file tmpdir, ".vimrc", <<-EOL
469
+ " Bundle: #{tmpdir}/repo
470
+ " Bundle-Command: oh-no-this-command-does-not-exist
471
+ EOL
472
+
473
+ vim_update_bundles__expect_error
474
+ assert $?.exitstatus == 47, "the bundle-command should have produced 47, not #{$?.exitstatus}"
475
+ end
476
+ end
477
+
478
+
479
+ def test_static_bundle
480
+ prepare_test do |tmpdir|
481
+ vim_update_bundles
482
+ Dir.mkdir "#{tmpdir}/.vim/bundle/foreign"
483
+ Dir.mkdir "#{tmpdir}/.vim/bundle/static"
484
+ write_file tmpdir, ".vimrc", '" Static: static'
485
+
486
+ vim_update_bundles
487
+ assert_test ?d, "#{tmpdir}/.vim/bundle/static"
488
+ refute_test ?d, "#{tmpdir}/.vim/bundle/foreign"
489
+ assert_test ?d, "#{tmpdir}/.vim/Trashed-Bundles/foreign-01"
490
+ end
491
+ end
492
+
493
+
494
+ def test_no_updates_run
495
+ # Makes sure we still add and delete even when --no-updates prevents updates
496
+ prepare_test do |tmpdir|
497
+ create_mock_repo "#{tmpdir}/plugin1"
498
+ write_file tmpdir, ".vimrc", "\" Bundle: #{tmpdir}/plugin1"
499
+ vim_update_bundles '--no-updates'
500
+
501
+ # make sure plugin1 was added even though --no-updates was turned on
502
+ assert_test ?f, "#{tmpdir}/.vim/bundle/plugin1/first"
503
+ refute_test ?f, "#{tmpdir}/.vim/bundle/plugin1/second"
504
+
505
+ update_mock_repo "#{tmpdir}/plugin1", "second"
506
+ create_mock_repo "#{tmpdir}/plugin2"
507
+ write_file tmpdir, ".vimrc", "\" Bundle: #{tmpdir}/plugin1\n\" Bundle: #{tmpdir}/plugin2"
508
+ vim_update_bundles '-n' # test single-letter arg
509
+
510
+ # make sure plugin1 hasn't been updated but plugin2 has been added
511
+ assert_test ?f, "#{tmpdir}/.vim/bundle/plugin1/first"
512
+ refute_test ?f, "#{tmpdir}/.vim/bundle/plugin1/second"
513
+ assert_test ?f, "#{tmpdir}/.vim/bundle/plugin2/first"
514
+
515
+ # Remove the repository.
516
+ write_file tmpdir, ".vimrc", "\" Bundle: #{tmpdir}/plugin1"
517
+ vim_update_bundles '--no-updates'
518
+
519
+ # make sure plugin1 hasn't been updated but plugin2 has been deleted
520
+ assert_test ?f, "#{tmpdir}/.vim/bundle/plugin1/first"
521
+ refute_test ?f, "#{tmpdir}/.vim/bundle/plugin1/second"
522
+ refute_test ?f, "#{tmpdir}/.vim/bundle/plugin2/first"
523
+ end
524
+ end
525
+
526
+
527
+ def test_create_dotfile_environment
528
+ prepare_test do |tmpdir|
529
+ Dir.mkdir "#{tmpdir}/.dotfiles"
530
+ vim_update_bundles
531
+ check_tree tmpdir, '.dotfiles/vim', '.dotfiles/vimrc'
532
+ end
533
+ end
534
+
535
+
536
+ def test_create_dotfile_environment_with_vimrc_in_vim
537
+ prepare_test do |tmpdir|
538
+ Dir.mkdir "#{tmpdir}/zedots"
539
+ Dir.mkdir "#{tmpdir}/zedots/vim"
540
+ write_file tmpdir, "zedots/vim/vimrc", '" ignored'
541
+
542
+ vim_update_bundles "--dotfiles_path='#{tmpdir}/zedots'"
543
+ check_tree tmpdir, 'zedots/vim', 'zedots/vim/vimrc'
544
+ refute_test ?e, "#{tmpdir}/.dotfiles/.vimrc"
545
+ refute_test ?e, "#{tmpdir}/zedots/.vimrc"
546
+ end
547
+ end
548
+
549
+
550
+ def test_create_custom_vimrc_environment
551
+ prepare_test do |tmpdir|
552
+ Dir.mkdir "#{tmpdir}/mydots"
553
+ vim_update_bundles "vimrc_path='#{tmpdir}/mydots/vim rc'"
554
+ check_tree tmpdir, '.vim', 'mydots/vim rc'
555
+ end
556
+ end
557
+
558
+
559
+ def test_create_custom_conffile_environment
560
+ prepare_test do |tmpdir|
561
+ Dir.mkdir "#{tmpdir}/parent"
562
+ Dir.mkdir "#{tmpdir}/parent/child"
563
+ ENV['PARENT'] = 'parent'
564
+ File.open("#{tmpdir}/.vim-update-bundles.conf", 'w') { |f|
565
+ f.write "vimrc_path = #{tmpdir}/$PARENT/child/vv zz"
566
+ }
567
+ vim_update_bundles
568
+ check_tree tmpdir, '.vim', 'parent/child/vv zz'
569
+ end
570
+ end
571
+
572
+
573
+ def test_interpolation_works
574
+ prepare_test do |tmpdir|
575
+ vim_update_bundles "--vimdir_path='$HOME/vimmy' --vimrc_path='$vimdir_path/vimmyrc'"
576
+ check_tree tmpdir, 'vimmy', 'vimmy/vimmyrc'
577
+ end
578
+ end
579
+
580
+
581
+ def test_unknown_interpolation_fails
582
+ prepare_test do |tmpdir|
583
+ vim_update_bundles__expect_error "--verbose='$unknown'"
584
+ assert $?.exitstatus == 1, "the bundle-command should have produced 1, not #{$?.exitstatus}"
585
+ # Make sure it didn't create any files.
586
+ refute_test ?e, "#{tmpdir}/.vim"
587
+ refute_test ?e, "#{tmpdir}/.vimrc"
588
+ end
589
+ end
590
+
591
+
592
+ def ensure_marker log, marker_string
593
+ # ensure marker is still in file but not at the top
594
+ assert_match /#{marker_string}/, log
595
+ assert_equal "*bundle-log.txt*", log[0..15]
596
+ # also ensure the header only appears once
597
+ assert_no_match /\*bundle-log\.txt\*/, log[15..-1]
598
+ end
599
+
600
+
601
+ def test_bundles_txt_and_logfile
602
+ # ensures .vim/doc/bundles.txt and bundle-log.txt are filled in
603
+ prepare_test do |tmpdir|
604
+
605
+ # test logfiles with an empty .vimrc
606
+ Dir.mkdir "#{tmpdir}/.vim"
607
+ write_file tmpdir, ".vimrc", ''
608
+ vim_update_bundles
609
+
610
+ assert_test ?f, "#{tmpdir}/.vim/doc/bundles.txt"
611
+ assert_test ?f, "#{tmpdir}/.vim/doc/bundle-log.txt"
612
+
613
+ # Make a repository with a tagged commit and commits after that.
614
+ create_mock_repo "#{tmpdir}/repo"
615
+ update_mock_repo_tagged "#{tmpdir}/repo", 'second', '0.2'
616
+ write_file tmpdir, ".vimrc", "\" Bundle: #{tmpdir}/repo"
617
+ vim_update_bundles
618
+
619
+ list = File.read "#{tmpdir}/.vim/doc/bundles.txt"
620
+ log = File.read "#{tmpdir}/.vim/doc/bundle-log.txt"
621
+
622
+ assert_match /\|repo\|\s*0\.2/, list
623
+ assert_no_match /\|repo\|\s*0\.3/, list # duh
624
+ assert_match /Add\s*\|repo\|\s*0\.2/, log
625
+
626
+ marker_string = "A marker to ensure the logfile is not changed"
627
+ File.open("#{tmpdir}/.vim/doc/bundle-log.txt", "a") { |f| f.puts marker_string }
628
+
629
+ # Pull upstream changes.
630
+ update_mock_repo_tagged "#{tmpdir}/repo", 'third', '0.3'
631
+ vim_update_bundles
632
+
633
+ list = File.read "#{tmpdir}/.vim/doc/bundles.txt"
634
+ log = File.read "#{tmpdir}/.vim/doc/bundle-log.txt"
635
+
636
+ assert_no_match /\|repo\|\s*0\.2/, list
637
+ assert_match /\|repo\|\s*0\.3/, list
638
+ assert_match /Add\s*\|repo\|\s*0\.2/, log
639
+ assert_match /up\s*\|repo\|\s*0\.2\s*->\s*0\.3/, log
640
+ ensure_marker log, marker_string
641
+
642
+ # won't bother changing the remote since vim-update-bundles handles it
643
+ # as a delete followed by an add. might be worth testing though.
644
+
645
+ write_file tmpdir, ".vimrc", ''
646
+ vim_update_bundles
647
+
648
+ list = File.read "#{tmpdir}/.vim/doc/bundles.txt"
649
+ log = File.read "#{tmpdir}/.vim/doc/bundle-log.txt"
650
+
651
+ assert_no_match /\|repo\|\s*0\.2/, list
652
+ assert_no_match /\|repo\|\s*0\.3/, list
653
+ assert_match /Add\s*\|repo\|\s*0\.2/, log
654
+ assert_match /up\s*\|repo\|\s*0\.2\s*->\s*0\.3/, log
655
+ assert_match /Del\s*\|repo\|\s*0\.3/, log
656
+ ensure_marker log, marker_string
657
+ end
658
+ end
659
+ end
660
+