How to list all remote repositories in Mercurial? - mercurial

I'm just looking for a Mercurial command that can list the available repositories in the remote parent repository. When I used subversion, this was simple, as in:
svn ls httpx://server/repos/002/trunk
svn ls httpx://server/repos/002/trunk/blort
svn ls httpx://server/repos/002/trunk/blort/fubar
And then I could use ``svn co'' to fetch as much or as little of some directory tree as I wished.
However, I can't find the analog to this in Mercurial. All the tutorials seem to expect you to know precisely the path to the remote repository and don't discuss anything about even some top level browsing of the remote repository.
Thanks.

There is only 1 path to the repository.
With a DVCS you typically clone the repository as a whole. Then you can look at it all you
want locally. That is why you have received those answers in the past.

I dont know about a command but it is doable with a script
for repo in `curl $url/hgweb.cgi | \
grep -v "atom" | \
grep hgweb.cgi | \
awk -F'>' '{ print $3}' | \
awk -F'<' '{print $1}'`; do \
echo $repo \
done

Related

In hg how do I pull all remotes/paths in one command?

I'm looking for the equivalent of git fetch --all. I currently have three different remote paths configured for my repository. hg paths shows all three. How do I do hg pull --all to fetch the new change sets from all remote repositories?
I figured out how to do this with an alias. In your ~/.hgrc add:
[alias]
pullall = !$HG paths | cut -f 1 -d ' ' | xargs -n 1 $HG pull
Then you can run hg pullall to fetch all the remotes.

How to drop a prefix from hg archive?

I would like to export files from a repository, ignoring changes in the working tree. Furthermore, rather than exporting everything, I would like to see a subset of it. The destination directory might already contain some files and those must be overwritten.
Given:
project/some/sub/dir/
I would like to export it to:
output/dir/
In git, I can use:
git archive --prefix=dir/ HEAD -- some/sub/dir/ | tar -xv -C output
What is the equivalent command in hg? If I use hg archive -t files -I some/sub/dir output/, then I get output/some/sub/dir. I could pipe the result through tar, but then I have to manually calculate the prefix that should be dropped:
hg archive -t tar -I some/sub/dir/ - |
tar -xv -C output --strip-components=3
(in reality, I have some other tar patterns that should be ignored such as --exclude='.*'). Any ideas? This export will be done for three other directories located in the repository.
Current situation:
srcdir=some/sub/dir
dstdir=output/dir
# hg archive auto-adds a 'proj-version' prefix. Given the srcdir,
# proj-version/some/sub/dir/X should become dstdir/X, so strip 4 components
prefixlength=$(grep -c / <<<"/${srcdir%%/}/")
hg archive -t tar -I "$srcdir" - |
tar -xv -C "$dstdir" --strip-components=$prefixlength
You can
hg archive ... && cd output/some/sub/dir && tar ... isn't it?
Build intermediate repo (Convert Extension), where some/sub/dir/ will be root of this repository (understand also sample from Converting from Mercurial topic) and get tar'red archive directly from hg archive for intermediate repository

Any way to pull/update all subrepos?

I'm looking into the viability of switching from svn to mercurial for my organization, but there's one hangup I can't seem to find a solution for.
Is there any way to pull and update a repo and all subrepos without manually pulling and updating each one?
I'd like to switch to mercurial, but if that's not possible then it's a no-go for us.
Edit: Good god I must be tired today... two questions on SO for which I find the answers minutes after asking...
Somehow missed this, and found it right after asking the question:
https://www.mercurial-scm.org/wiki/OnsubExtension
You can define a simple shell alias like the following
alias hgsub='find . -name ".hg" -type d | grep -v "\./\.hg" | \
xargs -n1 dirname | xargs -n1 -iREPO hg -R REPO '
and then do
hgsub tip
hgsub pull -u
As an alterantive, a batch script might help:
#echo off
for /D %%d in (*) do (
if exist %%d\.hg (
echo Verzeichnis %%d
cd %%d
hg pull -u
echo ----------------------------------------------
cd ..
)
)
pause

Testing for uncommitted changes in mercurial

What's the best way to check in script if there're uncommitted changes in mercurial's working tree.
(the way I would with git diff --quiet in git)
In mercurial 1.4 and later you can use the summary command, which gives output like this when changes exist:
$ hg summary
parent: 0:ad218537bdef tip
commited
branch: default
commit: 1 modified
update: (current)
and this post-commit:
$ hg summary
parent: 1:ef93d692f646 tip
sfsdf
branch: default
commit: (clean)
update: (current)
Alternately, you could install the prompt extension and do something like this:
$ hg prompt '{status}'
which will output a ! or ? or nothing as appropriate.
Both of those, of course, are just alternate text outputs. I couldn't find anything that used the exit code directly, but since $? checks the last command in a pipe you could do?
hg summary | grep -q 'commit: (clean)'
which will set $? non-zero if any changes are uncommitted:
$ hg summary | grep -q 'commit: (clean)' ; echo $?
0
$ echo more >> that
$ hg summary | grep -q 'commit: (clean)' ; echo $?
1
You can also run hg id. If the hash ends with a + it indicates the working copy has changes. This should even work with old versions of hg.
It sounds like you're already using zsh; well, a couple days ago I helped to update the Mercurial support for the built-in VCS_INFO for putting VCS info in your prompt. Slated for the next release is support for showing changes to the working directory (among other things). If you don't want to wait you can grab the necessary files from CVS.
At the moment my prompt includes this (using only built-in zsh functionality):
(hg)[1801+ branchname somemq.patch, anycurrentbookmarks]
I use:
hg status -m -a -r -d -u
If no changes with tracked files, then the command output is an empty string.
I use this bash-snippet for some time now:
if [[ $(hg status 2>/dev/null) ]]
then
# do something
fi
Both id and summary are slower than status, so this is the fastest way I currently know, ignoring untracked files:
[[ -z `hg status | grep -v '^?'` ]] && echo no-changes || echo has-changes
There should be something more elegant than simply
[ `hg st |wc -l` -eq 0 ] && echo hi

How do I delete all untracked files from my working directory in Mercurial?

Is it possible to delete all untracked files from my working directory? Let's say I added a bunch of files to my working directory, didn't add them via 'hg add' and now want to get rid of those new files entirely?
I'm on windows, although I'm using PowerShell, so a combined solution is also possible here.
Add the Mercurial Extension called purge. It is distributed by Mercurial.
This extension adds a “purge” command to “hg” that removes files not known to Mercurial. i.e. untracked Files. So your command would be,
hg purge
It is not enabled by default, maybe to avoid accidentally removing files that you forgot to add.
To install this extension, add this to your mercurial settings file (.hgrc on Unix, Mercurial.ini on Windows)
[extensions]
purge =
To enable this extension temporarily you can use
hg purge --config extensions.purge=
The proper way without purge is:
hg st -un0 | xargs -0 rm
Thanks! This worked for me also in Powershell:
hg st -un | rm
rm $(hg st -u)
...where -u stands for "untracked" you can also pick another state.
You can use
hg purge --all
to remove all the ignored and untracked files
(first you need to install the purge extension as explained in some answers)
Try following:
hg st -un | xargs rm
if you don't want to use purge:
rm $(hg st | grep ^? | awk '{print $2}')
This should do the trick:
hg status | grep '^\?' | sed 's/^\? //' | xargs rm -rf
Assuming that you are using a *nix system you could run something like this:
rm `hg st | awk '/\?/ {print $2}'`
from the root of the mercurial repository.
I don't know of a standard mercurial command to achieve the same but I believe there are many more command-line options to do this. I'm sure there are "better" solutions and would be interested to hear any other suggestions.
Please use this command with caution as it was not thoroughly tested.
This works from Windows 10 command line (used cautiously of course):
for /f %g in ('hg status -un') do #echo %g & #del %g
A quick/hacky way, if you do not have local changes, is to delete the folders you want from the file manager (Windows explorer for example) and then use "hg revert" which restores only the tracked files.