knife-essentials 1.1.1 → 1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,4 @@
1
1
  require 'chef_fs/knife'
2
- require 'chef_fs/file_system'
3
2
 
4
3
  class Chef
5
4
  class Knife
@@ -8,7 +7,9 @@ class Chef
8
7
  ChefFS = ::ChefFS
9
8
  banner "knife delete [PATTERN1 ... PATTERNn]"
10
9
 
11
- common_options
10
+ deps do
11
+ require 'chef_fs/file_system'
12
+ end
12
13
 
13
14
  option :recurse,
14
15
  :short => '-r',
@@ -16,16 +17,16 @@ class Chef
16
17
  :boolean => true,
17
18
  :default => false,
18
19
  :description => "Delete directories recursively."
19
- option :remote_only,
20
- :long => '--remote-only',
20
+ option :both,
21
+ :long => '--both',
21
22
  :boolean => true,
22
23
  :default => false,
23
- :description => "Only delete the remote copy (leave the local copy)."
24
- option :local_only,
25
- :long => '--local-only',
24
+ :description => "Delete both the local and remote copies."
25
+ option :local,
26
+ :long => '--local',
26
27
  :boolean => true,
27
28
  :default => false,
28
- :description => "Only delete the local copy (leave the remote copy)."
29
+ :description => "Delete the local copy (leave the remote copy)."
29
30
 
30
31
  def run
31
32
  if name_args.length == 0
@@ -36,26 +37,26 @@ class Chef
36
37
 
37
38
  # Get the matches (recursively)
38
39
  error = false
39
- if config[:remote_only]
40
+ if config[:local]
40
41
  pattern_args.each do |pattern|
41
- ChefFS::FileSystem.list(chef_fs, pattern).each do |result|
42
+ ChefFS::FileSystem.list(local_fs, pattern).each do |result|
42
43
  if delete_result(result)
43
44
  error = true
44
45
  end
45
46
  end
46
47
  end
47
- elsif config[:local_only]
48
+ elsif config[:both]
48
49
  pattern_args.each do |pattern|
49
- ChefFS::FileSystem.list(local_fs, pattern).each do |result|
50
- if delete_result(result)
50
+ ChefFS::FileSystem.list_pairs(pattern, chef_fs, local_fs).each do |chef_result, local_result|
51
+ if delete_result(chef_result, local_result)
51
52
  error = true
52
53
  end
53
54
  end
54
55
  end
55
- else
56
+ else # Remote only
56
57
  pattern_args.each do |pattern|
57
- ChefFS::FileSystem.list_pairs(pattern, chef_fs, local_fs).each do |chef_result, local_result|
58
- if delete_result(chef_result, local_result)
58
+ ChefFS::FileSystem.list(chef_fs, pattern).each do |result|
59
+ if delete_result(result)
59
60
  error = true
60
61
  end
61
62
  end
@@ -1,6 +1,4 @@
1
1
  require 'chef_fs/knife'
2
- require 'chef_fs/file_system'
3
- require 'chef/run_list'
4
2
 
5
3
  class Chef
6
4
  class Knife
@@ -9,7 +7,10 @@ class Chef
9
7
  ChefFS = ::ChefFS
10
8
  banner "knife deps PATTERN1 [PATTERNn]"
11
9
 
12
- common_options
10
+ deps do
11
+ require 'chef_fs/file_system'
12
+ require 'chef/run_list'
13
+ end
13
14
 
14
15
  option :recurse,
15
16
  :long => '--[no-]recurse',
@@ -1,5 +1,4 @@
1
1
  require 'chef_fs/knife'
2
- require 'chef_fs/command_line'
3
2
 
4
3
  class Chef
5
4
  class Knife
@@ -8,7 +7,9 @@ class Chef
8
7
  ChefFS = ::ChefFS
9
8
  banner "knife diff PATTERNS"
10
9
 
11
- common_options
10
+ deps do
11
+ require 'chef_fs/command_line'
12
+ end
12
13
 
13
14
  option :recurse,
14
15
  :long => '--[no-]recurse',
@@ -1,5 +1,4 @@
1
1
  require 'chef_fs/knife'
2
- require 'chef_fs/command_line'
3
2
 
4
3
  class Chef
5
4
  class Knife
@@ -8,7 +7,9 @@ class Chef
8
7
  ChefFS = ::ChefFS
9
8
  banner "knife download PATTERNS"
10
9
 
11
- common_options
10
+ deps do
11
+ require 'chef_fs/command_line'
12
+ end
12
13
 
13
14
  option :recurse,
14
15
  :long => '--[no-]recurse',
@@ -1,6 +1,4 @@
1
1
  require 'chef_fs/knife'
2
- require 'chef_fs/file_system'
3
- require 'chef_fs/file_system/not_found_error'
4
2
 
5
3
  class Chef
6
4
  class Knife
@@ -9,7 +7,10 @@ class Chef
9
7
  ChefFS = ::ChefFS
10
8
  banner "knife edit [PATTERN1 ... PATTERNn]"
11
9
 
12
- common_options
10
+ deps do
11
+ require 'chef_fs/file_system'
12
+ require 'chef_fs/file_system/not_found_error'
13
+ end
13
14
 
14
15
  option :local,
15
16
  :long => '--local',
@@ -1,6 +1,4 @@
1
1
  require 'chef_fs/knife'
2
- require 'chef_fs/file_system'
3
- require 'highline'
4
2
 
5
3
  class Chef
6
4
  class Knife
@@ -9,7 +7,10 @@ class Chef
9
7
  ChefFS = ::ChefFS
10
8
  banner "knife list [-dfR1p] [PATTERN1 ... PATTERNn]"
11
9
 
12
- common_options
10
+ deps do
11
+ require 'chef_fs/file_system'
12
+ require 'highline'
13
+ end
13
14
 
14
15
  option :recursive,
15
16
  :short => '-R',
@@ -1,6 +1,4 @@
1
- require 'json'
2
- require 'chef_fs/data_handler/data_handler_base'
3
- require 'chef_fs/raw_request'
1
+ require 'chef/knife'
4
2
 
5
3
  class Chef
6
4
  class Knife
@@ -9,6 +7,12 @@ class Chef
9
7
  ChefFS = ::ChefFS
10
8
  banner "knife raw REQUEST_PATH"
11
9
 
10
+ deps do
11
+ require 'json'
12
+ require 'chef_fs/data_handler/data_handler_base'
13
+ require 'chef_fs/raw_request'
14
+ end
15
+
12
16
  option :method,
13
17
  :long => '--method METHOD',
14
18
  :short => '-m METHOD',
@@ -1,14 +1,4 @@
1
1
  require 'chef_fs/knife'
2
- require 'chef_zero/server'
3
- require 'chef_zero/data_store/memory_store'
4
-
5
- # For ChefFSStore
6
- require 'chef_fs/file_pattern'
7
- require 'chef_fs/file_system'
8
- require 'chef_fs/file_system/not_found_error'
9
- require 'chef_fs/file_system/memory_root'
10
- require 'chef_zero/data_store/data_already_exists_error'
11
- require 'chef_zero/data_store/data_not_found_error'
12
2
 
13
3
  class Chef
14
4
  class Knife
@@ -17,7 +7,26 @@ class Chef
17
7
  ChefFS = ::ChefFS
18
8
  banner "knife show [PATTERN1 ... PATTERNn]"
19
9
 
20
- common_options
10
+ deps do
11
+ begin
12
+ require 'chef_zero/server'
13
+ rescue LoadError
14
+ STDERR.puts <<EOM
15
+ ERROR: chef-zero must be installed to run "knife serve"! To install:
16
+
17
+ gem install chef-zero
18
+
19
+ EOM
20
+ exit(1)
21
+ end
22
+ require 'chef_zero/data_store/memory_store'
23
+ require 'chef_fs/file_pattern'
24
+ require 'chef_fs/file_system'
25
+ require 'chef_fs/file_system/not_found_error'
26
+ require 'chef_fs/file_system/memory_root'
27
+ require 'chef_zero/data_store/data_already_exists_error'
28
+ require 'chef_zero/data_store/data_not_found_error'
29
+ end
21
30
 
22
31
  option :remote,
23
32
  :long => '--remote',
@@ -1,6 +1,4 @@
1
1
  require 'chef_fs/knife'
2
- require 'chef_fs/file_system'
3
- require 'chef_fs/file_system/not_found_error'
4
2
 
5
3
  class Chef
6
4
  class Knife
@@ -9,7 +7,10 @@ class Chef
9
7
  ChefFS = ::ChefFS
10
8
  banner "knife show [PATTERN1 ... PATTERNn]"
11
9
 
12
- common_options
10
+ deps do
11
+ require 'chef_fs/file_system'
12
+ require 'chef_fs/file_system/not_found_error'
13
+ end
13
14
 
14
15
  option :local,
15
16
  :long => '--local',
@@ -1,5 +1,4 @@
1
1
  require 'chef_fs/knife'
2
- require 'chef_fs/command_line'
3
2
 
4
3
  class Chef
5
4
  class Knife
@@ -8,7 +7,9 @@ class Chef
8
7
  ChefFS = ::ChefFS
9
8
  banner "knife upload PATTERNS"
10
9
 
11
- common_options
10
+ deps do
11
+ require 'chef_fs/command_line'
12
+ end
12
13
 
13
14
  option :recurse,
14
15
  :long => '--[no-]recurse',
@@ -26,7 +27,13 @@ class Chef
26
27
  :long => '--[no-]force',
27
28
  :boolean => true,
28
29
  :default => false,
29
- :description => "Force upload of files even if they match (quicker and harmless, but doesn't print out what it changed)"
30
+ :description => "Force upload of files even if they match (quicker for many files). Will overwrite frozen cookbooks."
31
+
32
+ option :freeze,
33
+ :long => '--[no-]freeze',
34
+ :boolean => true,
35
+ :default => false,
36
+ :description => "Freeze cookbooks that get uploaded."
30
37
 
31
38
  option :dry_run,
32
39
  :long => '--dry-run',
@@ -1,6 +1,4 @@
1
1
  require 'chef_fs/knife'
2
- require 'chef_fs/file_system'
3
- require 'chef_fs/file_system/not_found_error'
4
2
 
5
3
  class Chef
6
4
  class Knife
@@ -9,7 +7,10 @@ class Chef
9
7
  ChefFS = ::ChefFS
10
8
  banner "knife xargs [COMMAND]"
11
9
 
12
- common_options
10
+ deps do
11
+ require 'chef_fs/file_system'
12
+ require 'chef_fs/file_system/not_found_error'
13
+ end
13
14
 
14
15
  # TODO modify to remote-only / local-only pattern (more like delete)
15
16
  option :local,
@@ -340,7 +340,7 @@ module ChefFS
340
340
  if options[:dry_run]
341
341
  ui.output "Would update #{dest_path}" if ui
342
342
  else
343
- dest_entry.copy_from(src_entry)
343
+ dest_entry.copy_from(src_entry, options)
344
344
  ui.output "Updated #{dest_path}" if ui
345
345
  end
346
346
  end
@@ -0,0 +1,29 @@
1
+ #
2
+ # Author:: John Keiser (<jkeiser@opscode.com>)
3
+ # Copyright:: Copyright (c) 2012 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'chef_fs/file_system/operation_failed_error'
20
+
21
+ module ChefFS
22
+ module FileSystem
23
+ class AlreadyExistsError < OperationFailedError
24
+ def initialize(operation, entry, cause = nil)
25
+ super(operation, entry, cause)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -162,8 +162,8 @@ module ChefFS
162
162
  [ are_same, nil, nil ]
163
163
  end
164
164
 
165
- def copy_from(other)
166
- parent.upload_cookbook_from(other)
165
+ def copy_from(other, options = {})
166
+ parent.upload_cookbook_from(other, options)
167
167
  end
168
168
 
169
169
  def rest
@@ -0,0 +1,29 @@
1
+ #
2
+ # Author:: John Keiser (<jkeiser@opscode.com>)
3
+ # Copyright:: Copyright (c) 2012 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'chef_fs/file_system/already_exists_error'
20
+
21
+ module ChefFS
22
+ module FileSystem
23
+ class CookbookFrozenError < AlreadyExistsError
24
+ def initialize(operation, entry, cause = nil)
25
+ super(operation, entry, cause)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -19,6 +19,8 @@
19
19
  require 'chef_fs/file_system/rest_list_dir'
20
20
  require 'chef_fs/file_system/cookbook_dir'
21
21
  require 'chef_fs/raw_request'
22
+ require 'chef_fs/file_system/operation_failed_error'
23
+ require 'chef_fs/file_system/cookbook_frozen_error'
22
24
 
23
25
  require 'tmpdir'
24
26
 
@@ -58,20 +60,18 @@ module ChefFS
58
60
  end
59
61
  end
60
62
 
61
- def create_child_from(other)
62
- upload_cookbook_from(other)
63
+ def create_child_from(other, options = {})
64
+ upload_cookbook_from(other, options)
63
65
  end
64
66
 
65
- def upload_cookbook_from(other)
66
- Chef::Config[:versioned_cookbooks] ? upload_versioned_cookbook(other) : upload_unversioned_cookbook(other)
67
+ def upload_cookbook_from(other, options = {})
68
+ Chef::Config[:versioned_cookbooks] ? upload_versioned_cookbook(other, options) : upload_unversioned_cookbook(other, options)
67
69
  rescue Timeout::Error => e
68
70
  raise ChefFS::FileSystem::OperationFailedError.new(:write, self, e), "Timeout writing: #{e}"
69
71
  rescue Net::HTTPServerException => e
70
72
  case e.response.code
71
73
  when "409"
72
- ui.error "Version #{other_cookbook_version.version} of cookbook #{other_cookbook_version.name} is frozen. Use --force to override."
73
- Chef::Log.debug(e)
74
- raise Exceptions::CookbookFrozen
74
+ raise ChefFS::FileSystem::CookbookFrozenError.new(:write, self, e), "Cookbook #{other.name} is frozen"
75
75
  else
76
76
  raise ChefFS::FileSystem::OperationFailedError.new(:write, self, e), "HTTP error writing: #{e}"
77
77
  end
@@ -81,7 +81,7 @@ module ChefFS
81
81
  # Cookbook Version uploader also requires a lot of refactoring
82
82
  # to make this work. So instead, we make a temporary cookbook
83
83
  # symlinking back to real cookbook, and upload the proxy.
84
- def upload_versioned_cookbook(other)
84
+ def upload_versioned_cookbook(other, options)
85
85
  cookbook_name = ChefFS::FileSystem::ChefRepositoryFileSystemEntry.canonical_cookbook_name(other.name)
86
86
 
87
87
  Dir.mktmpdir do |temp_cookbooks_path|
@@ -94,8 +94,11 @@ module ChefFS
94
94
  proxy_loader = Chef::Cookbook::CookbookVersionLoader.new(proxy_cookbook_path, other.parent.chefignore)
95
95
  proxy_loader.load_cookbooks
96
96
 
97
+ cookbook_to_upload = proxy_loader.cookbook_version
98
+ cookbook_to_upload.freeze_version if options[:freeze]
99
+
97
100
  # Instantiate a new uploader based on the proxy loader
98
- uploader = Chef::CookbookUploader.new(proxy_loader.cookbook_version, proxy_cookbook_path, :rest => rest)
101
+ uploader = Chef::CookbookUploader.new(cookbook_to_upload, proxy_cookbook_path, :force => options[:force], :rest => rest)
99
102
 
100
103
  with_actual_cookbooks_dir(temp_cookbooks_path) do
101
104
  upload_cookbook!(uploader)
@@ -103,8 +106,10 @@ module ChefFS
103
106
  end
104
107
  end
105
108
 
106
- def upload_unversioned_cookbook(other)
107
- uploader = Chef::CookbookUploader.new(other.chef_object, other.parent.file_path, :rest => rest)
109
+ def upload_unversioned_cookbook(other, options)
110
+ cookbook_to_upload = other.chef_object
111
+ cookbook_to_upload.freeze_version if options[:freeze]
112
+ uploader = Chef::CookbookUploader.new(cookbook_to_upload, other.parent.file_path, :force => options[:force], :rest => rest)
108
113
 
109
114
  with_actual_cookbooks_dir(other.parent.file_path) do
110
115
  upload_cookbook!(uploader)
@@ -122,7 +127,7 @@ module ChefFS
122
127
  end
123
128
 
124
129
  # Chef 11 changes this API
125
- def upload_cookbook!(uploader)
130
+ def upload_cookbook!(uploader, options = {})
126
131
  if uploader.respond_to?(:upload_cookbook)
127
132
  uploader.upload_cookbook
128
133
  else
@@ -57,7 +57,9 @@ module ChefFS
57
57
  rescue Timeout::Error => e
58
58
  raise ChefFS::FileSystem::OperationFailedError.new(:create_child, self, e), "Timeout creating child '#{name}': #{e}"
59
59
  rescue Net::HTTPServerException => e
60
- if e.response.code != "409"
60
+ if e.response.code == "409"
61
+ raise ChefFS::FileSystem::AlreadyExistsError.new(:create_child, self, e), "Cannot create #{name} under #{path}: already exists"
62
+ else
61
63
  raise ChefFS::FileSystem::OperationFailedError.new(:create_child, self, e), "HTTP error creating child '#{name}': #{e}"
62
64
  end
63
65
  end
@@ -81,6 +81,8 @@ module ChefFS
81
81
  rescue Net::HTTPServerException => e
82
82
  if e.response.code == "404"
83
83
  raise ChefFS::FileSystem::NotFoundError.new(self, e)
84
+ elsif $!.response.code == "409"
85
+ raise ChefFS::FileSystem::AlreadyExistsError.new(:create_child, self, e), "Failure creating '#{name}': #{path}/#{name} already exists"
84
86
  else
85
87
  raise ChefFS::FileSystem::OperationFailedError.new(:create_child, self, e), "Failure creating '#{name}': #{e.message}"
86
88
  end
@@ -16,16 +16,22 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require 'chef_fs/file_system/chef_server_root_dir'
20
- require 'chef_fs/file_system/chef_repository_file_system_root_dir'
21
- require 'chef_fs/file_pattern'
22
- require 'chef_fs/path_utils'
23
- require 'chef_fs/parallelizer'
24
- require 'chef/config'
19
+ require 'chef/knife'
25
20
 
26
21
  module ChefFS
27
22
  class Knife < Chef::Knife
28
- def self.common_options
23
+ # Workaround for CHEF-3932
24
+ def self.deps
25
+ super do
26
+ require 'chef_fs/file_system/chef_server_root_dir'
27
+ require 'chef_fs/file_system/chef_repository_file_system_root_dir'
28
+ require 'chef_fs/file_pattern'
29
+ require 'chef_fs/path_utils'
30
+ require 'chef_fs/parallelizer'
31
+ require 'chef/config'
32
+ yield
33
+ end
34
+
29
35
  option :repo_mode,
30
36
  :long => '--repo-mode MODE',
31
37
  :description => "Specifies the local repository layout. Values: static, everything, hosted_everything. Default: everything/hosted_everything"
@@ -39,6 +45,13 @@ module ChefFS
39
45
  :description => 'Maximum number of simultaneous requests to send (default: 10)'
40
46
  end
41
47
 
48
+ def self.inherited(c)
49
+ super
50
+ # Ensure we always get to do our includes, whether subclass calls deps or not
51
+ c.deps do
52
+ end
53
+ end
54
+
42
55
  def configure_chef
43
56
  super
44
57
  Chef::Config[:repo_mode] = config[:repo_mode] if config[:repo_mode]
@@ -1,3 +1,3 @@
1
1
  module ChefFS
2
- VERSION = "1.1.1"
2
+ VERSION = "1.2"
3
3
  end
@@ -23,8 +23,9 @@ require 'chef_fs/command_line'
23
23
  # Removes the date stamp from the diff and replaces it with ' DATE'
24
24
  # example match: "/dev/null\t2012-10-16 16:15:54.000000000 +0000"
25
25
  # windows match: "--- /dev/null\tTue Oct 16 18:04:34 2012"
26
- def remove_date(diff)
27
- diff.gsub(/([+-]{3}.*)\t.*/, '\1 DATE')
26
+ def remove_os_differences(diff)
27
+ diff = diff.gsub(/([+-]{3}.*)\t.*/, '\1 DATE')
28
+ diff.gsub(/^@@ -\d(,\d)? \+\d(,\d)? @@/, 'CONTEXT_LINE_NUMBERS')
28
29
  end
29
30
 
30
31
  describe 'diff', :uses_diff => true do
@@ -88,33 +89,33 @@ describe 'diff', :uses_diff => true do
88
89
  it 'ChefFS::CommandLine.diff_print(/)' do
89
90
  results = []
90
91
  ChefFS::CommandLine.diff_print(pattern('/'), a, b, nil, nil) do |diff|
91
- results << remove_date(diff)
92
+ results << remove_os_differences(diff)
92
93
  end
93
94
  results.should =~ [
94
95
  'diff --knife a/both_dirs/sub_both_files_different b/both_dirs/sub_both_files_different
95
96
  --- a/both_dirs/sub_both_files_different DATE
96
97
  +++ b/both_dirs/sub_both_files_different DATE
97
- @@ -1 +1 @@
98
+ CONTEXT_LINE_NUMBERS
98
99
  -a
99
100
  +b
100
101
  ','diff --knife a/both_dirs/sub_dirs_empty_in_a_filled_in_b/subsub b/both_dirs/sub_dirs_empty_in_a_filled_in_b/subsub
101
102
  new file
102
103
  --- /dev/null DATE
103
104
  +++ b/both_dirs/sub_dirs_empty_in_a_filled_in_b/subsub DATE
104
- @@ -0,0 +1 @@
105
+ CONTEXT_LINE_NUMBERS
105
106
  +subsub
106
107
  ','diff --knife a/both_dirs/sub_dirs_empty_in_b_filled_in_a/subsub b/both_dirs/sub_dirs_empty_in_b_filled_in_a/subsub
107
108
  deleted file
108
109
  --- a/both_dirs/sub_dirs_empty_in_b_filled_in_a/subsub DATE
109
110
  +++ /dev/null DATE
110
- @@ -1 +0,0 @@
111
+ CONTEXT_LINE_NUMBERS
111
112
  -subsub
112
113
  ','Only in a/both_dirs: sub_a_only_dir
113
114
  ','diff --knife a/both_dirs/sub_a_only_file b/both_dirs/sub_a_only_file
114
115
  deleted file
115
116
  --- a/both_dirs/sub_a_only_file DATE
116
117
  +++ /dev/null DATE
117
- @@ -1 +0,0 @@
118
+ CONTEXT_LINE_NUMBERS
118
119
  -sub_a_only_file
119
120
  ','File a/both_dirs/sub_dir_in_a_file_in_b is a directory while file b/both_dirs/sub_dir_in_a_file_in_b is a regular file
120
121
  ','File a/both_dirs/sub_file_in_a_dir_in_b is a regular file while file b/both_dirs/sub_file_in_a_dir_in_b is a directory
@@ -123,32 +124,32 @@ deleted file
123
124
  new file
124
125
  --- /dev/null DATE
125
126
  +++ b/both_dirs/sub_b_only_file DATE
126
- @@ -0,0 +1 @@
127
+ CONTEXT_LINE_NUMBERS
127
128
  +sub_b_only_file
128
129
  ','diff --knife a/both_files_different b/both_files_different
129
130
  --- a/both_files_different DATE
130
131
  +++ b/both_files_different DATE
131
- @@ -1 +1 @@
132
+ CONTEXT_LINE_NUMBERS
132
133
  -a
133
134
  +b
134
135
  ','diff --knife a/dirs_empty_in_a_filled_in_b/subsub b/dirs_empty_in_a_filled_in_b/subsub
135
136
  new file
136
137
  --- /dev/null DATE
137
138
  +++ b/dirs_empty_in_a_filled_in_b/subsub DATE
138
- @@ -0,0 +1 @@
139
+ CONTEXT_LINE_NUMBERS
139
140
  +subsub
140
141
  ','diff --knife a/dirs_empty_in_b_filled_in_a/subsub b/dirs_empty_in_b_filled_in_a/subsub
141
142
  deleted file
142
143
  --- a/dirs_empty_in_b_filled_in_a/subsub DATE
143
144
  +++ /dev/null DATE
144
- @@ -1 +0,0 @@
145
+ CONTEXT_LINE_NUMBERS
145
146
  -subsub
146
147
  ','Only in a: a_only_dir
147
148
  ','diff --knife a/a_only_file b/a_only_file
148
149
  deleted file
149
150
  --- a/a_only_file DATE
150
151
  +++ /dev/null DATE
151
- @@ -1 +0,0 @@
152
+ CONTEXT_LINE_NUMBERS
152
153
  -a_only_file
153
154
  ','File a/dir_in_a_file_in_b is a directory while file b/dir_in_a_file_in_b is a regular file
154
155
  ','File a/file_in_a_dir_in_b is a regular file while file b/file_in_a_dir_in_b is a directory
@@ -157,40 +158,40 @@ deleted file
157
158
  new file
158
159
  --- /dev/null DATE
159
160
  +++ b/b_only_file DATE
160
- @@ -0,0 +1 @@
161
+ CONTEXT_LINE_NUMBERS
161
162
  +b_only_file
162
163
  ' ]
163
164
  end
164
165
  it 'ChefFS::CommandLine.diff_print(/both_dirs)' do
165
166
  results = []
166
167
  ChefFS::CommandLine.diff_print(pattern('/both_dirs'), a, b, nil, nil) do |diff|
167
- results << remove_date(diff)
168
+ results << remove_os_differences(diff)
168
169
  end
169
170
  results.should =~ [
170
171
  'diff --knife a/both_dirs/sub_both_files_different b/both_dirs/sub_both_files_different
171
172
  --- a/both_dirs/sub_both_files_different DATE
172
173
  +++ b/both_dirs/sub_both_files_different DATE
173
- @@ -1 +1 @@
174
+ CONTEXT_LINE_NUMBERS
174
175
  -a
175
176
  +b
176
177
  ','diff --knife a/both_dirs/sub_dirs_empty_in_a_filled_in_b/subsub b/both_dirs/sub_dirs_empty_in_a_filled_in_b/subsub
177
178
  new file
178
179
  --- /dev/null DATE
179
180
  +++ b/both_dirs/sub_dirs_empty_in_a_filled_in_b/subsub DATE
180
- @@ -0,0 +1 @@
181
+ CONTEXT_LINE_NUMBERS
181
182
  +subsub
182
183
  ','diff --knife a/both_dirs/sub_dirs_empty_in_b_filled_in_a/subsub b/both_dirs/sub_dirs_empty_in_b_filled_in_a/subsub
183
184
  deleted file
184
185
  --- a/both_dirs/sub_dirs_empty_in_b_filled_in_a/subsub DATE
185
186
  +++ /dev/null DATE
186
- @@ -1 +0,0 @@
187
+ CONTEXT_LINE_NUMBERS
187
188
  -subsub
188
189
  ','Only in a/both_dirs: sub_a_only_dir
189
190
  ','diff --knife a/both_dirs/sub_a_only_file b/both_dirs/sub_a_only_file
190
191
  deleted file
191
192
  --- a/both_dirs/sub_a_only_file DATE
192
193
  +++ /dev/null DATE
193
- @@ -1 +0,0 @@
194
+ CONTEXT_LINE_NUMBERS
194
195
  -sub_a_only_file
195
196
  ','File a/both_dirs/sub_dir_in_a_file_in_b is a directory while file b/both_dirs/sub_dir_in_a_file_in_b is a regular file
196
197
  ','File a/both_dirs/sub_file_in_a_dir_in_b is a regular file while file b/both_dirs/sub_file_in_a_dir_in_b is a directory
@@ -199,21 +200,21 @@ deleted file
199
200
  new file
200
201
  --- /dev/null DATE
201
202
  +++ b/both_dirs/sub_b_only_file DATE
202
- @@ -0,0 +1 @@
203
+ CONTEXT_LINE_NUMBERS
203
204
  +sub_b_only_file
204
205
  ' ]
205
206
  end
206
207
  it 'ChefFS::CommandLine.diff_print(/) with depth 1' do
207
208
  results = []
208
209
  ChefFS::CommandLine.diff_print(pattern('/'), a, b, 1, nil) do |diff|
209
- results << remove_date(diff)
210
+ results << remove_os_differences(diff)
210
211
  end
211
212
  results.should =~ [
212
213
  'Common subdirectories: b/both_dirs
213
214
  ','diff --knife a/both_files_different b/both_files_different
214
215
  --- a/both_files_different DATE
215
216
  +++ b/both_files_different DATE
216
- @@ -1 +1 @@
217
+ CONTEXT_LINE_NUMBERS
217
218
  -a
218
219
  +b
219
220
  ','Common subdirectories: b/both_dirs_empty
@@ -224,7 +225,7 @@ new file
224
225
  deleted file
225
226
  --- a/a_only_file DATE
226
227
  +++ /dev/null DATE
227
- @@ -1 +0,0 @@
228
+ CONTEXT_LINE_NUMBERS
228
229
  -a_only_file
229
230
  ','File a/dir_in_a_file_in_b is a directory while file b/dir_in_a_file_in_b is a regular file
230
231
  ','File a/file_in_a_dir_in_b is a regular file while file b/file_in_a_dir_in_b is a directory
@@ -233,21 +234,21 @@ deleted file
233
234
  new file
234
235
  --- /dev/null DATE
235
236
  +++ b/b_only_file DATE
236
- @@ -0,0 +1 @@
237
+ CONTEXT_LINE_NUMBERS
237
238
  +b_only_file
238
239
  ' ]
239
240
  end
240
241
  it 'ChefFS::CommandLine.diff_print(/*_*) with depth 0' do
241
242
  results = []
242
243
  ChefFS::CommandLine.diff_print(pattern('/*_*'), a, b, 0, nil) do |diff|
243
- results << remove_date(diff)
244
+ results << remove_os_differences(diff)
244
245
  end
245
246
  results.should =~ [
246
247
  'Common subdirectories: b/both_dirs
247
248
  ','diff --knife a/both_files_different b/both_files_different
248
249
  --- a/both_files_different DATE
249
250
  +++ b/both_files_different DATE
250
- @@ -1 +1 @@
251
+ CONTEXT_LINE_NUMBERS
251
252
  -a
252
253
  +b
253
254
  ','Common subdirectories: b/both_dirs_empty
@@ -258,7 +259,7 @@ new file
258
259
  deleted file
259
260
  --- a/a_only_file DATE
260
261
  +++ /dev/null DATE
261
- @@ -1 +0,0 @@
262
+ CONTEXT_LINE_NUMBERS
262
263
  -a_only_file
263
264
  ','File a/dir_in_a_file_in_b is a directory while file b/dir_in_a_file_in_b is a regular file
264
265
  ','File a/file_in_a_dir_in_b is a regular file while file b/file_in_a_dir_in_b is a directory
@@ -267,14 +268,14 @@ deleted file
267
268
  new file
268
269
  --- /dev/null DATE
269
270
  +++ b/b_only_file DATE
270
- @@ -0,0 +1 @@
271
+ CONTEXT_LINE_NUMBERS
271
272
  +b_only_file
272
273
  ' ]
273
274
  end
274
275
  it 'ChefFS::CommandLine.diff_print(/) in name-only mode' do
275
276
  results = []
276
277
  ChefFS::CommandLine.diff_print(pattern('/'), a, b, nil, :name_only) do |diff|
277
- results << remove_date(diff)
278
+ results << remove_os_differences(diff)
278
279
  end
279
280
  results.should =~ [
280
281
  "b/both_dirs/sub_both_files_different\n",
@@ -300,7 +301,7 @@ new file
300
301
  it 'ChefFS::CommandLine.diff_print(/) in name-status mode' do
301
302
  results = []
302
303
  ChefFS::CommandLine.diff_print(pattern('/'), a, b, nil, :name_status) do |diff|
303
- results << remove_date(diff)
304
+ results << remove_os_differences(diff)
304
305
  end
305
306
  results.should =~ [
306
307
  "M\tb/both_dirs/sub_both_files_different\n",
@@ -100,8 +100,8 @@ EOM
100
100
  file 'roles/x.json', {}
101
101
  file 'users/x.json', {}
102
102
 
103
- it 'knife delete /cookbooks/x fails' do
104
- knife('delete /cookbooks/x').should_fail <<EOM
103
+ it 'knife delete --both /cookbooks/x fails' do
104
+ knife('delete --both /cookbooks/x').should_fail <<EOM
105
105
  ERROR: /cookbooks/x (remote) must be deleted recursively! Pass -r to knife delete.
106
106
  ERROR: /cookbooks/x (local) must be deleted recursively! Pass -r to knife delete.
107
107
  EOM
@@ -109,8 +109,8 @@ EOM
109
109
  knife('list -Rf --local /').should_succeed everything
110
110
  end
111
111
 
112
- it 'knife delete -r /cookbooks/x deletes x' do
113
- knife('delete -r /cookbooks/x').should_succeed "Deleted /cookbooks/x\n"
112
+ it 'knife delete --both -r /cookbooks/x deletes x' do
113
+ knife('delete --both -r /cookbooks/x').should_succeed "Deleted /cookbooks/x\n"
114
114
  knife('list -Rf /').should_succeed <<EOM
115
115
  /clients
116
116
  /clients/chef-validator.json
@@ -150,8 +150,8 @@ EOM
150
150
  EOM
151
151
  end
152
152
 
153
- it 'knife delete -r --local-only /cookbooks/x deletes x locally but not remotely' do
154
- knife('delete -r --local-only /cookbooks/x').should_succeed "Deleted /cookbooks/x\n"
153
+ it 'knife delete -r --local /cookbooks/x deletes x locally but not remotely' do
154
+ knife('delete -r --local /cookbooks/x').should_succeed "Deleted /cookbooks/x\n"
155
155
  knife('list -Rf /').should_succeed server_everything
156
156
  knife('list -Rf --local /').should_succeed <<EOM
157
157
  /clients
@@ -172,8 +172,8 @@ EOM
172
172
  EOM
173
173
  end
174
174
 
175
- it 'knife delete -r --remote-only /cookbooks/x deletes x remotely but not locally' do
176
- knife('delete -r --remote-only /cookbooks/x').should_succeed "Deleted /cookbooks/x\n"
175
+ it 'knife delete -r /cookbooks/x deletes x remotely but not locally' do
176
+ knife('delete -r /cookbooks/x').should_succeed "Deleted /cookbooks/x\n"
177
177
  knife('list -Rf /').should_succeed <<EOM
178
178
  /clients
179
179
  /clients/chef-validator.json
@@ -201,8 +201,8 @@ EOM
201
201
  context 'with an empty data bag on both' do
202
202
  data_bag 'empty', {}
203
203
  directory 'data_bags/empty'
204
- it 'knife delete /data_bags/empty fails but deletes local version' do
205
- knife('delete /data_bags/empty').should_fail <<EOM
204
+ it 'knife delete --both /data_bags/empty fails but deletes local version' do
205
+ knife('delete --both /data_bags/empty').should_fail <<EOM
206
206
  ERROR: /data_bags/empty (remote) must be deleted recursively! Pass -r to knife delete.
207
207
  ERROR: /data_bags/empty (local) must be deleted recursively! Pass -r to knife delete.
208
208
  EOM
@@ -252,8 +252,8 @@ EOM
252
252
  end
253
253
  end
254
254
 
255
- it 'knife delete /data_bags/x fails' do
256
- knife('delete /data_bags/x').should_fail <<EOM
255
+ it 'knife delete --both /data_bags/x fails' do
256
+ knife('delete --both /data_bags/x').should_fail <<EOM
257
257
  ERROR: /data_bags/x (remote) must be deleted recursively! Pass -r to knife delete.
258
258
  ERROR: /data_bags/x (local) must be deleted recursively! Pass -r to knife delete.
259
259
  EOM
@@ -261,8 +261,8 @@ EOM
261
261
  knife('list -Rf --local /').should_succeed everything
262
262
  end
263
263
 
264
- it 'knife delete -r /data_bags/x deletes x' do
265
- knife('delete -r /data_bags/x').should_succeed "Deleted /data_bags/x\n"
264
+ it 'knife delete --both -r /data_bags/x deletes x' do
265
+ knife('delete --both -r /data_bags/x').should_succeed "Deleted /data_bags/x\n"
266
266
  knife('list -Rf /').should_succeed <<EOM
267
267
  /clients
268
268
  /clients/chef-validator.json
@@ -302,8 +302,8 @@ EOM
302
302
  EOM
303
303
  end
304
304
 
305
- it 'knife delete /environments/x.json deletes x' do
306
- knife('delete /environments/x.json').should_succeed "Deleted /environments/x.json\n"
305
+ it 'knife delete --both /environments/x.json deletes x' do
306
+ knife('delete --both /environments/x.json').should_succeed "Deleted /environments/x.json\n"
307
307
  knife('list -Rf /').should_succeed <<EOM
308
308
  /clients
309
309
  /clients/chef-validator.json
@@ -345,8 +345,8 @@ EOM
345
345
  EOM
346
346
  end
347
347
 
348
- it 'knife delete /roles/x.json deletes x' do
349
- knife('delete /roles/x.json').should_succeed "Deleted /roles/x.json\n"
348
+ it 'knife delete --both /roles/x.json deletes x' do
349
+ knife('delete --both /roles/x.json').should_succeed "Deleted /roles/x.json\n"
350
350
  knife('list -Rf /').should_succeed <<EOM
351
351
  /clients
352
352
  /clients/chef-validator.json
@@ -388,8 +388,8 @@ EOM
388
388
  EOM
389
389
  end
390
390
 
391
- it 'knife delete /environments/_default.json fails but still deletes the local copy' do
392
- knife('delete /environments/_default.json').should_fail :stderr => "ERROR: /environments/_default.json (remote) cannot be deleted (default environment cannot be modified).\n", :stdout => "Deleted /environments/_default.json\n"
391
+ it 'knife delete --both /environments/_default.json fails but still deletes the local copy' do
392
+ knife('delete --both /environments/_default.json').should_fail :stderr => "ERROR: /environments/_default.json (remote) cannot be deleted (default environment cannot be modified).\n", :stdout => "Deleted /environments/_default.json\n"
393
393
  knife('list -Rf /').should_succeed server_everything
394
394
  knife('list -Rf --local /').should_succeed <<EOM
395
395
  /clients
@@ -411,14 +411,14 @@ EOM
411
411
  EOM
412
412
  end
413
413
 
414
- it 'knife delete /environments/nonexistent.json fails' do
415
- knife('delete /environments/nonexistent.json').should_fail "ERROR: /environments/nonexistent.json: No such file or directory\n"
414
+ it 'knife delete --both /environments/nonexistent.json fails' do
415
+ knife('delete --both /environments/nonexistent.json').should_fail "ERROR: /environments/nonexistent.json: No such file or directory\n"
416
416
  knife('list -Rf /').should_succeed server_everything
417
417
  knife('list -Rf --local /').should_succeed everything
418
418
  end
419
419
 
420
- it 'knife delete / fails' do
421
- knife('delete /').should_fail <<EOM
420
+ it 'knife delete --both / fails' do
421
+ knife('delete --both /').should_fail <<EOM
422
422
  ERROR: / (remote) cannot be deleted.
423
423
  ERROR: / (local) cannot be deleted.
424
424
  EOM
@@ -426,8 +426,8 @@ EOM
426
426
  knife('list -Rf --local /').should_succeed everything
427
427
  end
428
428
 
429
- it 'knife delete -r /* fails' do
430
- knife('delete -r /*').should_fail <<EOM
429
+ it 'knife delete --both -r /* fails' do
430
+ knife('delete --both -r /*').should_fail <<EOM
431
431
  ERROR: / (remote) cannot be deleted.
432
432
  ERROR: / (local) cannot be deleted.
433
433
  ERROR: /clients (remote) cannot be deleted.
@@ -459,14 +459,14 @@ EOM
459
459
  directory 'roles'
460
460
  directory 'users'
461
461
 
462
- it 'knife delete /cookbooks/x fails' do
463
- knife('delete /cookbooks/x').should_fail "ERROR: /cookbooks/x (remote) must be deleted recursively! Pass -r to knife delete.\n"
462
+ it 'knife delete --both /cookbooks/x fails' do
463
+ knife('delete --both /cookbooks/x').should_fail "ERROR: /cookbooks/x (remote) must be deleted recursively! Pass -r to knife delete.\n"
464
464
  knife('list -Rf /').should_succeed server_everything
465
465
  knife('list -Rf --local /').should_succeed nothing
466
466
  end
467
467
 
468
- it 'knife delete -r /cookbooks/x deletes x' do
469
- knife('delete -r /cookbooks/x').should_succeed "Deleted /cookbooks/x\n"
468
+ it 'knife delete --both -r /cookbooks/x deletes x' do
469
+ knife('delete --both -r /cookbooks/x').should_succeed "Deleted /cookbooks/x\n"
470
470
  knife('list -Rf /').should_succeed <<EOM
471
471
  /clients
472
472
  /clients/chef-validator.json
@@ -490,14 +490,14 @@ EOM
490
490
  knife('list -Rf --local /').should_succeed nothing
491
491
  end
492
492
 
493
- it 'knife delete /data_bags/x fails' do
494
- knife('delete /data_bags/x').should_fail "ERROR: /data_bags/x (remote) must be deleted recursively! Pass -r to knife delete.\n"
493
+ it 'knife delete --both /data_bags/x fails' do
494
+ knife('delete --both /data_bags/x').should_fail "ERROR: /data_bags/x (remote) must be deleted recursively! Pass -r to knife delete.\n"
495
495
  knife('list -Rf /').should_succeed server_everything
496
496
  knife('list -Rf --local /').should_succeed nothing
497
497
  end
498
498
 
499
- it 'knife delete -r /data_bags/x deletes x' do
500
- knife('delete -r /data_bags/x').should_succeed "Deleted /data_bags/x\n"
499
+ it 'knife delete --both -r /data_bags/x deletes x' do
500
+ knife('delete --both -r /data_bags/x').should_succeed "Deleted /data_bags/x\n"
501
501
  knife('list -Rf /').should_succeed <<EOM
502
502
  /clients
503
503
  /clients/chef-validator.json
@@ -521,8 +521,8 @@ EOM
521
521
  knife('list -Rf --local /').should_succeed nothing
522
522
  end
523
523
 
524
- it 'knife delete /environments/x.json deletes x' do
525
- knife('delete /environments/x.json').should_succeed "Deleted /environments/x.json\n"
524
+ it 'knife delete --both /environments/x.json deletes x' do
525
+ knife('delete --both /environments/x.json').should_succeed "Deleted /environments/x.json\n"
526
526
  knife('list -Rf /').should_succeed <<EOM
527
527
  /clients
528
528
  /clients/chef-validator.json
@@ -547,8 +547,8 @@ EOM
547
547
  knife('list -Rf --local /').should_succeed nothing
548
548
  end
549
549
 
550
- it 'knife delete /roles/x.json deletes x' do
551
- knife('delete /roles/x.json').should_succeed "Deleted /roles/x.json\n"
550
+ it 'knife delete --both /roles/x.json deletes x' do
551
+ knife('delete --both /roles/x.json').should_succeed "Deleted /roles/x.json\n"
552
552
  knife('list -Rf /').should_succeed <<EOM
553
553
  /clients
554
554
  /clients/chef-validator.json
@@ -573,20 +573,20 @@ EOM
573
573
  knife('list -Rf --local /').should_succeed nothing
574
574
  end
575
575
 
576
- it 'knife delete /environments/_default.json fails' do
577
- knife('delete /environments/_default.json').should_fail "", :stderr => "ERROR: /environments/_default.json (remote) cannot be deleted (default environment cannot be modified).\n"
576
+ it 'knife delete --both /environments/_default.json fails' do
577
+ knife('delete --both /environments/_default.json').should_fail "", :stderr => "ERROR: /environments/_default.json (remote) cannot be deleted (default environment cannot be modified).\n"
578
578
  knife('list -Rf /').should_succeed server_everything
579
579
  knife('list -Rf --local /').should_succeed nothing
580
580
  end
581
581
 
582
- it 'knife delete / fails' do
583
- knife('delete /').should_fail "ERROR: / (remote) cannot be deleted.\nERROR: / (local) cannot be deleted.\n"
582
+ it 'knife delete --both / fails' do
583
+ knife('delete --both /').should_fail "ERROR: / (remote) cannot be deleted.\nERROR: / (local) cannot be deleted.\n"
584
584
  knife('list -Rf /').should_succeed server_everything
585
585
  knife('list -Rf --local /').should_succeed nothing
586
586
  end
587
587
 
588
- it 'knife delete -r /* fails' do
589
- knife('delete -r /*').should_fail <<EOM
588
+ it 'knife delete --both -r /* fails' do
589
+ knife('delete --both -r /*').should_fail <<EOM
590
590
  ERROR: / (remote) cannot be deleted.
591
591
  ERROR: / (local) cannot be deleted.
592
592
  ERROR: /clients (remote) cannot be deleted.
@@ -608,8 +608,8 @@ EOM
608
608
  knife('list -Rf --local /').should_succeed nothing
609
609
  end
610
610
 
611
- it 'knife delete /environments/nonexistent.json fails' do
612
- knife('delete /environments/nonexistent.json').should_fail "ERROR: /environments/nonexistent.json: No such file or directory\n"
611
+ it 'knife delete --both /environments/nonexistent.json fails' do
612
+ knife('delete --both /environments/nonexistent.json').should_fail "ERROR: /environments/nonexistent.json: No such file or directory\n"
613
613
  knife('list -Rf /').should_succeed server_everything
614
614
  knife('list -Rf --local /').should_succeed nothing
615
615
  end
@@ -665,14 +665,14 @@ EOM
665
665
  file 'roles/x.json', {}
666
666
  file 'users/x.json', {}
667
667
 
668
- it 'knife delete /cookbooks/x fails' do
669
- knife('delete /cookbooks/x').should_fail "ERROR: /cookbooks/x (local) must be deleted recursively! Pass -r to knife delete.\n"
668
+ it 'knife delete --both /cookbooks/x fails' do
669
+ knife('delete --both /cookbooks/x').should_fail "ERROR: /cookbooks/x (local) must be deleted recursively! Pass -r to knife delete.\n"
670
670
  knife('list -Rf /').should_succeed server_nothing
671
671
  knife('list -Rf --local /').should_succeed everything
672
672
  end
673
673
 
674
- it 'knife delete -r /cookbooks/x deletes x' do
675
- knife('delete -r /cookbooks/x').should_succeed "Deleted /cookbooks/x\n"
674
+ it 'knife delete --both -r /cookbooks/x deletes x' do
675
+ knife('delete --both -r /cookbooks/x').should_succeed "Deleted /cookbooks/x\n"
676
676
  knife('list -Rf /').should_succeed server_nothing
677
677
  knife('list -Rf --local /').should_succeed <<EOM
678
678
  /clients
@@ -693,14 +693,14 @@ EOM
693
693
  EOM
694
694
  end
695
695
 
696
- it 'knife delete /data_bags/x fails' do
697
- knife('delete /data_bags/x').should_fail "ERROR: /data_bags/x (local) must be deleted recursively! Pass -r to knife delete.\n"
696
+ it 'knife delete --both /data_bags/x fails' do
697
+ knife('delete --both /data_bags/x').should_fail "ERROR: /data_bags/x (local) must be deleted recursively! Pass -r to knife delete.\n"
698
698
  knife('list -Rf /').should_succeed server_nothing
699
699
  knife('list -Rf --local /').should_succeed everything
700
700
  end
701
701
 
702
- it 'knife delete -r /data_bags/x deletes x' do
703
- knife('delete -r /data_bags/x').should_succeed "Deleted /data_bags/x\n"
702
+ it 'knife delete --both -r /data_bags/x deletes x' do
703
+ knife('delete --both -r /data_bags/x').should_succeed "Deleted /data_bags/x\n"
704
704
  knife('list -Rf /').should_succeed server_nothing
705
705
  knife('list -Rf --local /').should_succeed <<EOM
706
706
  /clients
@@ -721,8 +721,8 @@ EOM
721
721
  EOM
722
722
  end
723
723
 
724
- it 'knife delete /environments/x.json deletes x' do
725
- knife('delete /environments/x.json').should_succeed "Deleted /environments/x.json\n"
724
+ it 'knife delete --both /environments/x.json deletes x' do
725
+ knife('delete --both /environments/x.json').should_succeed "Deleted /environments/x.json\n"
726
726
  knife('list -Rf /').should_succeed server_nothing
727
727
  knife('list -Rf --local /').should_succeed <<EOM
728
728
  /clients
@@ -744,8 +744,8 @@ EOM
744
744
  EOM
745
745
  end
746
746
 
747
- it 'knife delete /roles/x.json deletes x' do
748
- knife('delete /roles/x.json').should_succeed "Deleted /roles/x.json\n"
747
+ it 'knife delete --both /roles/x.json deletes x' do
748
+ knife('delete --both /roles/x.json').should_succeed "Deleted /roles/x.json\n"
749
749
  knife('list -Rf /').should_succeed server_nothing
750
750
  knife('list -Rf --local /').should_succeed <<EOM
751
751
  /clients
@@ -767,8 +767,8 @@ EOM
767
767
  EOM
768
768
  end
769
769
 
770
- it 'knife delete /environments/_default.json fails but still deletes the local copy' do
771
- knife('delete /environments/_default.json').should_fail :stderr => "ERROR: /environments/_default.json (remote) cannot be deleted (default environment cannot be modified).\n", :stdout => "Deleted /environments/_default.json\n"
770
+ it 'knife delete --both /environments/_default.json fails but still deletes the local copy' do
771
+ knife('delete --both /environments/_default.json').should_fail :stderr => "ERROR: /environments/_default.json (remote) cannot be deleted (default environment cannot be modified).\n", :stdout => "Deleted /environments/_default.json\n"
772
772
  knife('list -Rf /').should_succeed server_nothing
773
773
  knife('list -Rf --local /').should_succeed <<EOM
774
774
  /clients
@@ -790,14 +790,14 @@ EOM
790
790
  EOM
791
791
  end
792
792
 
793
- it 'knife delete / fails' do
794
- knife('delete /').should_fail "ERROR: / (remote) cannot be deleted.\nERROR: / (local) cannot be deleted.\n"
793
+ it 'knife delete --both / fails' do
794
+ knife('delete --both /').should_fail "ERROR: / (remote) cannot be deleted.\nERROR: / (local) cannot be deleted.\n"
795
795
  knife('list -Rf /').should_succeed server_nothing
796
796
  knife('list -Rf --local /').should_succeed everything
797
797
  end
798
798
 
799
- it 'knife delete -r /* fails' do
800
- knife('delete -r /*').should_fail <<EOM
799
+ it 'knife delete --both -r /* fails' do
800
+ knife('delete --both -r /*').should_fail <<EOM
801
801
  ERROR: / (remote) cannot be deleted.
802
802
  ERROR: / (local) cannot be deleted.
803
803
  ERROR: /clients (remote) cannot be deleted.
@@ -819,8 +819,8 @@ EOM
819
819
  knife('list -Rf --local /').should_succeed everything
820
820
  end
821
821
 
822
- it 'knife delete /environments/nonexistent.json fails' do
823
- knife('delete /environments/nonexistent.json').should_fail "ERROR: /environments/nonexistent.json: No such file or directory\n"
822
+ it 'knife delete --both /environments/nonexistent.json fails' do
823
+ knife('delete --both /environments/nonexistent.json').should_fail "ERROR: /environments/nonexistent.json: No such file or directory\n"
824
824
  knife('list -Rf /').should_succeed server_nothing
825
825
  knife('list -Rf --local /').should_succeed everything
826
826
  end
@@ -875,8 +875,8 @@ EOM
875
875
  cookbook 'x', '1.0.1', { 'metadata.rb' => 'version "1.0.1"', 'onlyin1.0.1.rb' => 'hi' }
876
876
 
877
877
  # TODO this seems wrong
878
- it 'knife delete /cookbooks/x deletes the latest version on the server and the local version' do
879
- knife('delete -r /cookbooks/x').should_succeed "Deleted /cookbooks/x\n"
878
+ it 'knife delete --both -r /cookbooks/x deletes the latest version on the server and the local version' do
879
+ knife('delete --both -r /cookbooks/x').should_succeed "Deleted /cookbooks/x\n"
880
880
  knife('raw /cookbooks/x').should_succeed(/1.0.0/)
881
881
  knife('list --local /cookbooks').should_succeed ''
882
882
  end
@@ -886,8 +886,8 @@ EOM
886
886
  cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"', 'onlyin1.0.0.rb' => ''}
887
887
  cookbook 'x', '0.9.9', { 'metadata.rb' => 'version "0.9.9"', 'onlyin0.9.9.rb' => 'hi' }
888
888
 
889
- it 'knife delete /cookbooks/x deletes the latest version on the server and the local version' do
890
- knife('delete -r /cookbooks/x').should_succeed "Deleted /cookbooks/x\n"
889
+ it 'knife delete --both /cookbooks/x deletes the latest version on the server and the local version' do
890
+ knife('delete --both -r /cookbooks/x').should_succeed "Deleted /cookbooks/x\n"
891
891
  knife('raw /cookbooks/x').should_succeed(/0.9.9/)
892
892
  knife('list --local /cookbooks').should_succeed ''
893
893
  end
@@ -896,8 +896,8 @@ EOM
896
896
  when_the_chef_server 'has a later version for the cookbook, and no current version' do
897
897
  cookbook 'x', '1.0.1', { 'metadata.rb' => 'version "1.0.1"', 'onlyin1.0.1.rb' => 'hi' }
898
898
 
899
- it 'knife delete /cookbooks/x deletes the server and client version of the cookbook' do
900
- knife('delete -r /cookbooks/x').should_succeed "Deleted /cookbooks/x\n"
899
+ it 'knife delete --both /cookbooks/x deletes the server and client version of the cookbook' do
900
+ knife('delete --both -r /cookbooks/x').should_succeed "Deleted /cookbooks/x\n"
901
901
  knife('raw /cookbooks/x').should_fail(/404/)
902
902
  knife('list --local /cookbooks').should_succeed ''
903
903
  end
@@ -906,8 +906,8 @@ EOM
906
906
  when_the_chef_server 'has an earlier version for the cookbook, and no current version' do
907
907
  cookbook 'x', '0.9.9', { 'metadata.rb' => 'version "0.9.9"', 'onlyin0.9.9.rb' => 'hi' }
908
908
 
909
- it 'knife delete /cookbooks/x deletes the server and client version of the cookbook' do
910
- knife('delete -r /cookbooks/x').should_succeed "Deleted /cookbooks/x\n"
909
+ it 'knife delete --both /cookbooks/x deletes the server and client version of the cookbook' do
910
+ knife('delete --both -r /cookbooks/x').should_succeed "Deleted /cookbooks/x\n"
911
911
  knife('raw /cookbooks/x').should_fail(/404/)
912
912
  knife('list --local /cookbooks').should_succeed ''
913
913
  end
@@ -919,7 +919,7 @@ EOM
919
919
  cookbook 'x', '2.0.11', { 'metadata.rb' => 'version "2.0.11"' }
920
920
  cookbook 'x', '11.0.0', { 'metadata.rb' => 'version "11.0.0"' }
921
921
  it 'knife delete deletes the latest version' do
922
- knife('delete -r /cookbooks/x').should_succeed "Deleted /cookbooks/x\n"
922
+ knife('delete --both -r /cookbooks/x').should_succeed "Deleted /cookbooks/x\n"
923
923
  knife('raw /cookbooks/x').should_succeed /2.0.11/
924
924
  end
925
925
  end
@@ -368,6 +368,38 @@ EOM
368
368
  knife('diff --name-status /cookbooks').should_succeed ''
369
369
  end
370
370
  end
371
+
372
+ when_the_repository 'has a different file in the cookbook' do
373
+ file 'cookbooks/x/metadata.rb', 'version "1.0.0"'
374
+
375
+ it 'knife upload --freeze freezes the cookbook' do
376
+ knife('upload --freeze /cookbooks/x').should_succeed <<EOM
377
+ Updated /cookbooks/x
378
+ EOM
379
+ # Modify a file and attempt to upload
380
+ file 'cookbooks/x/metadata.rb', 'version "1.0.0" # This is different'
381
+ knife('upload /cookbooks/x').should_fail "ERROR: /cookbooks failed to write: Cookbook x is frozen\n"
382
+ end
383
+ end
384
+ end
385
+
386
+ when_the_chef_server 'has a frozen cookbook' do
387
+ cookbook 'frozencook', '1.0.0', {
388
+ 'metadata.rb' => 'version "1.0.0"'
389
+ }, :frozen => true
390
+
391
+ when_the_repository 'has an update to said cookbook' do
392
+ file 'cookbooks/frozencook/metadata.rb', 'version "1.0.0" # This is different'
393
+
394
+ it 'knife upload fails to upload the frozen cookbook' do
395
+ knife('upload /cookbooks/frozencook').should_fail "ERROR: /cookbooks failed to write: Cookbook frozencook is frozen\n"
396
+ end
397
+ it 'knife upload --force uploads the frozen cookbook' do
398
+ knife('upload --force /cookbooks/frozencook').should_succeed <<EOM
399
+ Updated /cookbooks/frozencook
400
+ EOM
401
+ end
402
+ end
371
403
  end
372
404
 
373
405
  when_the_repository 'has a cookbook' do
@@ -27,8 +27,8 @@ module KnifeSupport
27
27
  :skip_expires => true
28
28
  }
29
29
 
30
- # This is Chef::Knife.run without load_commands and load_deps--we'll
31
- # load stuff ourselves, thank you very much
30
+ # This is Chef::Knife.run without load_commands--we'll load stuff
31
+ # ourselves, thank you very much
32
32
  stdout = StringIO.new
33
33
  stderr = StringIO.new
34
34
  old_loggers = Chef::Log.loggers
@@ -37,6 +37,7 @@ module KnifeSupport
37
37
  puts "knife: #{args.join(' ')}" if DEBUG
38
38
  subcommand_class = Chef::Knife.subcommand_class_from(args)
39
39
  subcommand_class.options = Chef::Application::Knife.options.merge(subcommand_class.options)
40
+ subcommand_class.load_deps
40
41
  instance = subcommand_class.new(args)
41
42
 
42
43
  # Capture stdout/stderr
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-essentials
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: '1.2'
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: 2013-05-28 00:00:00.000000000 Z
12
+ date: 2013-06-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chef
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ! '>='
36
36
  - !ruby/object:Gem::Version
37
- version: '0'
37
+ version: '1.2'
38
38
  type: :development
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
- version: '0'
45
+ version: '1.2'
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: rspec
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -145,6 +145,7 @@ files:
145
145
  - lib/chef_fs/file_system/acl_dir.rb
146
146
  - lib/chef_fs/file_system/acl_entry.rb
147
147
  - lib/chef_fs/file_system/acls_dir.rb
148
+ - lib/chef_fs/file_system/already_exists_error.rb
148
149
  - lib/chef_fs/file_system/base_fs_dir.rb
149
150
  - lib/chef_fs/file_system/base_fs_object.rb
150
151
  - lib/chef_fs/file_system/chef_repository_file_system_cookbooks_dir.rb
@@ -154,6 +155,7 @@ files:
154
155
  - lib/chef_fs/file_system/chef_server_root_dir.rb
155
156
  - lib/chef_fs/file_system/cookbook_dir.rb
156
157
  - lib/chef_fs/file_system/cookbook_file.rb
158
+ - lib/chef_fs/file_system/cookbook_frozen_error.rb
157
159
  - lib/chef_fs/file_system/cookbook_subdir.rb
158
160
  - lib/chef_fs/file_system/cookbooks_acl_dir.rb
159
161
  - lib/chef_fs/file_system/cookbooks_dir.rb