I have an repository for an app that I\'m working on that includes a configuration file. Currently, I distribute with a .dist
extension, and have the user rename th
As others have pointed out, there is no magical solution for this in Git. And as far as I know, it's the same with other version control systems.
Hooks are also of no solution here, if they would work this way, that would be a serious security threat - just by cloning a repo, an evil code could execute in your machine.
But to use your app, the user has to do at least one more thing besides cloning it with git: running your app.
If modifying the config file is not required for running the application, then if your program does if [ ! -e config ] ; then cp config.dist config ; fi
on startup, then that should be IMHO quite enough. Additionally you should have warning inside config.dist
which says you shouldn't modify this file, but make a copy of it instead.
If the modification of config file is required, then starting the program without config file could start up some installation mode, that asks the user to enter the needed configuration options and saves them.
A third possibility is that your app is unable to modify the config file when it starts up (maybe it's just some JavaScript + HTML files). In that case I see no other option than to have some separate build script or let the user just manually do it.
This is a good question, but AFAIK there is no git solution for this.
Few workarounds:
config.dist
when config
is not present (e.g. PHPUnit uses this technique)You can also version and distribute:
.gitattributes
files declaring a filter driver (for only 'config.dist')config
file)Now that is bending a bit what a filter driver is about (it is about modifying the content of a file, regardless of its "state", i.e its full path and name). But it can work.
The .gitattributes
would contain:
config.dist filter=generateConfig
And you can register your smudge script (applied during the checkout step when creating/updating the working directory) like:
git config --global filter.generateConfig.smudge /path/to/generateConfig
I'd probably include an 'install' script of some sort that copied 'config.dist' to 'config'.
I don't think there's a way to have a file both not-ignored and ignored.