Why does .hgignore appears in my patches? - mercurial

I use Mercurial Queues to work with patches.
There was no .hgignore initially.
I'm not sure if I first created an MQ patch and then created my .hgignore or the other way round.
(By "creating a patch" I mean hg qnew patch_name -m "...")
Anyway, I made some changes to .hgignore after I created the MQ patch.
When I did hg qrefresh; hg export qtip I got the changed contents of .hgignore also in my patch.
So, tried adding an .hgignore entry to .hgignore itself. But that didn't work. The changes persisted.
So, I tried hg forget .hgignore and this made a bigger mess. It nows shows that I deleted .hgignore in my patch. Like so:
--- a/.hgignore
+++ /dev/null
- all
- the lines of .hgignore
- the lines of .hgignore
How do I resolve this problem?
I just want .hgignore to be part of my local repo and help in not tracking some files.

.hgignore is designed to be tracked by Mercurial (doc). The standard way to ignore files in local clone only is to use ui.ignore setting:
# .hg/hgrc
[ui]
ignore = /path/to/repo/.hg/hgignore
If you have multiple local ignore files then you can write
[ui]
ignore.first = /path/to/repo/.hg/firstignore
ignore.second = /path/to/repo/.hg/secondignore
Additional global ignore files can be configured in this way:
[ui]
ignore.first = /path/to/repo/.hg/firstignore
ignore.second = /path/to/repo/.hg/secondignore
ignore.third = ~/thirdignore
All settings live in hgrc file. More details here:
hgrc file location: doc
ui.ignore setting reference: doc
about .hgignore files: doc
original recipe: Tips And Tricks

Related

Find committed files that should have been ignored

How can I list all files in a repository that were committed (explicitly), although they were ignored because of the .hgignore file
.hgignore uses glob syntax
running on Windows
it's not necessary to take any global .hgignore file into account
My idea:
hg manifest > filter using the content of .hgignore > result
You have to learn and use filesets in this case
List files that are in .hgignore but are already tracked:
hg locate "set:hgignore() and not ignored()"

Make .hgignore in a Mercurial repository available to all subrepos?

I have a Mercurial repository with several subrepos. Is there a possibility to only define a general .hgignore-File (e.g. to ignore object-files) both in the main repository and, optionally a specialized one in the sub-repositories?
There is not enough information in the manual. Specifying a .hgignore file with
[ui]
ignore = .hgignore
to .hgrc in my home-directory also does not work.
Any ideas?
A .hgignore file in each subrepo would serve as the specialized one for that subrepo. Then you can use the main repo's .hgignore as the main one by including this in each subrepo's hgrc file:
[ui]
ignore.main = \absolute\path\to\mainrepo\.hgignore
The reason why doing ignore = .hgignore didn't work for you in your global .hgrc (and won't in repo hgrc) is that having simply .hgignore is a relative file path and its resolution to an absolute path depends on the current working directory used when invoking hg. Examples:
If you're in \repos\main\ and invoke hg st, it will look for \repos\main\.hgignore. Same thing if you invoke hg st -R nested, because the current working directory is still the same.
But if you were in \repos\main\nested\ and then invoked hg st, the config would now be looking at \repos\main\nested\.hgignore.
If you want to specify a global .hgignore that is in your home directory, you would need to specify it with a non-relative path (or at least much less relative):
[ui]
ignore = ~\.hgignore

Mercurial extension to automatically generate .hgignore file?

I have been thinking that it sure would be nice to have a command like "hg ignore" that would automatically add all untracked files to the .hgignore file.
Manually editing the .hgignore file is powerful, but when I am frequently creating new repositories it would be nice to be able to add only the files I want and then do an hg ignore to automatically have Mercurial ignore any others.
Does anyone know of any extensions that do this?
Try this once you've added all the files you need:
hg stat --unknown --no-status >> .hgignore
You can create a command to automatically generate your .hgignore using an alias. On a Unix-like system, add the following lines to your .hg/hgrc (or one of Mercurial's other configuration files):
[alias]
ignore = !echo 'syntax: glob' >> $(hg root)/.hgignore && \
$HG status --unknown --no-status >> $(hg root)/.hgignore
This will give you a hg ignore command that will populate the .hgignore file with all currently unknown files, thus turning them into ignored.
On Windows, the syntax for the alias is:
[alias]
ignore = !echo syntax: glob > .hgignore && "%HG%" status --unknown --no-status -X .hgignore >> .hgignore
On Windows, you must run it in the root directory of the repository, otherwise the .hgignore file will be created in the current directory, which is probably not what you want.
The ! syntax in aliases is new in Mercurial 1.7. In earlier versions you can add
[alias]
ignore = status --unknown --no-status
and then redirect the output of this command to the .hgignore file yourself:
hg ignore >> .hgignore
You will then also need to take care of adding a syntax: glob line, if necessary (the default syntax is regular expressions).

abort: untracked file in working directory differs from file in requested revision: '.hgignore'

I am trying to pull some files and directories and I am having the following messages:
When I look in my repository I can see that the files have been downloaded but all contains _ as prefix, and even the names of files and folders contain _
requesting all changes
adding changesets
adding manifests
adding file changes
added 1094 changesets with 4304 changes to 1071 files abort:
untracked file in working directory differs from file in requested revision: '.hgignore' [command interrupted]
What is wrong?
I think you have created a .hgignore in your working directory without adding it to the repository (hg add). This file is "untracked".
Someone else, from another clone, has added this file too, committed and pushed it. Now, when you try to update your working directory, Mercurial try to add this file but sees a file with the same name in your working directory which is untracked and different.
There's two solution to your problem :
Backup your .hgignore file, do the update and add the differences from the backup if necessary
Add your own file to the repository with hg add, then re-run the update. It will maybe be necessary to commit the file prior to the update.
I'll advise using the first solution.
When you say the files in the repository have _ as a prefix, you're looking down inside the .hg directory aren't you? That's the data store for Mercurial itself and the files in there are revlogs, not your files. Outside of .hg you'll have a working directory where the files are the actual files you expect. You're not getting one of those now because hg update is refusing to update the working directory because doing so would overwrite your uncomitted .hgignore file.
What exact command are you running? It looks like it's doing a hg pull followed by an hg update so I'd guess hg clone but if you already have a .hgignore lying around that's not the right command to use. If instead you're using hg pull -u or hg fetch you should just use hg pull instead to get the changesets. Then you can:
hg add .hgignore # add the hg ignore file you already have that's untracked
hg commit -m .hgignore # commit the .hgignore file you just added
hg merge # merge your new commit (.hgignore) with the changesets you just pulled down.

For Mercurial (Hg), why the file .hgignore cannot be ignored?

I have these in the proj/.hgignore:
syntax: glob
log/*
*~
*.orig
dump/*
*.hgignore
.hgignore
tmp/*
but for some reason, when I do an hg st or hg com, the file .hgignore still shows up to be modified or to be committed. So the .hgignore cannot be ignored? There might be particulars in my folder that my team didn't want to ignore but I do. So I don't want to commit this file.
Chris has it in the comment: you've probably already added your .hgignore file, and an add overrides the .hgignore. You need to hg forget .hgignore and hg commit and then you'll find your file is ignored.
Thats said, most people put the .hgignore file into the repo for a reason -- so that the next person to clone doesn't accidentally commit all of their log/temporary files.
I think you're looking for this:
https://www.mercurial-scm.org/wiki/TipsAndTricks#Ignore_files_in_local_working_copy_only
The overall .hgignore file is necessary to ignore anything, and so you can't exclude it.