Specific Version Configurations

I want to work from several places - for example, on a website. Each PC has its own project repository (preferably Mercurial, Git otherwise), but each computer needs its own configuration settings for testing locally, for example base_url. What is the best option for a version of this configuration file that will also contain global configuration settings?

Repository Information:

  • BitBucket repo with config.php: global configuration + configuration for live server.
  • Repo pc A with config.php: global configuration + configuration for PC A
  • Repo pc B with config.php: global configuration + configuration for pc B

When I check the BitBucket repository, I get the full live server configuration. If I need to make corrections and test them locally, I change the settings in real time to specific PC settings. Then fix the error or something else, commit and click on BitBucket. At the moment, the settings for a specific computer will be redirected to the global BitBucket repository: not what I want.

So what is the best way to do this right?

+4
source share
3 answers

I am not very familiar with php, but I assume that you can have a global config.php file that can include (require?) config.<hostname>.php files. Thus, all configuration files will be under version control, but there will be no conflicts. PHP should have some way to determine the host name of the current computer and then load the appropriate configuration file.

The resulting repository will look like this:

 / /config.php /config.web_server.php /config.pc_A.php /config.pc_B.php 
+1
source

What you need is a smudge clean script that changes the configuration depending on which machine you are on.

https://git-scm.com/docs/gitattributes

https://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes#_keyword_expansion

If you want to track each PC configuration in a separate branch, make changes in the config, and then merge your changes into the branch that you opened on the general console, but ignore your change

 git merge --no-ff -s ours yourbranch 

Now you can merge from your branch, but your configuration change will never be merged, because it is already considered merged in accordance with the DAG.

Hope this helps.

+3
source

I would plan config.php to be transparent. The repository itself does not have to care about the environment in which it works. I don’t know what you need to change in order to start and run in your case, but perhaps cancel the functionality from your config.php into some settings, which in turn are read by config.php.

0
source

All Articles