vim-flavor 1.0.2 → 1.0.3

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.
data/features/.nav CHANGED
@@ -9,7 +9,7 @@
9
9
  - command_line:
10
10
  - flavorfile:
11
11
  - version_lock.feature
12
- - caching.feature
12
+ - caching:
13
13
  - resolve_dependencies.feature
14
14
  - testing_vim_plugins:
15
15
  - typical_usage.feature
@@ -0,0 +1,13 @@
1
+ It would be better to install/upgrade Vim plugins as fast as possible.
2
+ Since `vim-flavor` manages Vim plugins with Git, it has to clone each plugin's
3
+ repository at first, and it also has to fetch changes from time to time.
4
+ But network access is typically time-consuming.
5
+
6
+ Therefore `vim-flavor` caches fetched stuffs. The cache is stored in
7
+ `~/.vim-flavor`. When `vim-flavor` needs to deploy plugins, it avoids network
8
+ access as much as possible.
9
+
10
+
11
+
12
+
13
+ <!-- vim: set expandtab shiftwidth=4 softtabstop=4 textwidth=78 : -->
@@ -1,4 +1,4 @@
1
- Feature: Caching
1
+ Feature: Basics
2
2
  In order to finish deployment as fast as possible,
3
3
  as a lazy Vim user,
4
4
  I want to cache repositories of plugins which are installed before.
@@ -0,0 +1,63 @@
1
+ Feature: Deployment
2
+ In order to finish deployment as fast as possible,
3
+ as a lazy Vim user,
4
+ I want to skip plugins which are already deployed with proper versions.
5
+
6
+ Background:
7
+ Given a repository "foo" with versions "1.0 1.1 1.2"
8
+ And a flavorfile with:
9
+ """ruby
10
+ flavor '$foo_uri', '~> 1.0'
11
+ """
12
+ Scenario: Deploy plugins which are not deployed yet
13
+ Given a flavor "$foo_uri" is not deployed to "$home/.vim"
14
+ When I run `vim-flavor install`
15
+ Then it should pass with template:
16
+ """
17
+ Checking versions...
18
+ Use $foo_uri ... 1.2
19
+ Deploying plugins...
20
+ $foo_uri 1.2 ... done
21
+ Completed.
22
+ """
23
+ And a flavor "$foo_uri" version "1.2" is deployed to "$home/.vim"
24
+
25
+ Scenario: Skip plugins which are already deployed with proper versions
26
+ Given I run `vim-flavor install`
27
+ And a flavor "$foo_uri" version "1.2" is deployed to "$home/.vim"
28
+ When I create a file named "abc" in "$foo_uri" deployed to "$home/.vim"
29
+ And I run `vim-flavor install`
30
+ Then it should pass with template:
31
+ """
32
+ Checking versions...
33
+ Use $foo_uri ... 1.2
34
+ Deploying plugins...
35
+ $foo_uri 1.2 ... skipped (already deployed)
36
+ Completed.
37
+ """
38
+ And a flavor "$foo_uri" version "1.2" is deployed to "$home/.vim"
39
+ And a file named "abc" should exist in "$foo_uri" deployed to "$home/.vim"
40
+
41
+ Scenario: Redeploy plugins if their versions differ from deployed ones
42
+ Given a lockfile with:
43
+ """
44
+ $foo_uri (1.0)
45
+ """
46
+ And I run `vim-flavor install`
47
+ And a flavor "$foo_uri" version "1.0" is deployed to "$home/.vim"
48
+ When I create a file named "abc" in "$foo_uri" deployed to "$home/.vim"
49
+ And I edit the lockfile as:
50
+ """
51
+ $foo_uri (1.1)
52
+ """
53
+ And I run `vim-flavor install`
54
+ Then it should pass with template:
55
+ """
56
+ Checking versions...
57
+ Use $foo_uri ... 1.1
58
+ Deploying plugins...
59
+ $foo_uri 1.1 ... done
60
+ Completed.
61
+ """
62
+ And a flavor "$foo_uri" version "1.1" is deployed to "$home/.vim"
63
+ And a file named "abc" should not exist in "$foo_uri" deployed to "$home/.vim"
@@ -0,0 +1,32 @@
1
+ Feature: Edge cases
2
+ In order to use the same configuration across multiple environments,
3
+ as a lazy Vim user,
4
+ I want to properly update cached repositories of plugins.
5
+
6
+ Scenario: Using `vim-flavor` on multiple environments
7
+ Given a repository "foo" with versions "1.0 1.1 1.2"
8
+ And a flavorfile with:
9
+ """ruby
10
+ flavor '$foo_uri', '~> 1.0'
11
+ """
12
+ And I run `vim-flavor install`
13
+ And a lockfile is created with:
14
+ """
15
+ $foo_uri (1.2)
16
+ """
17
+ And a flavor "$foo_uri" version "1.2" is deployed to "$home/.vim"
18
+ And "foo" version "1.3" is released
19
+ And "foo" version "1.4" is released
20
+ And I copy a new lockfile from another machine with:
21
+ """
22
+ $foo_uri (1.3)
23
+ """
24
+ And "$foo_uri" version "1.3" is not cached
25
+ When I run `vim-flavor install`
26
+ Then it should pass
27
+ And the lockfile is updated with:
28
+ """
29
+ $foo_uri (1.3)
30
+ """
31
+ And a flavor "$foo_uri" version "1.3" is deployed to "$home/.vim"
32
+ And "$foo_uri" version "1.3" is cached
@@ -19,6 +19,23 @@ Given /^a (?:(?:GitHub|local) )?repository "(.+)" with versions "(.+)"$/ do |bas
19
19
  END
20
20
  end
21
21
 
22
+ Given /^"(.+)" version "(.+)" is released$/ do |basename, version|
23
+ repository_path = make_repo_path(basename)
24
+ doc_name = basename.split('/').last.sub(/^vim-/, '')
25
+ sh <<-"END"
26
+ {
27
+ cd '#{repository_path}' &&
28
+ for v in #{version}
29
+ do
30
+ echo "*#{doc_name}* $v" >'doc/#{doc_name}.txt'
31
+ git add doc
32
+ git commit -m "Version $v"
33
+ git tag -m "Version $v" "$v"
34
+ done
35
+ } >/dev/null
36
+ END
37
+ end
38
+
22
39
  Given /^a repository "(.+)" from offline cache$/ do |repo_name|
23
40
  repository_path = make_repo_path(repo_name).sub(expand('$tmp/'), '')
24
41
  sh <<-"END"
@@ -34,6 +51,15 @@ Given /^I disable network to the original repository of "(.+)"$/ do |basename|
34
51
  }
35
52
  end
36
53
 
54
+ When /^I create a file named "(.+?)" in "(.+?)" deployed to "(.+?)"$/ do |file_name, v_repo_name, v_vimfiles_path|
55
+ flavor_path = make_flavor_path(expand(v_vimfiles_path), expand(v_repo_name))
56
+ steps %Q{
57
+ When I write to "#{flavor_path}/#{file_name}" with:
58
+ """
59
+ """
60
+ }
61
+ end
62
+
37
63
  Then /^a flavor "(.+)" version "(.+)" is deployed to "(.+)"$/ do |v_repo_name, version, v_vimfiles_path|
38
64
  flavor_path = make_flavor_path(expand(v_vimfiles_path), expand(v_repo_name))
39
65
  basename = expand(v_repo_name).split('/').last.sub(/^vim-/, '')
@@ -52,3 +78,20 @@ Then /^a flavor "(.+)" is not deployed to "(.+)"$/ do |v_repo_name, v_vimfiles_p
52
78
  Then a directory named "#{flavor_path}" should not exist
53
79
  }
54
80
  end
81
+
82
+ Then /^"(.+)" version "(.+)" is (?:(not) )?cached$/ do |v_repo_name, version, p|
83
+ d = make_cached_repo_path(expand(v_repo_name), expand('$home').to_stash_path)
84
+ (system <<-"END").should == (p != 'not')
85
+ {
86
+ cd '#{d}' &&
87
+ git rev-list --quiet '#{version}'
88
+ } >/dev/null 2>&1
89
+ END
90
+ end
91
+
92
+ Then /^a file named "(.+?)" (should(?: not)?) exist in "(.+?)" deployed to "(.+?)"$/ do |file_name, should, v_repo_name, v_vimfiles_path|
93
+ flavor_path = make_flavor_path(expand(v_vimfiles_path), expand(v_repo_name))
94
+ steps %Q{
95
+ Then a file named "#{flavor_path}/#{file_name}" #{should} exist
96
+ }
97
+ end
@@ -7,12 +7,30 @@ Given 'a lockfile with:' do |content|
7
7
  }
8
8
  end
9
9
 
10
+ Given 'I copy a new lockfile from another machine with:' do |content|
11
+ steps %Q{
12
+ Given a lockfile with:
13
+ """
14
+ #{content}
15
+ """
16
+ }
17
+ end
18
+
10
19
  Given 'I delete the lockfile' do
11
20
  steps %Q{
12
21
  Given I remove the file "#{'.'.to_lockfile_path}"
13
22
  }
14
23
  end
15
24
 
25
+ When 'I edit the lockfile as:' do |content|
26
+ steps %Q{
27
+ Given a lockfile with:
28
+ """
29
+ #{content}
30
+ """
31
+ }
32
+ end
33
+
16
34
  Then /^(?:a|the) lockfile is (?:created|updated) with:$/ do |content|
17
35
  # For some reason, Cucumber drops the last newline from every docstring...
18
36
  steps %Q{
@@ -12,6 +12,10 @@ class FakeUserEnvironment
12
12
  }
13
13
  end
14
14
 
15
+ def make_cached_repo_path(repo_name, stash_path)
16
+ "#{stash_path}/repos/#{repo_name.zap}"
17
+ end
18
+
15
19
  def make_flavor_path(vimfiles_path, repo_name)
16
20
  "#{vimfiles_path.to_flavors_path}/#{repo_name.zap}"
17
21
  end
@@ -54,6 +54,12 @@ module Vim
54
54
  nf.clone() unless already_cached
55
55
 
56
56
  if mode == :install and lf and nf.satisfied_with?(lf)
57
+ if not nf.cached_version?(lf.locked_version)
58
+ nf.fetch()
59
+ if not nf.cached_version?(lf.locked_version)
60
+ raise RuntimeError, "#{nf.repo_name} is locked to #{lf.locked_version}, but no such version exists"
61
+ end
62
+ end
57
63
  nf.use_specific_version(lf.locked_version)
58
64
  else
59
65
  nf.fetch() if already_cached
@@ -70,21 +76,49 @@ module Vim
70
76
  trace "Deploying plugins...\n"
71
77
 
72
78
  a_flavors_path = File.absolute_path(flavors_path)
79
+ deployment_memo = LockFile.load_or_new(a_flavors_path.to_lockfile_path)
73
80
 
81
+ # To uninstall flavors which were deployed by vim-flavor 1.0.2 or
82
+ # older, the whole deployed flavors have to be removed. Because
83
+ # deployment_memo is recorded since 1.0.3.
74
84
  FileUtils.rm_rf(
75
85
  [a_flavors_path],
76
86
  :secure => true
77
- )
87
+ ) if deployment_memo.flavors.empty?
78
88
 
79
89
  create_vim_script_for_bootstrap(a_flavors_path)
80
90
 
81
91
  flavors.
82
92
  before_each {|f| trace " #{f.repo_name} #{f.locked_version} ..."}.
83
- after_each {|f| trace " done\n"}.
84
93
  on_failure {trace " failed\n"}.
85
94
  each do |f|
86
- f.deploy(a_flavors_path)
95
+ df = deployment_memo.flavor_table[f.repo_name]
96
+ deployed_version = (df and df.locked_version)
97
+ if f.locked_version == deployed_version
98
+ trace " skipped (already deployed)\n"
99
+ else
100
+ FileUtils.rm_rf(
101
+ [f.make_deployment_path(a_flavors_path)],
102
+ :secure => true
103
+ )
104
+ f.deploy(a_flavors_path)
105
+ trace " done\n"
106
+ end
87
107
  end
108
+
109
+ deployment_memo.flavors.each do |df|
110
+ if flavors.all? {|f| f.repo_name != df.repo_name}
111
+ trace " #{df.repo_name} ..."
112
+ FileUtils.rm_rf(
113
+ [df.make_deployment_path(a_flavors_path)],
114
+ :secure => true
115
+ )
116
+ trace " uninstalled\n"
117
+ end
118
+ end
119
+
120
+ deployment_memo.flavors = flavors
121
+ deployment_memo.save()
88
122
  end
89
123
 
90
124
  def create_vim_script_for_bootstrap(flavors_path)
@@ -21,11 +21,24 @@ module Vim
21
21
  Dir.exists?(cached_repo_path)
22
22
  end
23
23
 
24
+ def cached_version?(version)
25
+ system <<-"END"
26
+ {
27
+ cd '#{cached_repo_path}' &&
28
+ git rev-list --quiet '#{version}'
29
+ } >/dev/null 2>&1
30
+ END
31
+ end
32
+
24
33
  def cached_repo_path
25
34
  @cached_repo_path ||=
26
35
  "#{ENV['HOME'].to_stash_path}/repos/#{@repo_name.zap}"
27
36
  end
28
37
 
38
+ def make_deployment_path(flavors_path)
39
+ "#{flavors_path}/#{repo_name.zap}"
40
+ end
41
+
29
42
  def self.github_repo_uri(user, repo)
30
43
  p = (ENV['VIM_FLAVOR_GITHUB_URI_PREFIX'] ||= 'git://github.com/')
31
44
  s = (ENV['VIM_FLAVOR_GITHUB_URI_SUFFIX'] ||= '.git')
@@ -66,7 +79,7 @@ module Vim
66
79
  end
67
80
 
68
81
  def deploy(flavors_path)
69
- deployment_path = "#{flavors_path}/#{repo_name.zap}"
82
+ deployment_path = make_deployment_path(flavors_path)
70
83
  sh %Q[
71
84
  {
72
85
  cd '#{cached_repo_path}' &&
@@ -19,6 +19,10 @@ module Vim
19
19
  flavor_table.values.sort_by {|f| f.repo_name}
20
20
  end
21
21
 
22
+ def flavors=(fs)
23
+ flavor_table.replace(Hash[fs.map {|f| [f.repo_name, f]}])
24
+ end
25
+
22
26
  def load()
23
27
  s = File.open(@path, 'r') {|io| io.read()}
24
28
  @flavor_table =
@@ -1,5 +1,5 @@
1
1
  module Vim
2
2
  module Flavor
3
- VERSION = '1.0.2'
3
+ VERSION = '1.0.3'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vim-flavor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-06 00:00:00.000000000 Z
12
+ date: 2012-12-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: parslet
@@ -110,7 +110,10 @@ files:
110
110
  - bin/vim-flavor
111
111
  - features/.nav
112
112
  - features/README.md
113
- - features/caching.feature
113
+ - features/caching/README.md
114
+ - features/caching/basics.feature
115
+ - features/caching/deployment.feature
116
+ - features/caching/edge_cases.feature
114
117
  - features/command_line/README.md
115
118
  - features/command_line/progress_messages.feature
116
119
  - features/flavorfile/README.md
@@ -188,7 +191,10 @@ specification_version: 3
188
191
  summary: A tool to manage your favorite Vim plugins
189
192
  test_files:
190
193
  - features/README.md
191
- - features/caching.feature
194
+ - features/caching/README.md
195
+ - features/caching/basics.feature
196
+ - features/caching/deployment.feature
197
+ - features/caching/edge_cases.feature
192
198
  - features/command_line/README.md
193
199
  - features/command_line/progress_messages.feature
194
200
  - features/flavorfile/README.md