How to detect that commits are pushable - mercurial

In Git it is easy, because remote/branch is pointing to a different commit than branch. How to do it with Mercurial?

If you mean seeing what's different between your local repo and the one you're pushing to, try
hg outgoing

Since Mercurial 2.1, there is also a purely local solution: phases. The draft phase is probably what you are looking for. For details, refer to:
https://www.mercurial-scm.org/wiki/Phases
You may find hg phase <rev> and hg log -r "draft()" interesting.

There is an remotebranch extension that will give you a Git-like setup. It tracks the remote heads for the repositories listed in the [paths] and exposes them as tags named <path>/<branch>. This lets you run
$ hg diff -r foo/default
to see what has changed since the default branch in the foo repository. There is also new revset keywords that let you do things like
$ hg log -r "not pushed()"
to get what
$ hg outgoing
would do, but without any network traffic.

What's the command line call to show all revisions in the draft phase?
hg log --style phases
That will display the log + the phase, since Mercurial 2.7 (2013-08-01).

I'd just use hg outgoing as others are suggesting, but hg summary will tell you too. It may require the --remote option to have it check the remote default server.

If you need to select the changesets for further processing, then you can use the outgoing revset predicate. This lets you re-implement hg outgoing as
hg log -r "outgoing()"
but the real benefit is that you can use this in other contexts, such as
hg strip "outgoing()"

Related

Mercurial equivalent to hg qdiff?

mq, which I like a lot, but which I understand is being deprecated in favor of changeset evolution, provides a command hg qdiff that shows the combination of the last-saved patch mixed with the current working directory diffs. I.e., it shows what will be the content of the complete patch if I enter hg commit --amend right now.
Is there a way to show the combined diff like that in base (non-mq) mercurial?
I realized the answer as I prepared to submit the question: hg diff with respect to the parent of the current change:
hg diff -r '.^'

Get tip changeset of remote Mercurial repository

My .hg/hgrc file has the line:
default = http://some/remote/repository
Is there a quick command to print the tip revision of that repository (which may or may not be inside my local repository)?
You can use the identify command like this:
$ hg identify $(hg paths default)
This is one of the few commands that can operate on a remote repository. If you need more information about the remote repository, then I suggest you take a look at hg incoming.
The following returns the latest changeset number (tip) of a remote repository:
hg identify --id http://www.myrepo.com
hg id default
This is a shorter form of "hg identify $(hg paths default)".

How to view diff between head of local repository and head of remote repository?

Before I push to a remote repository, I want to see a consolidated diff between the head of my local repository and the head of the repository I'm pushing too. The best way I know of doing this is to hg clone the remote repository, get the revision of the head, then do a diff between my head and that revision. But this is time-consuming. Is there a quick way?
In addition to
$ hg outgoing -p
which I normally use, I'll like to point you to revision sets. That is a query language that you can use with hg diff (and all other commands that lets you specify changesets). So you can implement hg outgoing -p by
$ hg log -r "outgoing()" -p
and you can get a diff between the parent of the first outgoing changeset and the last outgoing changeset with
$ hg diff -r "p1(first(outgoing()))" -r "last(outgoing())"
Finally, the remotebranch extension can maintain local information about the remote branches so that you don't need to use the network to lookup this information. It lets you use
$ hg log -r "not pushed()"
to find the outgoing changesets, but it's much faster since there's no network round trips involved.
If you're looking for a way of getting all the changes you've made that aren't in the remote repository.
$ hg outgoing -p
The -p is optional and reports in the form of a patch, otherwise it reports in the same way a hg log. This is just your changes regardless of whether anybody else has pushed anything to the remote repository.
If you're looking for changes in the remote repository that you don't have then you use
$ hg incoming
Again there's a -p form if you want it.
Neither of these are exactly what you asked for, but I suspect you don't actually want that.
If you really want the difference between your changes and the new head in the remote repo created by someone else, then you'll need to pull their changes over.
hg pull
hg heads # find revision number of new head
hg diff -r 124992 # or whatever the revision number is.

How to revert a Mercurial hg pull?

If you do an hg pull and then an hg update (or an hg merge), is there a way to back this out? Ie: revert your repository to the state prior to doing the hg pull?
I believe you can do hg update -r n where you would specify the changeset prior to the pull as n. Though I'm guessing this will still leave the changesets in your repository but this isn't really what we want. ??
hg strip will remove revisions from a repository. Like all powerful commands, its dangerous, so be careful.
https://www.mercurial-scm.org/wiki/StripExtension
Also see:
https://www.mercurial-scm.org/wiki/EditingHistory
If you catch your mistake immediately (or reasonably soon), you can just use hg strip REV to roll back the latest (one or more) changes. ...
Ok, you can't rollback because you've done a commit. What you can do is use 'hg strip' which is part of mq (after 2.8 strip is in it's own extension), or use mq to remove the changes. Either way I suggest you do everything on another clone, just in case.
To do strip, update to a revision that you want to keep, and then
hg strip <REV>
where <REV> is the first revision you want to remove. It will remove that one and all decendents (including your merge commit).
Alternatively you can
hg qnew (if you don't already have a patch queue)
hg qimport <REV>
which will import a single revision into the patch queue. You can then add more, and then use the mq commands to edit, rearrange, delete, or whatever you want to do with those revisions. qdel deletes the current patch.
Edit: Obviously, you'll need to enable the MQ extension for both of these, unless you're using 2.8 or later. In that case strip is in the strip extension, and mq in the mq extension. Both are shipped with the standard installation.
hg --rollback can be used to undo the last transaction so as long as your hg pull is still the most recent transaction then you can use that. This command should be used with care though. See here for some more details.
you can:
hg update -C <version>
see the mercurial FAQ.
If you want to remove all traces of the pull form your history then you need to use an extension as Bert F suggests (the philosophy in mercurial is to never change history)
if you dont mind history containing your mistake you have two slightly different options hg update -C -r which will create a new branch at the version you specify or hg revert -r which will stay on the same branch but create a new uncommited change undoing everything.

How to repeatedly merge branches in Mercurial

We're using Mercurial where I work and I want to have a setup similar to how I used SVN:
Trunk
Tags
Production
Branches
Since Mercurial supports branches natively, I know how to create a named branch, but I can't find any documentation on how to repeatedly merge 'Trunk' with 'Production'.
Quite simply, I want to have a development branch for normal work and a production branch that I routinely pull changes from the development branch into. How do I do this with Mercurial?
As the previous poster mentioned, the transplant extension can be used for cherry-picking individual changes from one branch to another. If, however, you always want to pull all the latest changes, the hg merge command will get you there.
The simplest case is when you're using clones to implement branching (since that's the use case Mercurial is designed around). Assuming you've turned on the built-in fetch extension in your .hgrc / Mercurial.ini:
cd ~/src/development
# hack hack hack
hg commit -m "Made some changes"
cd ../production
hg fetch ../development
If you're using local branches:
hg update -C development
# hack hack hack
hg commit -m "Made some changes"
hg update -C production
hg merge development
hg commit -m "Merged from development"
Something like hg transplant? That's what we use on our dev and prod branches.