Reputation: 2842
So I was searching for a way to handle the configurations file in a git projet. I read some articles about the subject but all of them where suggesting a second, local-only file. And that doesn't feel right to me.
So I messed around with some of the git commands to find a way to achieve things another way.
A way I found this could be possible may be like this :
The config for the example is a simple key : value
list inside a file.
The local
state is the lastest pulled version of the template :
1 : 1
2 : 2
3 : 3
The remote
state is the version on the repository :
1 : 1
a : 2
3 : 3
4 : 4
On this file I have one new field : 4
and a modified field a
.
Finally the working
state is the configuration file used by the application. It is a copy of the local
file modified with the secret values for running the application. This version should not be pushed to the repository.
1 : secret1
2 : secret2
3 : secret3
Here is the workflow I thought about :
On pull
/checkout
:
working
file into a separate file to prevent being rewritten;local
and the remote
to get the last configuration template; local
and the saved_working
.The last merge should provide user a display for the new field to add, as long as not overriding the existing fields values.
An example of such operation may be :
1st merge :
- 2 : 2
+ a : 2
+ 4 : 4
2nd merge :
1 : secret1
- 2 : secret2
+ a : 2
3 : secret3
+ 4 : 4
And now, before being able to use the application again, we clearly see the lines to changes.
What do you think ?
Upvotes: 1
Views: 287
Reputation: 3025
I'd recommend you to think thoroughly WHY you do need to store config file in the repo? If that's some default option set then it probably should be integrated into project (maybe compiled into binary; IDK what your project is). If that's a sample option set then you needn't using it in your working tree so just ignore it when pulling. Anyway the software shouldn't be unusable when config file is missing, it should have some default values therefore you won't need to merge your working config with the repo's version.
I used to keep my configs in the repo but later changed my mind and removed all these commits. Config is a changeable state referring to user preferences; code repo is for storing the history of the code. Mixing these two subjects seems bad practice to me.
upd
If you don't want to support upgrading config from older verison to a recent one there is just one way I can imagine:
So every time a dev pulls from remote repo, the config tool would be updated too and then launched. Tool committed in a revision upgrades actual config file from exactly the previous version to a recent version that was introduced in this revision. Obviously plain text tool is more preferable here (for tracking changes) but binary will work too.
Upvotes: 0
Reputation: 3410
I think an application should be able to read many configuration files, and only a default configuration file should be stored in the repository; for example:
Some projects (like ansible with Vault) store an encrypted version of the configuration file, that could be a solution too.
Would it work for your setup?
Another suggestion would be a separate branch where you cherry-pick the code or the configuration, depending your preferences.
Edit: precisions about cherry picking.
This was just a suggestion, it's like your toughs about merging, except you choose which commits you want to get from the "remote".
On your machine, working in the local
branch:
git fetch
git merge master
or git cherry-pick
the commits you wantNothing ground-breaking, I'm not sure if you expect the operation to be automated or manual.
Upvotes: 1