Is there any built in mechanism for editing a repository's hgrc config file using the Mercurial API? I'm writing an extension that requires storing some options in the config file, and I'd like to provide a command for do so (the options that need to be stored involve timestamps and would be a little tricky for users to edit manually).
The Mercurial codebase does not provide any automated way to edit hgrc files except when they're first created by a clone operation and then only to set the paths.default setting to the origin.
Related
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 lot of things in my .hgrc file so I keep it in a repository and share it between computers.
I have a lot of extensions enabled in the [extensions] section, but I don't necessarily want to use all of them on all of my computers.
Unfortunately, whenever I try to use Mercurial with my shared .hgrc file on a computer where I don't have every single one of the specified extensions installed, I get a message of the form:
*** failed to import extension evolve from $HG_EXTENSIONS/mutable-history/hgext/evolve.py: [Errno 2] No such file or directory: '/home/botond/programs/mercurial/extensions/mutable-history/hgext/evolve.py'
every time I run any hg command!
Is there a way to avoid this? For example, is there a way to specify in the .hgrc file, "load this extension if you can find it, otherwise don't load it and just be quiet about it"? (Then, if I actually try to use the extension, I'd get an error.)
additional search terms:
How to conditionally enable Mercurial extensions
Activate Mercurial extension based on condition
Enable a Mercurial extension only if it exists
Use Projrc extension
Enable all and any extensions in projrc's config
Disable missing|not needed files in .hg/hgrc
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'm using the Mercurial Convert extension to import data from a PerForce repository. The conversion appears to have worked correctly, but all the Windows line endings (CRLF) were replaced by unix endings (LF).
Is there a way to get this extension to leave the line endings alone?
While the conversion itself may change the eol style, you still can, in your new Hg repo, specify what eol you want to see for certain types of files on checkout:
See EolExtension.
When working with people on different operating systems, it can therefore be desirable to be able to checkout text files with the operating system native line ending representation.
This extension lets you specify how end of lines (EOLs) are converted between the repository representation and the working copy representation.
I was able to do what I wanted using the "Perfarce" extension for Mercurial. The line endings for the mercurial repository will follow the settings of the "LineEnd" property of the Perforce workspace you are using. The steps were the following (on Windows):
Clone the Perfarce repository (https://www.mercurial-scm.org/wiki/PerfarceExtension)
In the mercurial.ini file of your user folder, add the configuration information described https://www.mercurial-scm.org/wiki/PerfarceExtension
Create a Perforce workspace that maps desired parts of the Perforce repository to the root folder for the workspace on the local computer
Update the local workspace
Open a command line at the parent folder of the desired mercurial repository folder
set P4PASSWD=your_perforce_password
set P4USER=your_perforce_username
hg clone p4://perforce_server_ip:perforce_server_port/your_perforce_workspace_name destination_folder
The resulting hgrc file for this repository is set up to pull additional changes from the Perforce repository, so it could conceivably be used on an ongoing basis, but I didn't use that.
I'm new mercurial user. I setup the acl extension adding this into my hgrc file:
[hooks]
pretxnchangegroup.acl = python:hgext.acl.hook
[acl]
sources = serve pull push
[acl.deny]
** = mercurial
So with this code above I deny access to all files to user "mercurial". I successfully tested the acl extension and it works perfectly when I try to push to my central repository on which I put the code above. As expected I receive message that the access for the user "mercurial" is denied.
Now the problem is when I'm start pulling from central repository I don't have any restriction so I can pull anything without any restriction. What I want is to deny pull access for some files like I can do when I tried push comand. Is there any way I can do this?
Mercurial, unlike Subversion, doesn't allow controls on individual files, and for good reason. The DVCS model puts the entire repo on every developer's machine, so even if you restrict files on push and pull, the user could still just hg cat the file to get its contents.
Instead of trying to do this on the client side, I would instead break your repos based on who needs what and set permissions to individual repos. See my answer on the Kiln stack exchange Should I use more than one repository?. You can set permissions via http(s) or SSH, or if you happen to be using Kiln, through our permissions interface.
As came out in the comments with tghw, it sounds like what you really want is partial cloning by filepath, so that a person can clone or pull down only certain files or directories, but that's not possible in Mercurial (or git). That's the case because every revision is identified by a unique hash that includes, among other things, the hash of all the file changes. If you don't have all the files, you don't have all the changes, and you can't verify the hash.
If you really need to hide read access for some files from some people you'll need to split them up into separate repositories.
I have a solution:
convert your repo to git:
https://git.wiki.kernel.org/index.php/Interfaces,_frontends,_and_tools#Mercurial