Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mercurial: How to push a bookmarked changeset which creates a new remote head as if I was pushing a new branch?

General question.

I'm trying to use bookmarks instead of branches in mercurial. The reason of it is that I don't want to have a lot of unnecessary fixed-named permanent items in branches.

The problem appears when I use a separate bookmark for a new feature development and I want to push it to the out repository. Well, hg doesn't allow me to push if creates 'new remote head'. What should I to to be able to make such a push as if I was creating a new branch?

Example (a way to reproduce the problem).

Alice creates repository:

C:\TestHg>mkdir Alice
C:\TestHg>cd Alice
C:\TestHg\Alice>hg init
C:\TestHg\Alice>echo line1>>file.txt
C:\TestHg\Alice>hg addremove
adding file.txt
C:\TestHg\Alice>hg commit -m "Initial commit."

Bob clones Alice's repository:

C:\TestHg\Alice>cd ..
C:\TestHg>hg clone Alice Bob
updating to branch default
1 files updated, 0 files merged, 0 files removed, 0 files unresolved

Alice makes some changes in the code of the project:

C:\TestHg>cd Alice
C:\TestHg\Alice>echo line2 by Alice>>file.txt
C:\TestHg\Alice>hg commit -m "Alice continues her work on the project."

Bob starts his work on New Cool Feature using a separate bookmark to identify his independent 'branch' of work:

C:\TestHg\Alice>cd ..\Bob
C:\TestHg\Bob>hg bookmarks
no bookmarks set
C:\TestHg\Bob>hg bookmark NewCoolFeature
C:\TestHg\Bob>hg bookmarks
 * NewCoolFeature            0:792db6cfc262
C:\TestHg\Bob>echo line2 by Bob (as a part of New Cool Feature implementation)>>file.txt
C:\TestHg\Bob>hg commit -m "Bob starts his work on New Cool Feature"

Bob tries to push his changes to Alice's directory:

C:\TestHg\Bob>hg push -B NewCoolFeature
pushing to C:\TestHg\Alice
searching for changes
abort: push creates new remote head 38506e28a438!
(you should pull and merge or use push -f to force)

Ok, first Bob has to pull Alice's changes to his own repository:

C:\TestHg\Bob>hg pull
pulling from C:\TestHg\Alice
searching for changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files (+1 heads)
(run 'hg heads' to see heads, 'hg merge' to merge)

Well, now Bob has two heads in his repository which is fine.

C:\TestHg\Bob>hg glog
o  changeset:   2:66beef200ba4
|  tag:         tip
|  parent:      0:792db6cfc262
|  user:        Alice
|  date:        Sun May 20 13:10:04 2012 +0400
|  summary:     Alice continues her work on the project.
|
| @  changeset:   1:38506e28a438
|/   bookmark:    NewCoolFeature
|    user:        Bob
|    date:        Sun May 20 13:12:26 2012 +0400
|    summary:     Bob starts his work on New Cool Feature
|
o  changeset:   0:792db6cfc262
   user:        Alice
   date:        Sun May 20 13:08:39 2012 +0400
   summary:     Initial commit.

After trying to make one more push Bob is asked for merge. Bob doesn't want to make the merge, because his results of work on New Cool Feature are not ready yet for the merge.

C:\TestHg\Bob>hg push -B NewCoolFeature
pushing to C:\TestHg\Alice
searching for changes
abort: push creates new remote head 38506e28a438!
(did you forget to merge? use push -f to force)

Example related question.

What should Bob do to be able to push his changes to Alice's repo as if his changes are in a separate branch?

Updates

UPD1: In a real life situation Alice's repo is used as a central sync point for all members of the development team.

like image 566
Igor Soloydenko Avatar asked May 20 '12 10:05

Igor Soloydenko


1 Answers

He should either:

  • Not push. Why does he want his unfinished changes on someone else's machine?
  • Force it. He was asked if he forgot to merge. He didn't. He wants a new head, so force it.

The message is there because often it's easy to create a new head without realising. However sometimes it's exactly what you want, and so there's the override switch.

like image 68
Paul S Avatar answered Sep 24 '22 06:09

Paul S