开发者

Versioning machine specific configs

开发者 https://www.devze.com 2023-02-28 09:07 出处:网络
I want to work from several locations on -for instance- a website. Every pc has its own repository of the project (preferably Mercurial, Git otherwise), but each computer needs its own config settings

I want to work from several locations on -for instance- a website. Every pc has its own repository of the project (preferably Mercurial, Git otherwise), but each computer needs its own config settings for testing locally, like base_url. What is the best way of versioning this config fil开发者_StackOverflow中文版e which will include global config settings as well?

Repository details:

  1. Repo on BitBucket with config.php: global config + config for live server
  2. Repo pc A with config.php: global config + config specific for pc A
  3. Repo pc B with config.php: global config + config specific for pc B

When I checkout BitBucket repository I get the full live server configuration. If I need to make adjustments and test it locally, I change the live settings to the pc specific settings. Then fix a bug or whatever, commit and push to BitBucket. At this moment the pc specific settings will get pushed to the global BitBucket repo: not what I want.

So what's the best method to get this done properly?


What you need is a smudge clean script that changes the config depending on what 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's config in a separate branch, do the change to the config, then do a merge of your changes into the branch you have exposed in the common remote, but ignoring your change

git merge --no-ff -s ours yourbranch

From now on you can merge from your branch but your config change won't ever be merged as it is already considered having been merged according to the DAG.

Hope this helps.


I'm not very familiar with php, but I assume you could have a global config.php file which could include (require?) config.<hostname>.php files. This way all the config files would be under version control, but there would be no conflicts. PHP should have some way of determining the hostname of the current machine and then loading the appropriate config file.

The resulting repository layout might look like this

/
/config.php
/config.web_server.php
/config.pc_A.php
/config.pc_B.php


I would design config.php to be transparent. The repository itself shouldn't have to care about in what environment it's running on. I don't know what you need to change in order to get this up and running in your case, but perhaps lift out functionality from your config.php into some settings that is in turn read by config.php.

0

精彩评论

暂无评论...
验证码 换一张
取 消