{ "uuid": [ { "value": "c61f3ce9-54c7-4b07-9e44-7affd7d16e5b" } ], "langcode": [ { "value": "en" } ], "type": [ { "target_id": "daily_email", "target_type": "node_type", "target_uuid": "8bde1f2f-eef9-4f2d-ae9c-96921f8193d7" } ], "revision_timestamp": [ { "value": "2025-05-11T09:00:57+00:00" } ], "revision_uid": [ { "target_type": "user", "target_uuid": "b8966985-d4b2-42a7-a319-2e94ccfbb849" } ], "revision_log": [], "status": [ { "value": true } ], "uid": [ { "target_type": "user", "target_uuid": "b8966985-d4b2-42a7-a319-2e94ccfbb849" } ], "title": [ { "value": "One more \"run\" command, for Git worktrees" } ], "created": [ { "value": "2022-08-17T00:00:00+00:00" } ], "changed": [ { "value": "2025-05-11T09:00:57+00:00" } ], "promote": [ { "value": false } ], "sticky": [ { "value": false } ], "default_langcode": [ { "value": true } ], "revision_translation_affected": [ { "value": true } ], "path": [ { "alias": "\/daily\/2022\/08\/17\/one-more-run-command-git-worktrees", "langcode": "en" } ], "body": [ { "value": "\n

Here's another run<\/code> file example, this time relating to Git worktrees...<\/p>\n\n

One project that I work on is a multilingual Drupal application that needs to work in both English and Welsh. As I'm cloning a fresh version today, I'm doing it as a bare repository so I can use worktrees.<\/p>\n\n

To work on it locally, just like in production, I need to use a different URL for each language so that Drupal can identify it and load the correct content and configuration.<\/p>\n\n

For fixed environments like production or staging, the URLs are set in configuration files, but for ad-hoc environments such as local worktrees, I thought that the best approach was to override them as needed per worktree using Drush (a Drupal CLI tool).<\/p>\n\n

I could do this manually each time or I could automate it in a run<\/code> command. :)<\/p>\n\n

Here's the function that I came up with:<\/p>\n\n

function drupal:set-urls-for-worktree {\n  # Set the site URLs based on the current Git worktree name.\n  local worktree_name=\"$(basename $PWD)\"\n\n  local cy_url=\"cy-projectname-${worktree_name}.docker.localhost\"\n  local en_url=\"projectname-${worktree_name}.docker.localhost\"\n\n  # Update the URLs.\n  drush config:set language.negotiation url.domains.cy -y $cy_url\n  drush config:set language.negotiation url.domains.en -y $en_url\n\n  # Display the domains configuration to ensure that they were set correctly.\n  drush config:get language.negotiation url.domains\n}\n<\/code><\/pre>\n\n

It builds the worktree URL for each language based on the directory name, executes the configuration change, and finally displays the updated configuration so I can confirm that it's been set correctly.<\/p>\n\n

This is a good example of why I like using run<\/code> files and how I use them to automate and simplify parts of my workflow.<\/p>\n\n ", "format": "full_html", "processed": "\n

Here's another run<\/code> file example, this time relating to Git worktrees...<\/p>\n\n

One project that I work on is a multilingual Drupal application that needs to work in both English and Welsh. As I'm cloning a fresh version today, I'm doing it as a bare repository so I can use worktrees.<\/p>\n\n

To work on it locally, just like in production, I need to use a different URL for each language so that Drupal can identify it and load the correct content and configuration.<\/p>\n\n

For fixed environments like production or staging, the URLs are set in configuration files, but for ad-hoc environments such as local worktrees, I thought that the best approach was to override them as needed per worktree using Drush (a Drupal CLI tool).<\/p>\n\n

I could do this manually each time or I could automate it in a run<\/code> command. :)<\/p>\n\n

Here's the function that I came up with:<\/p>\n\n

function drupal:set-urls-for-worktree {\n  # Set the site URLs based on the current Git worktree name.\n  local worktree_name=\"$(basename $PWD)\"\n\n  local cy_url=\"cy-projectname-${worktree_name}.docker.localhost\"\n  local en_url=\"projectname-${worktree_name}.docker.localhost\"\n\n  # Update the URLs.\n  drush config:set language.negotiation url.domains.cy -y $cy_url\n  drush config:set language.negotiation url.domains.en -y $en_url\n\n  # Display the domains configuration to ensure that they were set correctly.\n  drush config:get language.negotiation url.domains\n}\n<\/code><\/pre>\n\n

It builds the worktree URL for each language based on the directory name, executes the configuration change, and finally displays the updated configuration so I can confirm that it's been set correctly.<\/p>\n\n

This is a good example of why I like using run<\/code> files and how I use them to automate and simplify parts of my workflow.<\/p>\n\n ", "summary": null } ], "feeds_item": [ { "imported": "1970-01-01T00:33:45+00:00", "guid": null, "hash": "1d0346a7d6dd5cac3b65b148563e58b2", "target_type": "feeds_feed", "target_uuid": "90c85284-7ca8-4074-9178-97ff8384fe76" } ] }