summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-04-27 10:46:27 -0700
committerGitHub <noreply@github.com>2018-04-27 10:46:27 -0700
commitc87e6e21b802ba3bc2798adf2bf867b91ed5dd00 (patch)
tree92d44ac26a5a3bcbbf9f17c285f43d0320f36ab7
parentd64f00f476c9bbcab8cc8cb3e15c6bd1df2a8761 (diff)
parent6d476386cf278105cf3c41414392ecb90c2bb00a (diff)
downloadchef-c87e6e21b802ba3bc2798adf2bf867b91ed5dd00.tar.gz
Merge pull request #7129 from rmoriz/rmoriz/git-prune
prune remotes with git fetch, fixes #3929
-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]")