Mercurial: Can I mix slashes and backslashes in paths? - mercurial

Are the following paths valid? Could they cause malfunction of Mercurial?
mercurial.ini file:
[ui]
ignore = ~\file/hgignore.ini
mercurial.ini file:
[ui]
ignore = .\file/hgignore.ini
hgrc file:
[paths]
default = D:\MySolution/MyProject

It shouldn't be an issue in hgrc.
It can be an issue in hgsub, for path to subrepos.

Related

Mercurial is ignoring new files

How can I make new files show up in hg status output?
Newly created files in my project directory do not appear when I run hg status. If I run hg status --all, I see that they are ignored. I would expect that newly created files would be indicated as untracked and that I would have to manually ignore them, rather than the other way around.
The new file type is not listed in .hgignore nor do I have anything that should affect it in my mercurial.ini.
# .hgignore
syntax: glob
## Specific Files ##
## File Types ##
*~
*.pyc
*\#
## Directories ##
venv/*
.idea/*
.pytest_*
__pycache__/*
*/__pycache__/*
; mercurial.ini
[ui]
username = Lorem Ipsum <loremipsum#dolorsitamet.com>
editor = "C:\Program Files\emacs-26.1-x86_64\bin\emacsclientw.exe"
[pager]
pager = C:\Program Files (x86)\less-530-win32-static-x86\less.exe
[color]
mode = win32
[alias]
; Prevents creation of .orig files
undo = revert --no-backup
The trouble is that hash is not escaped correctly in .hgignore.
Incorrect
*#
Correct
*\#
The .hgignore file uses hash for comments. Without it, Mercurial interprets *# as just *. This tells Mercurial to ignore everything! That's why nothing was showing up in hg status.

Why does .hgignore appears in my patches?

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

How do I set my username in Mercurial?

When running Mercurial I get this error:
t3#des:gem5$ hg qnew my_p.diff
abort: no username supplied (see "hg help config")
the hg help config says:
The configuration files use a simple ini-file format. A configuration file
consists of sections, led by a "[section]" header and followed by "name =
value" entries:
[ui]
username = Firstname Lastname <firstname.lastname#example.net>
verbose = True
But where is that ini file?
hg help config
These files do not exist by default and you will have to create the
appropriate configuration files yourself: global configuration like
the username setting is typically put into
"%USERPROFILE%\mercurial.ini" or "$HOME/.hgrc" and local configuration
is put into the per-repository "/.hg/hgrc" file.
Assuming your on linux, create the .hgrc file in either your home directory or in the repository dir in question,
dirunderhgcontrol/.hg/.hgrc
Add the info(ui, username, verbose...) you stated in your question to the new file and then give it a try.

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: Globally Ignore Files

I know about .hgignore and how I can ignore files on a project-by-project basis. I want to ignore stuff for all Mercurial repositories.
Is there something I can stick in .hgrc? Or put a .hgignore in my $HOME path (I tried that already but maybe I did something wrong).
You can add a path to a global or per-user ignore file in the [ui] section of your global/user hgrc or Mercurial.ini:
[ui]
ignore = ~/.hgignore
On Windows:
[ui]
ignore = %USERPROFILE%\.hgignore
In powershell, you can get to your global files like this.
PS> notepad $env:userprofile/mercurial.ini
...
[ui]
ignore = %USERPROFILE%\.hgignore
...
PS> notepad $env:userprofile/.hgignore
/bin/
/obj/