0

Scenario:
For each branch, I am using a different development database. The reason is that the schema might differ, depending on what work has been done on the branch.
This is straight forward, I simply change the connection string in the app.config.
However, this has the problem, that those changes - when committed - get merged back into the parent branch when I perform a merge, effectively overwriting the app.config of that parent branch.
Still, I want this changed app.config in my repository, so that Ican simply check out a branch and have the correct app.config. So, git update-index --assume-unchanged is not a solution.

Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443

2 Answers2

0

The solution to this problem is .gitignore. Environment of host specific settings should not be sharing the repository with the sources. The standard approach is to add app.properties to .gitignore and never commit; instead put app.properties.template from which the app.properties could be setup on a specific environment, or app.properties.default from where the defaults would be read.

Mykola Gurov
  • 8,517
  • 4
  • 29
  • 27
  • Thanks for your answer, but it is absolutely not answering my question. As I said, I automatically want those settings to switch when I switch my branch. If you know a way without committing the app.config to git, that's fine, but the switch needs to be automatic. – Daniel Hilgarth Oct 14 '15 at 19:48
  • OK, didn't get the question in full. The best solution IMHO would still be to externalize the schema into an env variable or scripts, otherwise you could stil hack away by splitting the config into two files `app.properties` and `schema.properties`, setting needed schemas in corresponding branches and making the app to read from both files. This way you won't have to change the `schema.properties` when switching between branches. You will still have to take extra care about this file when doing merges so that the right schema end up at the right branch. – Mykola Gurov Oct 14 '15 at 19:56
0

I have a solution but it is not automatic. Partly perhaps because of git but also because ignoring a complete file like that is not the right approach - what if you have made some other changes to app.config that you do want to merge?

Let me first see if I understand your problem correctly. You develop some feature on a branch, which when finished gets merged into some other "main" branch. While doing this development you make some temporarily changes that are not supposed to be included when finished. Specifically you mention database connection strings in app.config, but in the general case it could be anything like extra logging, skip calling certain functions, etc. You want to have everything checked in and stored in git so that there are no loose ends with modified files not checked in.

Assuming my understanding is correct, here is how I handle this: while developing I just add a given prefix and/or postfix (say ====) to the commit message of those commits that should not be merged, and then remove those commits at the end before doing the final merge.

So you end up with a commit history when done that looks like

* blah blah blah
* ==== Remove extra extra logging again ====
* blah blah blah
* ==== Extra extra logging ====
* blah blah blah
* blah blah blah
* ==== Extra logging ====
* ==== Skip calling whatever_function ====
* blah blah blah
* ==== Change database connection string ====
* blah blah blah

where it is trivial to remove those temporarily changes (this can probably be automated). You do have to change you work flow a tiny bit, but the benefits are absolutely worth it.

You can also see this answer where I described the same solution before with some more details and screenshots.

Community
  • 1
  • 1
hlovdal
  • 26,565
  • 10
  • 94
  • 165