diff options
| author | Kasper Timm Hansen <kaspth@gmail.com> | 2019-08-04 02:19:55 +0200 | 
|---|---|---|
| committer | Kasper Timm Hansen <kaspth@gmail.com> | 2019-08-04 02:19:55 +0200 | 
| commit | f1f5024b918ecf303b9908f78d1a6136d9418730 (patch) | |
| tree | 2e35bb48205daddbf6c5f02fdfbf8a39ffa23867 /railties/lib/rails/commands/credentials/credentials_command | |
| parent | 03e44f93001db97953917e0a100c627e189e2be6 (diff) | |
| download | rails-f1f5024b918ecf303b9908f78d1a6136d9418730.tar.gz rails-f1f5024b918ecf303b9908f78d1a6136d9418730.tar.bz2 rails-f1f5024b918ecf303b9908f78d1a6136d9418730.zip | |
Revise flow to what was described in 03e44f9
Diffstat (limited to 'railties/lib/rails/commands/credentials/credentials_command')
| -rw-r--r-- | railties/lib/rails/commands/credentials/credentials_command/diffing.rb | 43 | 
1 files changed, 27 insertions, 16 deletions
| diff --git a/railties/lib/rails/commands/credentials/credentials_command/diffing.rb b/railties/lib/rails/commands/credentials/credentials_command/diffing.rb index b7330178a3..1d34c68074 100644 --- a/railties/lib/rails/commands/credentials/credentials_command/diffing.rb +++ b/railties/lib/rails/commands/credentials/credentials_command/diffing.rb @@ -1,30 +1,41 @@  # frozen_string_literal: true  module Rails::Command::CredentialsCommand::Diffing # :nodoc: -  class Error < StandardError; end - -  def enable_diffing -    if enabled? -      say "Already enabled!" +  def enroll_project_in_credentials_diffing +    if enrolled? +      true      else -      enable -      say "Diffing enabled! Editing a credentials file will display a diff of what actually changed." +      gitattributes.write(<<~end_of_template, mode: "a") +        config/credentials/*.yml.enc diff=rails_credentials +        config/credentials.yml.enc diff=rails_credentials +      end_of_template + +      say "Project successfully enrolled!" +      say "Rails ensures the rails_credentials diff driver is set when running `credentials:edit`. See `credentials:help` for more."      end -  rescue Error -    say "Couldn't setup Git to enable credentials diffing." +  end + +  def ensure_rails_credentials_driver_is_set +    set_driver if enrolled? && !driver_configured?    end    private -    def enabled? +    def enrolled? +      gitattributes.read.match?(/config\/credentials(\/\*)?\.yml\.enc diff=rails_credentials/) +    rescue Errno::ENOENT +      false +    end + +    def driver_configured?        system "git config --get diff.rails_credentials.textconv", out: File::NULL      end -    def enable -      raise Error unless system("git config diff.rails_credentials.textconv 'bin/rails credentials:diff'") +    def set_driver +      puts "running" +      system "git config diff.rails_credentials.textconv 'bin/rails credentials:diff'" +    end -      Rails.root.join(".gitattributes").write(<<~end_of_template, mode: "a") -        config/credentials/*.yml.enc diff=rails_credentials -        config/credentials.yml.enc diff=rails_credentials -      end_of_template +    def gitattributes +      Rails.root.join(".gitattributes")      end  end | 
