I am currently working on a project which is under mercurial control and I was looking to get a hook upon update to edit the .htaccess fille to avoid changing the APPLICATION_ENV to fit the "mode" the application should run/load configs/connect to the database.
My repository structure goes as follow :
Main dev repo (ENV : development)
+-- Stable repo (Production version) (ENV : production)
+-- Local dev repo (working version) (ENV : development)
+-- Prototype repo (prototyping repo) (ENV : prototype)
The part of the .htaccess I would like to have edited is the following (the first to lines of the file) :
# Application var
SetEnv APPLICATION_ENV development
I don't mind to run a python script ( or any other language) I am looking to the right hook to put in the .hg\hgrc file
That's not the right thing to do, since that would change the actual file. The next commit you make you would actually commit that change to your repository.
Instead, the recommended approach is to do the following:
Make a template file, and commit that to your repository, ie. .htaccess.template
Add the actual file, .htaccess to the .hgignore file to make Mercurial avoid it
Locally, make a copy from the template file to the actual file, and then edit that
This ensures that changes to the actual file, whatever they may be, will not be committed to your repository.
Some configuration systems also support conditional includes, so that you can something like if extra config file X exists, load X as well, and you would then do the following instead:
Commit the actual file to the repository, but make it bare-bones, containing default values
End the file with such an include-statement
Add the name of the file you're including to the .hgignore file so that you won't commit such a file to the repository
This would ensure that anyone can add to or override the default configuration by adding their own version of that file that will be included.
Related
I have a C# MVC .Net Core application I'm building, the connection string is in a file called appsettings.json so what I want to do is simply exclude this from my git repository. I have added the following line to the git ignore file:
appsettings.json
I have also tried:
**/appsettings.json
But neither seem to work, the change I've made to the appsettings.json file still appears, am I missing something fundamental here?
This is a common misunderstanding about the way .gitignore works we all met at some point when working with Git: .gitignore will ignore all files that are not being tracked yet; indeed, files that are already being tracked in your Git repository are not ignored by your .gitignore setup.
To fulfil your need, it would be sufficient to untrack the files that you desire to ignore, i.e. in your case the appsettings.json file.
As reported in your question's comments, this has been answered already here. Then, your .gitignore setup will work as you would expect.
Adding an entry to your .gitignore file won't remove any files that have already been added to your repository. You need to remove them manually. For this you can use the rm command:
git rm --cached project/appsettings.json
Every answer in this thread misses the point: Being able to ignore changes on a tracked file.
You do not want to completely untrack this file as this would make you send the deletion of the item on the remote next time you push and thus delete the file for every of your collaborators, which you obviously do not want.
What you're looking for is actually perfectly possible in git, while a bit hidden:
git update-index --assume-unchanged <file>
which will precisely ignore the changes on a tracked file.
Now you can modify your appsettings.json file all you want and git won't bother you with it, and won't upload the changes when you push to the remote.
This is the official reference of git look at here
it says:
The purpose of gitignore files is to ensure that certain files not
tracked by Git remain untracked.
To stop tracking a file that is currently tracked, use
git rm --cached
We just switched to Mercurial from SVN. I have some local properties file like jdbc.properties that refers to my local database and is never checked into repository. When I try to pull files Mercurial complains there are uncommited files. How to best deal with this situation
Regards
If you never want to commit jdbc.properties to your repository, you should ignore it.
Check out the link for more information - in short, you'll have to create a text file called .hgignore in your working directory, and input the files names of the files you want to ignore.
Then, you'll never see the files again when you try to commit, and Mercurial won't complain about uncommitted files anymore.
If the application won't work without the config file and you want some version of it in the repository, you might not want to ignore it.
Because if you do, you can't just clone the repository and start your app - it will complain about the missing config file.
Plus, you probably want to have your configuration files under source control as well - just without "secret" data like usernames and passwords.
Maybe this approach is something for you then.
The example shown there is in MS Visual Studio (because that's what I'm using), but you can something similar in any other stack.
I have a file default.config in the root of my repository. I tweaked it for my own setup, and I do not want to commit it. Ever. What are my options other than commit -X "^default\.config$"?
I added ^default\.config$ to .hgignore, but it still shows up in the output of hg status -mard.
Edit: maybe it's possible to do this with Mercurial Queues. If I keep all my local config changes in a single patch, then I just have to remember to pop it before committing. Just thinking out loud...
Follow these steps:
Copy the file somewhere outside your working directory
Remove the file with hg rm default.config and commit the changes
Copy back your file to the working directory
As a good practice you can add a file called default.config.template or something which is committed to the repository. This file holds some kind of default values or comments on how to use it and other users/developers can copy this file to default.config if they're using your project.
Akluth has the correct answer: commit a template file to your repository and then copy that to the real name in each working copy. If the config file supports it, then use an include directive to load the template file from the real config file. Something like
// default.config
//
// load defaults from versioned template file
#include "default.config.template"
// override defaults with my settings
db_hostname = localhost
db_user = me
An alternative is to use -X with every command, as you suggest. There is an exclude extension that implements this idea. Remember to read the caveats — it doesn't work when merging because you cannot exclude files when committing a merge. The extension would need to be extended to handle that case, probably by shelving change before the merge and unshelving it afterwards.
This suggests another stragety, similar to using MQ as you suggest: use the new shelve extension in a set of pre- and post- hooks to shelve/unshelve the file before/after each operation. I think that could work, though I haven't tried it in real life.
I version controlled a project settings folder a couple months back on my default branch, and then over time created many branches off default. Now I've decided that I'd rather not have the project settings folder version controlled as it creates a lot of problems when switching between branches.
So I've hg forget'd this project settings folder which lets me keep the files on my local machine but removes them mercurial. However, when switching from one of the old branches which still have this folder versioned back to the default branch it actually removes the files from the local machine, which is bad.
How do I prevent that?
The folder is also in .hgignore on default now.
It's impossible to do.
But the common practice is to keep config.ini.dist in your repository and build environment-specific config by some build-system right after you check source code out.
The standard way to deal with this is to version control a template config file and ignore the real config file. The real config file can then include the template file, or maybe the template file is copied over once in a while.
The underlying reason for your problems is that running:
$ hg forget config.ini
is exactly the same as running:
$ hg remove config.ini
$ hg cat config.ini > config.ini
The forget command leaves the file behind in your working directory, but what you commit is still a file removal. This means that afterwards, Mercurial cannot distinguish between "file was forgotten" and "file was removed" — only the removal is committed, so the two commands look exactly the same.
I have a project using mercurial for version control, SCons to build, and google test to write unit tests. The hgrc file hooks pre-commit and runs SCons to build the project and and run unit tests. Is there a way to "check-in" a portion of the hgrc file so that newly checked out copies, and any merges with my version of the project automatically get an hgrc file that runs SCons when they try to commit?
You can't get people to automatically have entries in their .hg/hgrc when they clone -- doing so would make it possible for someone to put rm -rf ~ in a commit hook, and wouldn't that be a bummer for the erstwhile cloners.
What you can do is include a file named something like mandatory.hgrc outside of the 'hg directory and then tell cloners to put this line in their .hg/hgrc:
%include ../mandatory.hgrc
Though that's still showing an awful lot of trust in you.
If you control the machines, as in many corporate settings, you can have your package/deployment/update tools (we use puppet) put whatever you want in their /etc/mercurial/hgrc file.
You cannot checking anything under the .hg folder. What my team does it that we have a common mercurial.ini file which as part of the dev box setup we put in our user profile folders.