summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keiser <jkeiser@opscode.com>2013-05-07 10:07:21 -0700
committerJohn Keiser <jkeiser@opscode.com>2013-06-07 13:12:32 -0700
commit9fabc2ea4d024d5910c3e23c7be19b1d2c93c7ad (patch)
tree1e9de4767717ebdbdf76e3b27011613c8c2826fb
parent395cb75b0cd7aca6d4af27823417b247236676b9 (diff)
downloadchef-9fabc2ea4d024d5910c3e23c7be19b1d2c93c7ad.tar.gz
Add --no-diff option to allow download/upload of only new files
-rw-r--r--lib/chef/chef_fs/file_system.rb6
-rw-r--r--lib/chef/knife/download.rb6
-rw-r--r--lib/chef/knife/upload.rb6
-rw-r--r--spec/integration/knife/download_spec.rb31
-rw-r--r--spec/integration/knife/upload_spec.rb20
5 files changed, 67 insertions, 2 deletions
diff --git a/lib/chef/chef_fs/file_system.rb b/lib/chef/chef_fs/file_system.rb
index 385f955806..000a5cf90f 100644
--- a/lib/chef/chef_fs/file_system.rb
+++ b/lib/chef/chef_fs/file_system.rb
@@ -369,8 +369,10 @@ class Chef
return
else
- # Both are files! Copy them unless we're sure they are the same.
- if options[:force]
+ # Both are files! Copy them unless we're sure they are the same.'
+ if options[:diff] == false
+ should_copy = false
+ elsif options[:force]
should_copy = true
src_value = nil
else
diff --git a/lib/chef/knife/download.rb b/lib/chef/knife/download.rb
index 94f1b1b17f..26abcb3acd 100644
--- a/lib/chef/knife/download.rb
+++ b/lib/chef/knife/download.rb
@@ -33,6 +33,12 @@ class Chef
:default => false,
:description => "Don't take action, only print what would happen"
+ option :diff,
+ :long => '--[no-]diff',
+ :boolean => true,
+ :default => true,
+ :description => 'Turn off to avoid uploading existing files; only new (and possibly deleted) files with --no-diff'
+
def run
if name_args.length == 0
show_usage
diff --git a/lib/chef/knife/upload.rb b/lib/chef/knife/upload.rb
index 2b3fbd0e30..7105945a96 100644
--- a/lib/chef/knife/upload.rb
+++ b/lib/chef/knife/upload.rb
@@ -33,6 +33,12 @@ class Chef
:default => false,
:description => "Don't take action, only print what would happen"
+ option :diff,
+ :long => '--[no-]diff',
+ :boolean => true,
+ :default => true,
+ :description => 'Turn off to avoid uploading existing files; only new (and possibly deleted) files with --no-diff'
+
def run
if name_args.length == 0
show_usage
diff --git a/spec/integration/knife/download_spec.rb b/spec/integration/knife/download_spec.rb
index 13e95a0d3d..e95c6940d2 100644
--- a/spec/integration/knife/download_spec.rb
+++ b/spec/integration/knife/download_spec.rb
@@ -90,6 +90,11 @@ EOM
knife('download /').should_succeed "Updated /roles/x.json\n"
knife('diff --name-status /').should_succeed ''
end
+
+ it 'knife download --no-diff does not change the role' do
+ knife('download --no-diff /').should_succeed ''
+ knife('diff --name-status /').should_succeed "M\t/roles/x.json\n"
+ end
end
context 'except the role file is textually different, but not ACTUALLY different' do
@@ -186,6 +191,32 @@ EOM
knife('diff --name-status /').should_succeed ''
end
+ it 'knife download --no-diff creates the extra files' do
+ knife('download /').should_succeed <<EOM
+Created /clients
+Created /clients/chef-validator.json
+Created /clients/chef-webui.json
+Created /clients/x.json
+Created /cookbooks
+Created /cookbooks/x
+Created /cookbooks/x/metadata.rb
+Created /data_bags
+Created /data_bags/x
+Created /data_bags/x/y.json
+Created /environments
+Created /environments/_default.json
+Created /environments/x.json
+Created /nodes
+Created /nodes/x.json
+Created /roles
+Created /roles/x.json
+Created /users
+Created /users/admin.json
+Created /users/x.json
+EOM
+ knife('diff --name-status /').should_succeed ''
+ end
+
context 'when current directory is top level' do
cwd '.'
it 'knife download with no parameters reports an error' do
diff --git a/spec/integration/knife/upload_spec.rb b/spec/integration/knife/upload_spec.rb
index 1ee2021997..0adaa977c8 100644
--- a/spec/integration/knife/upload_spec.rb
+++ b/spec/integration/knife/upload_spec.rb
@@ -90,6 +90,10 @@ EOM
knife('upload /').should_succeed "Updated /roles/x.json\n"
knife('diff --name-status /').should_succeed ''
end
+ it 'knife upload --no-diff does not change the role' do
+ knife('upload /').should_succeed ''
+ knife('diff --name-status /').should_succeed "M\t/roles/x.json\n"
+ end
end
context 'except the role file is textually different, but not ACTUALLY different' do
@@ -142,6 +146,22 @@ Created /users/y.json
EOM
knife('diff --name-status /').should_succeed ''
end
+
+ it 'knife upload --no-diff adds the new files' do
+ knife('upload /').should_succeed <<EOM
+Created /clients/y.json
+Updated /cookbooks/x
+Created /cookbooks/y
+Created /data_bags/x/z.json
+Created /data_bags/y
+Created /data_bags/y/zz.json
+Created /environments/y.json
+Created /nodes/y.json
+Created /roles/y.json
+Created /users/y.json
+EOM
+ knife('diff --name-status /').should_succeed ''
+ end
end
end