How do I find out if I can push to a remote repository? - mercurial

In Mercurial, is there a way to find out if I'm authorized to push changes to a remote repository (without actually doing a hg push)? I simply want to verify that the settings in hgrc on the local and remote server is correct.

The only way to be really sure is to try it—and even then, if it succeeds, that just means you had permission; maybe you don't now.
That said, you can simply push to them a commit that you got from them, to see if you have all the permissions required to get that far. You will end up sending them nothing and writing nothing, but you'll test as much of that code path as you can test without actually sending them something.

Related

push to configured hg repository from web interface

I have a small group of developers and we all develop on our own machines. When we have code that is ready for testing, we merge and push to a RhodeCode installation. The hgrc file for my central RhodeCode repo is set up like this:
[paths]
test_env = /www/mysite/test
prod_env = /www/mysite/prod
[hooks]
changegroup = hg push test_env
so when a person checks code into RhodeCode, the changes are automatically pushed to the test environment. (There's a hg update in the test repo hgrc file, so the code updates there). This is perfect.
BUT.. I would like our RhodeCode admins to be able to push to prod without needing shell access on the server. Is there a way to allow someone to run a "hg push prod_env" from the RhodeCode interface? I figure since RhodeCode has full control over hg, it should be possible, but does this ability exists somewhere in RhodeCode? would it be a huge task to add it?
If not, how would you go about allowing an authenticated user to push a repository to production without shell access? I have been googling, but I can't seem to find anything. I know I could write a php script with a passthru("hg push test_env), but that seems like a permissions nightmare as apache runs as "nobody" and rhodecode owns the repo.
Thoughts?
Obviously, you cannot push nothing. But you can try to add or edit some file from the RhodeCode interface (which allows this to do) at the prod_env. This should cause local commit and push without accessing a shell.
For those looking at this question, here's how I solved it:
Wrote a passworded page in PHP with a button that executes this code:
shell_exec('hg pull -R ../wp-content/themes/2014');
I then put hg update in the hgrc file for the prod website, and made the web user and authorized user of the repository.
It works pretty good - i have slight security concerns because of the resulting file ownership, but assuming the PHP follows proper practice, there aren't any problems.

How to find out the size of a mercurial repository?

So, for example, if there's a mercurial repository https://code.google.com/p/potentiallyLarge is there a command which would allow me to find out its size before cloning it? Something like
hg size https://code.google.com/p/potentiallyLarge
Also, is there a command for doing this for subversion repositories?
The size used on disk is different from the bandwidth used to make a clone. Some hosting sites (such as Bitbucket) display the size on disk so that you know upfront how much space you'll need on your system before cloning. But I can see that Google Code doesn't, so it wont help you here.
The Mercurial wire protocol doesn't expose any commands that can tell you how big a repository is. When you make a normal clone, the client doesn't know upfront how much data it will receive, it just receives a stream of data. After receiving the changelog, the client knows how many manifests and filelogs to expect, but it doesn't know the size of them.
In fact, it's difficult for the server to compute how much data a clone will use: the network bandwidth used is less than the disk space since the compression used is different (bzip2 vs gzip). However, if you use --uncompressed with your clone (which Google Code doesn't support) then there is a trick, see below.
The only way to know much bandwidth a clone uses is to make one. If you have a clone already you can use hg bundle to simulate a clone:
$ hg bundle --all my-bundle.hg
The size of the bundle will tell you how much data there is in the repository.
A trick: If Google Code had supported hg clone --uncompressed, then you could use that to learn the size of a remote repository! When you use --uncompressed, the client asks the server to send the content of the .hg/ directory as-is — without re-compressing it with bzip2. Conveniently, the server starts the stream by telling the client the size of the repository. So you can start such a clone and then abort it (with Control-C) when your client has printed the line telling you the size of the repo.
Update: My answer below is wrong, but I'm leaving it here since MG provided some good info in response. It looks like the right answer is "no".
Not a great way, but a work-around sort of way. A hg clone URL is really just hg init ; hg pull URL And the command hg incoming tells you what you'd get if you did a pull, so you could do:
hg init theproject
cd theproject
hg incoming --stat URL_TO_THE_PROJECT
and get a pretty decent guess of how much data you'll be pulling down if you follow up with:
hg pull URL_TO_THE_PROJECT
I'm not sure about the network efficiency of hg incoming but I don't think it downloads everything from all the changesets, though I could be wrong about that. It offers a --bundle option that saves whatever incoming pulls down to a file from which you can later pull to avoid double downloading.

Changes force-pushed to a Mercurial server are not visible there

I have a problem when I'm pushing my code and files to the remote server.
It says that the changes (after they were commited) were pushed successfully onto the remote server but the changes are not visible on the server.
Since I don't have access to the server, how would I go about debugging this problem to find out where the problem occurred (the logs on the server don't show anything I am told)?
Maybe important note:
I had to force push the changes because it wouldn't sent them otherwise.
Second question:
How can I re-push my changes?
If
$ hg outgoing
shows nothing, then the changes are already there on the server — I promise! If you had access to the server, then running
$ hg log
would reveal that the changesets are really there. The confusion must be that the working copy on the server is not updated when you push changes to it. So someone needs to run
$ hg update
on the repository on the server to actually make the working copy update. Normally, you don't need a working copy on the server, but if you're using Mercurial to publish, say, a website, then you'll want a push to also update the working copy.
The solution is to add
[hooks]
changegroup = hg update
to the .hg/hgrc file on the server. Maybe you can ask some admin to install that hook for you?

Mercurial, push just to one developer

I'm trying to find out Mercurial advantages and i've read something about commiting between developers without influence on main branch.
I know i have to commit to my local repo, and then what? I don't like to push it to server (then everyone will see it right?), but just to one concrete user. I'd like him to fix something for me and send me back his changeset. Then later I'll push everything to server.
How can i do that? How should i do that in mercurial?
Run hg serve on your system. It will print something like:
listening at http://yoursystem.someplace.com:8000/ (bound to *:8000)
Assuming the other developer also has a clone of the server project, he can run:
hg pull http://yoursystem.someplace.com:8000
to get your updates.
Later you can reverse the process to get his changes back to you.
Hg serve is the easiest way, but if firewalls prevent you from doing that you can create a bundle and send it by email:
hg bundle thebundlefiletocreate.bundle http://URL/of/your/central/repo
then you can email the resulting thebundlefiletocreate.bundle file to the person. They can apply it with:
hg unbundle `thebundlefiletocreate.bundle`
This is a pretty clumsy way to work though. Using hg serve back and forth (as Mark suggested) is better if possible. Ideally you create a repo you can both read/write on a shared server or drive and both push/pull to it.

Is there anything like svnserve for Mercurial?

I'm attracted to Mercurial as a DVCS platform, but would like an easy to use server similar to svnserve. There is HgServe, but that appears to be read-only. If I want to be able to host the server on another machine, it appears I need to set up apache, etc. Is that really the case? Is there an easier method for a local network where security isn't an issue?
The problem here is that it's so easy, the mercurial documentation fails to appropriately cover it. If you clone with ssh:
hg clone ssh://user#host//path/to/repo /local/path
It will do the right thing on the "server" system (it automatically runs hg serve on the other end for the duration of the operation), and then any subsequent operations (push, pull, etc.) will be automatically run over ssh. (Make sure you use the double slash after the hostname if you want your path to start at the filesystem root, otherwise it'll start wherever ssh puts you).
Note that Hg "users" are separate from ssh users, so if you want everyone to use the same restricted account for ssh, they can - hg will still identify their changesets by the user set up in their .hgrc.