Read about our upcoming Code of Conduct on this issue

Commit 3cc74a4a authored by Tiger Watson's avatar Tiger Watson
Browse files

Merge branch '1193-touching-a-protected-file-no-longer-silences-the-diff-warning' into 'main'

Resolve "Touching a protected file no longer silences the diff warning"

Closes #1193

See merge request gitlab-org/gitlab-development-kit!2204
......@@ -130,7 +130,6 @@ update-summarize:
#
.PHONY: reconfigure
reconfigure: ensure-required-ruby-bundlers-installed \
touch-examples \
unlock-dependency-installers \
postgresql-sensible-defaults \
all \
......@@ -148,40 +147,6 @@ self-update: unlock-dependency-installers
$(Q)git stash ${QQ}
$(Q)support/self-update-git-worktree ${QQ}
clean-config:
$(Q)rm -rf \
Procfile \
gitaly/gitaly-*.praefect.toml \
gitaly/gitaly.config.toml \
gitaly/praefect.config.toml \
gitlab-pages/gitlab-pages.conf \
gitlab-runner-config.toml \
gitlab-shell/.gitlab_shell_secret \
gitlab-shell/config.yml \
gitlab-spamcheck/config/config.toml \
gitlab/workhorse/config.toml \
gitlab/config/cable.yml \
gitlab/config/database.yml \
gitlab/config/database_geo.yml \
gitlab/config/gitlab.yml \
gitlab/config/puma.rb \
gitlab/config/resque.yml \
gitlab/config/redis.cache.yml \
gitlab/config/redis.queues.yml \
gitlab/config/redis.shared_state.yml \
gitlab/config/redis.trace_chunks.yml \
gitlab/config/redis.rate_limiting.yml \
gitlab/config/redis.sessions.yml \
jaeger \
localhost.crt \
localhost.key \
nginx/conf/nginx.conf \
prometheus/prometheus.yml \
redis/redis.conf \
registry/config.yml \
registry_host.crt \
registry_host.key
touch-examples:
$(Q)touch \
gitlab-shell/config.yml.example \
......
......@@ -38,7 +38,10 @@ module GDK
end
def recover_cmd_string
"cp -f '#{destination_file}' '#{source_file}'"
<<~CMD
cp -f '#{destination_file}' \\
'#{source_file}'
CMD
end
private
......
......@@ -11,6 +11,7 @@ module GDK
BUNDLE_PRISTINE_CMD = 'bundle pristine'
YARN_CLEAN_CMD = 'yarn clean'
GIT_CLEAN_TMP_CMD = 'git clean -fX -- tmp/'
RESET_CONFIGS_CMD = 'make touch-examples reconfigure'
def run(_args = [])
%i[
......@@ -18,6 +19,7 @@ module GDK
gdk_tmp_clean
go_clean_cache
gdk_bundle
reset_configs
gitlab_bundle
gitaly_bundle
gitlab_tmp_clean
......@@ -67,6 +69,10 @@ module GDK
gdk_bundle_install && gdk_bundle_pristine
end
def reset_configs
shellout(RESET_CONFIGS_CMD, chdir: config.gdk_root)
end
def gdk_bundle_install
shellout(BUNDLE_INSTALL_CMD, chdir: config.gdk_root)
end
......
......@@ -11,6 +11,8 @@ module GDK
class ErbRenderer
attr_reader :source, :target
WAIT_WARNING_SECS = 5
def initialize(source, target, args = {})
@source = source
@target = target
......@@ -39,7 +41,6 @@ module GDK
if config.config_file_protected?(target)
warn_not_applied!
wait!
return
end
......@@ -60,25 +61,38 @@ module GDK
private
def warn_changes!(temp_file)
diff = Shellout.new(%W[git --no-pager diff --no-index #{colors_arg} -u #{target} #{temp_file}]).run
diff = Shellout.new(%W[git --no-pager diff --no-index #{colors_arg} -u #{target} #{temp_file}]).readlines[4..].join("\n")
GDK::Output.puts
GDK::Output.info("'#{target}' has incoming changes:")
GDK::Output.warn "Your '#{target}' contains changes. Here is the diff:"
GDK::Output.puts <<~DIFF
diff_output = <<~DIFF_OUTPUT
-------------------------------------------------------------------------------------------------------------
#{diff}
-------------------------------------------------------------------------------------------------------------
DIFF
DIFF_OUTPUT
GDK::Output.puts(diff_output, stderr: true)
end
def warn_not_applied!
GDK::Output.warn "The changes to '#{target}' have not been applied."
GDK::Output.puts <<~NOT_APPLIED
GDK::Output.warn "Changes to '#{target}' not applied because it's protected in gdk.yml."
action_options = <<~ACTION_OPTIONS
- To apply these changes, run:
rm #{target} && make #{target}
rm #{target} && make #{target}
- To silence this warning (at your own peril):
touch #{target}
touch #{target}
-------------------------------------------------------------------------------------------------------------
NOT_APPLIED
ACTION_OPTIONS
GDK::Output.puts(action_options, stderr: true)
GDK::Output.puts("Resuming in #{WAIT_WARNING_SECS} seconds..", stderr: true)
sleep(WAIT_WARNING_SECS)
end
def warn_overwritten!
......@@ -86,21 +100,12 @@ module GDK
GDK::Output.puts <<~OVERWRITTEN
#{backup.recover_cmd_string}
If you want to protect this file from being overwritten, see:
https://gitlab.com/gitlab-org/gitlab-development-kit/-/blob/main/doc/configuration.md#overwriting-configuration-files
-------------------------------------------------------------------------------------------------------------
OVERWRITTEN
end
def wait!
GDK::Output.puts <<~WAIT
... Waiting 5 seconds for previous warning to be noticed.
WAIT
sleep 5
end
def backup
@backup ||= Backup.new(target)
end
......
......@@ -97,7 +97,7 @@ RSpec.describe GDK::Backup do
travel_to(now) do
fake_destination_file = File.join(backups_path, 'Procfile.20210506185031')
expect(described_class.new(fake_source_file).recover_cmd_string).to eq("cp -f '#{fake_destination_file}' '#{fake_source_file}'")
expect(described_class.new(fake_source_file).recover_cmd_string).to eq("cp -f '#{fake_destination_file}' \\\n'#{fake_source_file}'\n")
end
end
end
......
......@@ -39,6 +39,9 @@ RSpec.describe GDK::Command::Pristine do
expect_shellout_command(described_class::BUNDLE_INSTALL_CMD, config.gdk_root).and_return(shellout_double)
expect_shellout_command(described_class::BUNDLE_PRISTINE_CMD, config.gdk_root).and_return(shellout_double)
# reset_configs
expect_shellout_command(described_class::RESET_CONFIGS_CMD, config.gdk_root).and_return(shellout_double)
# gitlab_bundle
expect_shellout_command(described_class::BUNDLE_INSTALL_CMD, config.gitlab.dir).and_return(shellout_double)
expect_shellout_command(described_class::BUNDLE_PRISTINE_CMD, config.gitlab.dir).and_return(shellout_double)
......
......@@ -23,8 +23,8 @@ describe GDK::ErbRenderer do
subject(:renderer) { described_class.new(erb_file.to_s, out_file.to_s, config: config) }
before do
allow(renderer).to receive(:wait!)
allow(renderer).to receive(:backup!)
FileUtils.rm_f(out_file)
end
......@@ -61,8 +61,9 @@ describe GDK::ErbRenderer do
let(:protected_config_files) { ['tmp/*.out'] }
it 'warns about changes and does not overwrite content' do
expect(GDK::Output).to receive(:warn).with(%r{The changes to 'tmp/example.out' have not been applied})
expect(GDK::Output).to receive(:warn).with(%r{Changes to 'tmp/example.out' not applied because it's protected in gdk.yml.})
expect(renderer).to receive(:warn_changes!)
expect(subject).to receive(:sleep).with(described_class::WAIT_WARNING_SECS)
renderer.safe_render!
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment