Created
August 17, 2025 15:20
-
-
Save bensheldon/788d0b8a8f94890f3d444d20dcca8891 to your computer and use it in GitHub Desktop.
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
| <% require_relative File.expand_path("git_worktree", __dir__) %> | |
| default: &default | |
| adapter: postgresql | |
| encoding: unicode | |
| pool: 20 | |
| connect_timeout: 5 | |
| checkout_timeout: 5 | |
| development: | |
| <<: *default | |
| database: myapp_development<%= GitWorktree.db_suffix %> | |
| test: | |
| <<: *default | |
| database: myapp_test<%= GitWorktree.db_suffix %><%= ENV["TEST_ENV_NUMBER"] %> | |
| production: | |
| <<: *default | |
| database: myapp_production |
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
| # config/git_worktree.rb | |
| module GitWorktree | |
| PROJECT_ROOT = File.expand_path("..", __dir__) | |
| def self.name | |
| git_path = File.join(PROJECT_ROOT, ".git") | |
| git_dir = nil | |
| if File.file?(git_path) | |
| contents = File.read(git_path, 1024) | |
| if contents && contents =~ /\Agitdir:\s*(.+)\s*\z/ | |
| git_dir = Regexp.last_match(1).strip | |
| end | |
| elsif File.directory?(git_path) | |
| git_dir = git_path | |
| end | |
| return nil unless git_dir&.include?("/worktrees/") | |
| raw = git_dir.split("/worktrees/").last.split("/").first | |
| sanitized = raw.to_s.gsub(/[^a-zA-Z0-9_]/, "_").downcase | |
| sanitized.empty? ? nil : sanitized | |
| end | |
| def self.db_suffix | |
| worktree = name | |
| worktree ? "_#{worktree}" : "" | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment