Is there a way to use the hg commit command only when filenames are supplied?
This should work:
hg commit file1 file2
This should not:
hg commit
I don't want people to mistakenly commit files that aren't supposed to be commited.
Is there a way to use the hg commit command only when filenames are supplied?
This should work:
hg commit file1 file2
This should not:
hg commit
I don't want people to mistakenly commit files that aren't supposed to be commited.
I'm not sure whether this is possible but it sounds like something is wrong with your workflow and/or knowledge of Mercurial so I am going to answer with how this problem is usually managed in Mercurial.
What do you mean when you say "commit files that aren't supposed to be committed"? I can get one of two meanings for that phrase:
If it's the first then you should either move the files out of the working copy or you should add them to the .hgignore
file. This file is used to specify files (or file pattens such as *.obj
) which should ignored by commands such as hg status
and hg commit --addremove
.
If it is the second then you and your team should review the changes that they have made before they commit them. They should use hg status
to check which files have been changed and then use hg diff
if they see anything that they might not have intended to commit. This is easier if you get into the habit of committing more frequently by only fixing one problem at a time or by breaking new features down into stages and commit after each stage.
Another possible problem is that you have a configuration file which would frequently be changed by the developer but shouldn't be committed to the repository. The typical solution to this problem is that you have a template configuration file in the repository that each person needs to copy to the correct name when they clone the repository.
If your working directory contains more than one specific change (the only reason I can think to commit only specific files), then it's possible that a single file may contain several changes - some you want to commit and some you don't.
Rather than limiting which files should be checked in, maybe you should consider using something like the Record extension or Shelve. Both allow you to specify which specific changes get committed, but in slightly different ways (I think Record would probably suit your need).
Personally however I would consider changing your workflow to make small changes and commit regularly. Your question suggests that you are trying to use Mercurial in an almost file-based way (à la CVS (or Subversion?)), whereas Mercurial is changeset-based, treating the state of the repository as a whole.
It's pretty simple, actually. You can do it by defining commit as an alias to itself, but with an explicit argument. In the [alias]
section of your hgrc file, add the following:
commit = commit $1
This can still handle multiple arguments: They are simply appended to the end of the alias expansion. But if you try to commit without an argument, you'll get an error similar to this:
abort: $1: No such file or directory
With a more elaborate alias you could give your own error message.