How do I configure Mercurial to not commit specific config files?
Asked Answered
L

2

6

My team is switching to Mercurial. Our projects all have a config file (web.config or app.config, and a few bat files as well - we are a C# shop). These files need to be part of the repository. When a developer clones the repository, local changes are needed to their config files to get them working. For example, a project's config file may need a connection string to the developer's database, or other environment-specific info. We don't want these changes ending up in the repository. And from time to time we do make changes to these configs that do need to get into the repository and distributed to the team and eventually the customer.

What is the easiest way for us to configure or use Mercurial so that these files are not getting committed by accident? I would like to be forced to make an explicit commit of such files, yet merges from the repo would automatically come down in updates.

This has to be a problem someone else has faced, but as Mercurial newbies we are all at a loss for the best solution.

Edit:

A similar question that may share some common solutions, but is not the same as this question, can be found at: Conditional Mercurial Ignore File

I am including this in case that other question might provide the answer you are looking for.

Lemuelah answered 12/1, 2011 at 22:6 Comment(3)
possible duplicate of Conditional Mercurial Ignore FileClearstory
If you read the two questions they are not the same. They are different questions that may share some common solutions. I am going to go ahead and edit my question to point over to the other question as a related question.Lemuelah
Duplicate of [ Mercurial Workflow Question - How to handle config files](#1379453). Solution appears very different though.Retool
T
6

The typical way to handle this is to store templates for the configuration files in your repositor, and add the actual configuration files to the ignore list in Mercurial.

This way, you have pristine, unmodified, copies of each configuration files available at all times, even for new developers who clone from scratch, but in order to make the configuration files usable, you need to make a local copy of it to the actual configuration file name, and modify the file. You could also use compare/merge programs, such as Beyond Compare, to compare a new version of the template file with your local copy of an older version, to see what changed, and add in the missing bits.

If you need to hard prevent committing the actual configuration files, you need a pre-commit or pre-push hook that does this.

Thomasson answered 12/1, 2011 at 23:36 Comment(2)
I liked your idea and upvoted it. We discussed it, but came up with a different solution. Thanks for the answer. It gave us yet another option to consider.Lemuelah
And you mean that you will have a non-compiling project?Nork
S
2

In your .hg/hgrc file do this:

[defaults]
commit = -X Projectname/web.config

(assuming "ProjectName" is the project subdir)


Edit:

Also, if you're using Tortoise HG - add this as well:

[tortoisehg]
ciexclude = Projectname/Web.config,Projectname/App_Data/DBFile.mdf

(by the way mind the FORWARD slash in folder-path! Even on Windows!)

Sheeting answered 16/12, 2013 at 14:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.