Can't get hgignore to work - mercurial

I'm trying to make mercurial ignore the "1.txt" file in win7, mercurial 2.3
Why is 1.txt still shown with the "hg status" command here?
\hgtest> dir
Directory: \hgtest
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 2012-08-27 11:01 .hg
-a--- 2012-08-27 11:03 44 .hgignore
-a--- 2012-08-27 11:02 6 1.txt
\hgtest> type .hgignore
syntax: glob
*.txt
\hgtest> hg status
? .hgignore
? 1.txt

I suspect it is because your .hgignore is in utf-16 encoding. Thereof the size 44 for a 22 character text.
hg probably don't understand the .hgignore file.
Try opening the file and save it in plain ANSI encoding.

Probably because it's still in the repository. Try to forget that file.
If you want to have this file in the repository, and at the same time ignore it, that it does not show, I think that this is not possible.

I just tried recreating your scenario based on the information in your original question on 64-bit Windows 7, but with Mercurial 2.2.3 (I am using TortoiseHg 2.4.2) and I don't see this problem. I checked both in a cmd.exe console and a Powershell console (which is what you appear to be using). I noticed, that the reported size of the .hgignore file in my case was half of what it was in your original question. I am not sure what the difference in size is because of. Since we are on different versions of Mercurial, I wonder if something broke in 2.3.

Related

PyCharm or Mercurial error: Number of lines annotated by Mercurial is not equal to number of lines in the file

When I click on Annotate, I often get this message in PyCharm 2018.2.5 (running on Ubuntu 18.04):
Number of lines annotated by Mercurial is not equal to number of lines
in the file. Check file econding and line separators
It looks like a Mercurial error, but in command line, the following command on the same file is succesful:
# hg annotate -ud <file>
Line enconding is LF, File encoding is UTF-8
EDIT
Mercurial version:
# hg --version
Mercurial Distributed SCM (version 4.5.3)
The file I'm try to annotate is in a subrepository, and checking the logs I discovered
PyCharm is trying to annotate using the father's repo.
If I execute the command in father's directory, I get an empty result.
So the error is misleading, and apparently I don't know how to set up PyCharm in this case.
Is there a way to fix this?
I got it. I think it makes sense answering my own question.
The structure of my project is the following:
Project root (no VCS)
RepoDir (hg repository)
SubRepoDir (hg subrepository)
In this configuration something confuses PyCharm, and subrepositories at third level
won't be recognized.
The following works pretty well:
RepoDir as Project root (hg repository)
SubRepoDir (hg subrepository)
If other directories are needed, one can add them as content root.

mercurial ignore .zip files in whole repository

i am using Mercurial for version controlling. I am trying to ignore zip files in the repository, my hgignore file is in the root directory of project
i got the codes below from http://www.selenic.com/mercurial/hg.1.html#patterns.
syntax: glob
**.zip
syntax: regexp
re:.*\.zip$
But these doesnt work for me.
i also tried
hg addremove
and
hg forget -I '*'
but it didnt help. Can you tell me how can properly ignore zip files from the repository?
Thanks for help.
EDIT
My problem was the zip files were already added to repository. I first forgot them and committed. Now it ignores
Simply writing *.zip inside .hgignore will do this. The patterns inside .hgignore are not rooted, so *.zip would match a zip archive no matter where it appears.

Why is .hgignore being ignored?

I am very new to Hg so please excuse my ignorance here...
I am using Mercurial and TortoiseHg in Windows 7. I have a repository created that has the following folder structure:
-- My repo dir
|
|--- .hg
|--- .hgignore
|--- File 1
|--- File 2
|--- ...
My database data files live in the repo directory but I do not want them to be included as part of the repository. I've tried all kinds of things in the .hgignore file, but regardless when I right-click on the repo folder in the Windows Shell and go to Hg Commit..., it includes the two database data files in the list of files to be committed. Yes, I can uncheck them manually, but my thought was that by being in .hgignore they wouldn't be included in the list of files to commit.
Here's my current incarnation of .hgignore, although I've tried a handful of others with no luck:
MyDatabase\.mdf
MyDatabase\_log\.ldf
Am I being daft here, or is it that TortoiseHg does not respect/inspect the .hgignore file when committing?
UPDATE:
Finally got this to work. I had to instruct Mercurial to forget the files, as #Diego suggested. Interestingly, though, when I followed #Diego's suggestions and tried to forget them via the command-line it did not work. I had to go to Windows Explorer, right-click on the files, and from the context menu I chose TortoiseHg --> Forget Files...
Thanks for the suggestions, everyone.
Maybe mercurial is already tracking those files. If files are already tracked then .hgignore does not have any effect. Try:
hg forget MyDatabase\.mdf MyDatabase\_log\.ldf
Then edit .hgignore to exclude those files and commit.
That should solve it.
You need to add this line at the beginning of your .hgignore file:
syntax: glob
MyDatabase\.mdf
MyDatabase\_log\.ldf
Scott,
Do you have any other mdf/ldf files that you want to add to the repository? If not, could you just try the following in your .hgignore file?
syntax: glob
*.mdf
*.ldf

How to ignore hgignore when reverting (aka remove all useless files)

I have a .hgignore file that works great for hiding all the files and directories creating when compiling my C# projects.
Now when doing a "revert" to a previous revision, I would also like to clean up my working directory, ie remove all the exes and dlls that I've previously compiled (as I may end up using the wrong version of an exe or dll without realizing it).
Is there a way to do that (kind of ignoring .hgignore somehow)? Right now I'm just removing all bin and obj directories, but maybe Hg can also do it...
You are looking for the purge extension.
Rudi's answer is best, but if you don't want to install an extension you can always do:
hg status -nu0 | xargs -0 rm -v
which does the same thing. (Optionally include i in the options for status to get ignored files too.

Prevent "hg status" from showing everything under untracked directories

I find the output of hg status too verbose for untracked directories. Suppose I have an empty repository that's managed by both git and hg. So there would be two directories, .git and .hg.
The output of git status is:
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .hg/
The output of hg status is:
? .git/HEAD
? .git/config
? .git/description
? .git/hooks/applypatch-msg.sample
? .git/hooks/commit-msg.sample
? .git/hooks/post-commit.sample
? .git/hooks/post-receive.sample
? .git/hooks/post-update.sample
? .git/hooks/pre-applypatch.sample
? .git/hooks/pre-commit.sample
? .git/hooks/pre-rebase.sample
? .git/hooks/prepare-commit-msg.sample
? .git/hooks/update.sample
? .git/info/exclude
Is there a way to reduce its output to something like the following line?
? .git/
This works for me :
hg status -q
Option -q/--quiet hides untracked (unknown and ignored) files unless explicitly requested with -u/--unknown or -i/--ignored.
You can just add in your .hgignore file
syntax:glob
.git
.gitattributes
.gitignore
To ignore .git entirely, and other git-related files.
If the goal is to only limit to a directory, you can still use .hgignore if you add an hidden file in that directory (after this answer):
syntax:regexp
^.git/(?!\.hidden).+$
Since Mercurial do not track directories at all, that will ignore all files within .git except the hidden one, effectively displaying only one line in the status.
You would also have the option -q/--quiet (to hg status), which hides untracked (unknown and ignored) files unless explicitly requested with -u/--unknown or -i/--ignored.
But that means .git would not even show up in that case.
But if the goal is to limit in general the output of hg status to only the directories and not their content for untracked files, then I believe this is not possible:
git track content of files and since no content is added, it only mentions the top directory has "having no content added"
mercurial tracks files (not directories), hence the comprehensive list (of files).
I understand the question is about how to reduce the output: I had similar need but did not want to untrack or ignore files. If you are using *NIX, you cloud use grep, and you just want to reduce the output as your question states, for example to get rid of these lines:
hg status | grep -v "^\?\s\.git"
Or for example not showing removed files
hg status | grep -v "^R"
In Windows PowerShell an equivalent would be:
hg status | Select-String -Pattern ("^[^R]")