I know there is a way to get mercurial to ignore specific files using hgignore.
Is there a way to get it to ignore all files above a certain size?
Thanks
Clever notion. There's no built-in functionality for that, but you could rig up something like:
find -type f -size +10M > .hgignore
You could run that in a precommit hook, but you'll want to delete the lines from the previous entry.
Unfortunately matching in .hgignore is done just by filenaming. However, nothing prevents you from writing a pre-commit hook that autocreates (appends) .hgignore files based on their size.
Related
I am trying to display the diff of each changed file in a changeset, using a template.
What I need is something very similar to "hg diff" command. I cannot find anything which might serve my purpose in the help here
To add context, I am trying to use this template in Bugzilla extension. I need to add the diff of the changes which went in to bugzilla ticket.
You can use diff() pattern
(extract from hg help templates - better than URL referenced by you)
- diff([includepattern [, excludepattern]])
You if you don't specify any patterns, it will simply give you the equivalent of hg log -p. If you want to print diff per file, you will need to pass explicit filenames as includepattern parameter, like
hg log -r tip --template "{diff('mercurial/bundlerepo.py')}"
Looping through the list of files (like "{files % '{file}'}" in templates help) seems broken in this case (well, I didn't manage to make it work). Probably it's a bug, so you can write to mercurial discussion list to get confirmation.
Anyways, to get more luxury support, better to write to mercurial discussion list, or join #mercurial IRC and ask :)
Also they will guide you on how to achieve what you are trying to do in better way - seems you are trying to reinvent something
Just made the mistake of using addremove to try and remove some files that were deleted without using hg remove
Now have hundreds of files that are going to be added on the next commit
Is there anyway I can quickly remove all these added files without having to resort to a bash script or even worse hg removing or forgetting each file manually?
If you want to just use internal hgcommands, you can do the following:
hg forget "set:added()"
Which will forget any file that's marked as "added" in the working directory. It makes use of the rather powerful filesets feature of Mercurial.
There are additional filters you can use when specifying files, which allows you to easily fix other mistakes. For example, easily re-add removed files but nothing else hg add "set:removed()". The functionality is similar to (tho' thankfully simpler than) mercurial revsets, and can be studied with:
hg help filesets
You do it quite easily on the command line using something along the lines of :
hg status --added --no-status | xargs hg forget
This should forget all files added since the last commit.
May I suggest to add the files you never want to add to a .hgignore file so this won't happen again ?
I'm using Mercurial to read and debug a complex project, and my modify of the project can be divided into different group of files clearly. For example, if I modified four files
src1.cc src1.hh src2.cc src2.hh
It's apparent that I can divide them into two file groups such as group src1 includes src1.cc src1.hh and group src2 includes src2.cc src2.hh.
I'm wondering if I can revert a group of files by a simple command like 'hg revert group-name-alias' instead of listing all the filename of the group, which is a awful idea if I have modified many files?
Any help really appreciated!
From what I can understand of your use-case, you can:
Use patterns in the hg revert command. This means that you can
run hg revert src1* to revert all the first group.
Most probably, though, your stuff is in sub-folders and thankfully
you can specify a parent folder to the revert command.
So say your files are really like: foo/src1.cc, foo/src1.hh,
bar/src2.cc, bar/src2.hh. In that case, you can revert all the
second group with hg revert bar, assuming you're in the top folder.
If you're already in the bar folder, you can run hg revert ..
You can specify several patterns.
Use Mercurial queues if each one of your "file groups" is also
a different unit of work (a different bug fix or feature). This is not
so desirable if all files belong to the same unit of work, though.
No. To the best of my knowledge, Mercurial has no mechanism for grouping files.
You could do some trickery with aliases ([alias] revert-group-name = revert src2.cc src2.hh in ~/.hgrc), but aliases can only be prefixes, and can't perform variable expansions.
If your files are simple enough, you could use shell globbing (hg revert src2*), or a shell variable (GROUP_NAME="src2.cc src2.hh", then hg revert $GROUP_NAME).
You could also consider writing a small Mercurial extension. If you know Python, they don't take very long (my first took me about 30 minutes).
If the filenames meet patterns, you can use that pattern:
hg revert src1*
or
hg revert src1*.*
If those files are in a specific directory, you can do this:
hg revert dir\*
If the directory is more than one level deep and you want to get that directory and all its subdirectories, you can use this version of that commend:
hg revert dir\**\*
I'm working in a code base that already has a lot of "TODO" comments, and before I push my changeset(s) I want to make sure I haven't left any of my TODO comments in there (rather than actually doing it, or adding it to the new-feature database and removing the comment).
At the moment I'm just using "TODO: Wilka" in each of the comments, so it's easy to search for. But is there a way with Mercurial I can search for "TODO" only in the files that have changed in a collection of changesets? Ideally, it would only search the lines that have actually changed - but even just the files would be good.
to search a specific set of revisions you could do:
hg grep -r 0:3 "\bTODO:"
Diff between wanted revisions piped to the grep, only modified files file be searched with the grep
hg diff -r 100:105 | grep TODO
EDIT:
As mentioned in the comments, this is presumes that grep is installed (so non Windows enviroment)
#thanks Tim, if using Windoes, use findstr instead of the grep
The automated way is via Mercurial commit hooks. The examples may be helpful as might the checkfiles extension referred to by mercurial developers.
In my experience, commit hooks are a mixed bag and often do what you want but are irksome when you really want to commit a TODO. The Shelve extension attempts to work around this, but the cure can be worse than the problem.
I haven't explored the possibility of something like hg com --but-ignore-my-TODO-hook which could be nifty.
I'm managing $HOME using Mercurial, to keep my dotfiles nice and tracked, or at least the ones that matter to me.
However, there's a profusion of files and directories in ~ that do not need to be tracked, and that set is ever-changing and ever-growing.
Historically, I've dealt with this by having this .hgignore:
syntax: glob
*
This keeps my status clean, as far as it goes, making only previously tracked files visible. However, I have some directories (in my case, scripts, .emacs.d) that I would like to see untracked files in; I almost always want to track new additions to those directories.
I know that I can run hg st -u scripts to identify untracked files, but I want a means whereby I can achieve the same function using plain ole hg status.
Is there a way to do this?
Try this in .hgignore instead:
syntax: regexp
^(?!(scripts|foo|bar)/)[^/]+/
^ matches start of path
(?!(scripts|foo|bar) uses negative lookahead to ignore all files except those in directories scripts, foo or bar
/) ensures that directories which have a tracked directory as a prefix are ignored
[^/]+/ then actually matches any directory (excluding those ruled out by the lookahead), so that files in ~ aren't ignored
Credit for the central idea in this solution (the negative lookahead) goes to Michael La Voie's answer to this question
This question has been asked here on SO quite a few times, and you'll get a lot of convoluted answers using zero-width negative look ahead assertions, an oft abused regex trick, but the better solutions are to either (a) just make the repo in that directory alone or (b) just add the files in that directory. For option (b) you'd just put .* in your .hgignore file to ignore everything, and then manually hg add the files you want tracked. In mercurial, unlike svn and cvs, you can override an ignore with an add.