Conditional Mercurial Ignore File
Asked Answered
A

4

6

I have a file in mercurial that I want dev machines to pull the file, but I want the deployment server to NOT pull the file (it has special mods to it that the dev machines don't have). Is this possible, or should I just have a custom push to server solution instead of just doing an hg pull?

Aloisia answered 21/12, 2010 at 17:26 Comment(0)
P
6

A typical way to do this would be to do the following:

You store a copy of each file in the repository, and name them correctly. For instance, if the file in question is web.config, you would store the following two in the repository:

  • web.server.config
  • web.dev.config

Then you would add a built step to ensure the right file was copied to the actual web.config file, you could use a batch file:

if "%COMPUTERNAME%" == "SERVER" copy web.server.config web.config
if not "%COMPUTERNAME%" == "SERVER" copy web.dev.config web.config

Then you would ignore web.config itself through .hgignore:

glob:web.config
Perjury answered 21/12, 2010 at 18:15 Comment(0)
D
2

A variant of Karlsen's answer that I always use.

I have /config or /etc directory in the project. That directory will often contain sample configs like:

  • dev.yaml
  • ci_server.yaml

Then my apps pull from /etc/app.yaml which is a symlink to the correct config depending on the host it's being run on.

The best think about doing it this way is you don't have variant code paths (the batch script branches) which eliminates a potential bug vector. This allows you to exercise the same code path that will be used in production (down to where to look for the override file).

Dreadfully answered 4/1, 2011 at 6:49 Comment(0)
E
1

Is this something that can be solved outside version control? For instance, include the file in all copies of the repository, but enable or disable its use with environment variables or something similar. This doesn't sound like something most version control systems are built to handle, unless you use nasty hacks to do things like add/remove/patch files after updating.

Elasmobranch answered 21/12, 2010 at 17:57 Comment(1)
I agree, but this file is necessary both on the server and on the dev machines. It is a settings file with paths to web urls/db connection strings/etc, and these values are different on the server than the dev machines.Aloisia
A
1

One option is to create a special hgignore file for the deployment server, that could or could not be included in the repository. Then in the server's hgrc file specify the path to the special hgignore file with the ignore variable.

This would ensure that updates to file would be ignored by the deployment server but could still be updated as usual for the development machines.

Animate answered 3/1, 2011 at 1:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.