summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoland Moriz <roland@moriz.de>2018-04-06 12:58:28 +0200
committerRoland Moriz <roland@moriz.de>2018-04-06 13:01:04 +0200
commit6d476386cf278105cf3c41414392ecb90c2bb00a (patch)
tree010a456bf988a498534aa515d662f066b35ce1ba
parentdcabccc37c0017d7ca330f1c54e6fd385a51eaf8 (diff)
downloadchef-6d476386cf278105cf3c41414392ecb90c2bb00a.tar.gz
prune remotes with git fetch, fixes #3929
Signed-off-by: Roland Moriz <roland@moriz.de>
-rw-r--r--lib/chef/provider/git.rb4
-rw-r--r--spec/unit/provider/git_spec.rb16
2 files changed, 10 insertions, 10 deletions
diff --git a/lib/chef/provider/git.rb b/lib/chef/provider/git.rb
index 302404e293..a14711e2b6 100644
--- a/lib/chef/provider/git.rb
+++ b/lib/chef/provider/git.rb
@@ -194,8 +194,8 @@ class Chef
converge_by("fetch updates for #{new_resource.remote}") do
# since we're in a local branch already, just reset to specified revision rather than merge
logger.trace "Fetching updates from #{new_resource.remote} and resetting to revision #{target_revision}"
- git("fetch", new_resource.remote, cwd: cwd)
- git("fetch", new_resource.remote, "--tags", cwd: cwd)
+ git("fetch", "--prune", new_resource.remote, cwd: cwd)
+ git("fetch", "--prune-tags", new_resource.remote, "--tags", cwd: cwd)
git("reset", "--hard", target_revision, cwd: cwd)
end
end
diff --git a/spec/unit/provider/git_spec.rb b/spec/unit/provider/git_spec.rb
index cacee0baaa..c32c2ee146 100644
--- a/spec/unit/provider/git_spec.rb
+++ b/spec/unit/provider/git_spec.rb
@@ -425,9 +425,9 @@ SHAS
it "runs a sync command with default options" do
expect(@provider).to receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository)
- expected_cmd1 = "git fetch origin"
+ expected_cmd1 = "git fetch --prune origin"
expect(@provider).to receive(:shell_out!).with(expected_cmd1, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]")
- expected_cmd2 = "git fetch origin --tags"
+ expected_cmd2 = "git fetch --prune-tags origin --tags"
expect(@provider).to receive(:shell_out!).with(expected_cmd2, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]")
expected_cmd3 = "git reset --hard d35af14d41ae22b19da05d7d03a0bafc321b244c"
expect(@provider).to receive(:shell_out!).with(expected_cmd3, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]")
@@ -440,12 +440,12 @@ SHAS
@resource.group("thisis")
expect(@provider).to receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository)
- expected_cmd1 = "git fetch origin"
+ expected_cmd1 = "git fetch --prune origin"
expect(@provider).to receive(:shell_out!).with(expected_cmd1, :cwd => "/my/deploy/dir",
:user => "whois", :group => "thisis",
:log_tag => "git[web2.0 app]",
:environment => { "HOME" => "/home/whois" })
- expected_cmd2 = "git fetch origin --tags"
+ expected_cmd2 = "git fetch --prune-tags origin --tags"
expect(@provider).to receive(:shell_out!).with(expected_cmd2, :cwd => "/my/deploy/dir",
:user => "whois", :group => "thisis",
:log_tag => "git[web2.0 app]",
@@ -461,9 +461,9 @@ SHAS
it "configures remote tracking branches when remote is ``origin''" do
@resource.remote "origin"
expect(@provider).to receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository)
- fetch_command1 = "git fetch origin"
+ fetch_command1 = "git fetch --prune origin"
expect(@provider).to receive(:shell_out!).with(fetch_command1, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]")
- fetch_command2 = "git fetch origin --tags"
+ fetch_command2 = "git fetch --prune-tags origin --tags"
expect(@provider).to receive(:shell_out!).with(fetch_command2, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]")
fetch_command3 = "git reset --hard d35af14d41ae22b19da05d7d03a0bafc321b244c"
expect(@provider).to receive(:shell_out!).with(fetch_command3, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]")
@@ -473,9 +473,9 @@ SHAS
it "configures remote tracking branches when remote is not ``origin''" do
@resource.remote "opscode"
expect(@provider).to receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository)
- fetch_command1 = "git fetch opscode"
+ fetch_command1 = "git fetch --prune opscode"
expect(@provider).to receive(:shell_out!).with(fetch_command1, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]")
- fetch_command2 = "git fetch opscode --tags"
+ fetch_command2 = "git fetch --prune-tags opscode --tags"
expect(@provider).to receive(:shell_out!).with(fetch_command2, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]")
fetch_command3 = "git reset --hard d35af14d41ae22b19da05d7d03a0bafc321b244c"
expect(@provider).to receive(:shell_out!).with(fetch_command3, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]")