Question

I'm trying to push a changeset that contains a named branch to a Mercurial repository hosted on Bitbucket, and I'm getting the push creates a new remote head (did you forget to merge?) error. This is happening regardless of whether or not I specify the --new-branch option to hg push.

(The Mercurial documentation recommends in such a case to "pull and merge before pushing," but when I run hg incoming it reports "no changes found", i.e., there's nothing in the Bitbucket repo that isn't in my local repo).

As the title suggests, there's a wrinkle to my scenario that may be relevant to the behavior I'm seeing, which I'll attempt to explain below:

The name of the branch I'm trying to push to the Bitbucket repo is actually the same as the name of a branch that I successfully pushed earlier, but then later closed via hg commit --close-branch, because I had erroneously created it with the wrong parent revision.

(It's a long story why the new branch name has to be the same as the old one -- but it does.)

I don't recall any problem pushing the branch the first time around. I believe I used hg push --new-branch to do it, but the actual command has scrolled off the top of my command-line history buffer by now, so I can't prove that. Regardless, though, the --new-branch option isn't solving the problem this time around.

Here's a diagram of the revision history:

   0         0. Baseline of production code
   |\
   1 \       1. Fixes to production code
   |  \
   2   \     2. More fixes to production code
  /|\  |
 3 | | |     3. Import new feature drop from offshore developer (*),
 | | | |        to named branch "drop1". (But I goofed! Parent
 | | | |        revision should have been r0.)
 | | | |
 4 | | |     4. "hg commit --close_branch" to prune the
   | | |        original "drop1" branch created in error.
   | | |
   | | 5     5. Import new feature drop again,
   | | |        this time with correct parent revision.
   | | |        Named branch via "branch -f drop1"
   | | |        (to shadow the name of the closed branch).
   |  \|
   |   6     6. Merge bug fixes from production into drop1
   |   |
   |   7     7. Fixes to drop1 code
   |
   8         8. Ongoing maintenance of production code

I've been able to commit r0 through r4 to the Bitbucket repo, but attempting to push r5 (with or without the --new-branch option) gives me:

abort: push creates new remote head 439d23090786 on branch 'drop1'!
(did you forget to merge? use push -f to force)

So the questions are:

  1. Do I have any choice but to use push -f to get r5 into the Bitbucket repo?
  2. Is it possible that Bitbucket's version of Mercurial doesn't understand that the original "drop1" branch was closed by the successful push of r4, thence causing hg push --new-branch --rev 5 to fail?

(*) Why the offshore developer isn't yet using Mercurial and Bitbucket directly, rather than emailing me code drops as zip archives, is a tale too horrible to tell.]

Was it helpful?

Solution

You are creating a second head of 'drop1', even though the other is closed. Just use -f as the error message states.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top