Reputation: 225
I'm using git post-receive hook to deploy versions of the web application from three branches (master, staging, and stable) on three servers (development, testing and production). The pairing between branches and servers is currently hard-coded in the script. However I'd like to remove this restriction and make this hook possible to manage unlimited quantity of branches. It can be done in the following way:
.git/???/<branch_name>
However I don't know where exactly in .git
directory can I place such files. Or maybe there is a better solution?
Upvotes: 2
Views: 1381
Reputation: 496902
Your options, as far as I can tell:
Use a stronger convention for server naming, so that config isn't necessary, beyond the base domain name. Leave that in the script. (That is, branchX -> branchX-deploy.example.com.)
Put a config file wherever you feel like in the .git directory, like you suggested. If it's not a filename git cares about, it'll never notice it. I'm not sure why you'd want to do this, though.
Put it in .git/config. Git lets you define arbitrary config parameters of the form branch.<name>.foo
. (I have no idea if this is a feature or an oversight. It's not documented, as far as I know.) In your case, something like branch.master.deploy_server
set to development.example.com
. Your script could then just go through all branches, and check whether that config option is set or not. (Use git config --get
.)
Put a config file in your repository. This seems a lot better than hiding it away. You might as well track the settings. If necessary, provide a way to override them - supply a different config file as an argument, supply individual branches/servers as options, interactive prompts, whatever suits you.
Personally, I'd probably do the last one. Tracking settings, even if they're only default settings, can't hurt you.
Upvotes: 2