Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I track system-specific config files in a repo/project?

I have a ruby project, and the database host and port might be different on dev and production. I need a way to get different values for those into my scripts for the two environments.

The project should be complete - so there should be some way to specify default values. I don't want a clone to be missing the config files. So ignoring them completely won't work.

How do you solve this problem with git?

like image 859
Sean Clark Hess Avatar asked Jan 28 '10 13:01

Sean Clark Hess


1 Answers

I would recommend using:

  • a template config file (a file with variable name in place of the host and port value)
  • a script able to replace those variable names with the appropriate values depending on the environment (detected by the script)

The Git solution is then a git attribute filter driver (see also GitPro book).

A filter driver consists of a clean command and a smudge command, either of which can be left unspecified.
Upon checkout, when the smudge command is specified, the command is fed the blob object from its standard input, and its standard output is used to update the worktree file.
Similarly, the clean command is used to convert the contents of worktree file upon check-in.

That way, the script (managed with Git) referenced by the smudge can replace all the variables by environement-specific values, while the clean script will restore its content to an untouched config file.

clean smudge

When you checkout your Git repo on a prod environment, the smudge process will produce a prod-like config file in the resulting working tree.

like image 172
VonC Avatar answered Sep 19 '22 16:09

VonC