Created
December 4, 2025 22:22
-
-
Save dpaluy/0b6e6f9b46e1aba6a618f9f46d19d94d to your computer and use it in GitHub Desktop.
Merge Rails encrypted credentials
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require 'open3' | |
| environment = ARGV[0] || 'default' | |
| creds_path = "config/credentials#{environment == 'default' ? '' : '/' + environment}.yml.enc" | |
| puts "\n=== Merging credentials conflict for #{creds_path} ===\n" | |
| # Extract both versions | |
| `git checkout --ours #{creds_path}` | |
| ours = `rails encrypted:show #{creds_path} 2>/dev/null || rails credentials:show -e #{environment} 2>/dev/null` | |
| File.write('tmp/ours.yml', ours) | |
| `git checkout --theirs #{creds_path}` | |
| theirs = `rails encrypted:show #{creds_path} 2>/dev/null || rails credentials:show -e #{environment} 2>/dev/null` | |
| File.write('tmp/theirs.yml', theirs) | |
| # Show visual diff | |
| puts "Your version (ours) vs Incoming (theirs):" | |
| puts `diff -u tmp/ours.yml tmp/theirs.yml || true` | |
| puts "\n" | |
| # Open editor for manual merge | |
| `rails credentials:edit -e #{environment}` | |
| puts "Credentials merged and encrypted. Stage with: git add #{creds_path}" | |
| `rm tmp/ours.yml tmp/theirs.yml 2>/dev/null` |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add to
bin/merge_credentials.shchmod +x bin/merge_credentials.shUsage: