Mercury workflow that allows you to work with several separate tasks in parallel

There are many discussions that touch upon questions that seem to be related to this question, but actually did not directly answer it. Basically, using Mercurial, I want to work simultaneously with several independent tasks within the same project.

For example, I’m assigned the errors X and Y at the same time. I’ve been working on X for a while, until I’m at the point where I need to pause it for several days. Let's say I need input from someone else who is not working. So I want to get to work with error-Y. Clearly, one option is simply to create a new clone of stable storage. The problem is that this requires a new working directory, a new Eclipse project, yada-yada ... I would like to be able to save one working copy.

With SVN, I can create a new branch in the repository for each task and just switch the working copy between them. With ClearCase, I could create a new activity for each of them. In both cases, I could work on each task on my own, in a clean environment. Then, when I finished the task, I can only commit / click this on the central repo.

I read about Hg called branches and bookmarks. I’m sure that somewhere there is a solution that corresponds to our workflow, but I don’t see this yet. Can someone explain the steps I can use to achieve this? Is it possible to create two chapters in my local repository with which I can simply switch between them? And then update / lock / push / pull these chapters yourself? In practice, I may not even combine them locally, just pushing everyone to our stable repo when it is ready. Am I just thinking about it completely wrong? I am very new to Hg (and generally DVCS) and trying to develop a workflow for it.

+4
source share
5 answers

The process you are describing is very simple to implement with Mercurial, and there are many ways to do this.

For example, you can use anonymous branches:

  • Place the tag or bookmark in the change set that you want to use as a start for both developments.
  • Design your first fix by doing what you need.
  • If you want to start another development line, just update the previously saved change set
  • Develop a second fix and commit changes

You have just created two anonymous branches in your working copy, starting with the accepted set of changes.

You are not limited by the number of anonymous branches or their starting point, you can even create new anonymous branches on your anonymous branches.

In some cases, tools like TortoiseHG or the GraphLog extension can really help you understand who the parents of each branch are and what is the best way to merge them.

Bookmarks are just a way to easily track various changes; you can bookmark each of your new goals. Depending on the version of Mercurial you are using, the bookmark will “follow” each new commit you make in your particular branch or not.

You can also use the named branch to achieve the same goal, but the problem is that you cannot easily remove the named branch after creating it, the name will still be them.

PS: this workflow or something very similar is described in the following blog post: http://stevelosh.com/blog/2010/02/mercurial-workflows-branch-as-needed/

+3
source

In general, I just go ahead and create named branches for any subproject or nontrivial bug fix. You can easily switch between branches between "hg update". When I was done with something, I simply combined it with default.

Here is an article with good branching information in Mercurial: http://stevelosh.com/blog/2009/08/a-guide-to-branching-in-mercurial/

+1
source

I wrote a guide on using named branches for tasks that you might find useful. You write in your answer:

Here are some errors that I found:

  • Merge your function branch to "default" when you are ready to push - you cannot just redirect your branch to a remote repository

You need hg push --new-branch if you want to allow Mercurial to create a new named branch in the remote repository. This is because branches are global and long-lived - so you shouldn't just create them with temporary names.

  • When you click, make sure that you select only clicking the "default" branch - if you do not, it will also try to push any other function branches that have not yet been clicked.

You can use hg push --branch X only to push the X branch (and any ancestors of course).

  • Hg will complain that your push creates new remote branches - this is normal as long as the branch is already merged locally.

Actually, merging it locally has nothing to do with this message - it comes every time you enter a new branch, and it does not matter if it merges or not. Named branches are the tool you use when you want to have several chapters in a common repository. By naming the branches, you avoid confusion when people pull and update: hg update default will still give you the main line of development, although there may be an X branch with very experimental and unstable code.

+1
source

When working with multiple tasks / bugs, I prefer to use bookmarks on named branches. They do not clutter your story with branching information (but this may be a personal preference).

Usually you only work with the default branch. To track this “main line of development", we create a bookmark called "master" (or, as you would like to call it). Now, before you start working with the error X, you create a bookmark "bugX".

  • hg bookmark master
    • ... work with the default branch, as always ...
  • hg bookmark bugX
    • ... work on bugX
  • hg commit -m "bugX 1"
    • ... work on bugX
  • hg commit -m "bugX 2"

Then you should work with error Y, because you need, for example, wait for someone else to enter. To do this, first go back to the main bookmark (where you left the "main line"), create a new bookmark for error Y and start working on it.

  • hg update wizard
  • hg bookmark bugY
    • ... work on bugY
  • hg commit -m "bugY 1"

You also need to stop working with error Y, and you want to continue your work on the "main line". First, you pull the latest changes from the central repo, and then start working on the main branch. When the function is finished, you can click it. Remember to just push the master branch using "hg push -r master":

  • hg update wizard
  • hg pull --rebase
    • ... work on the master
  • hg commit -m "new feature 1"
    • ... work on the master
  • hg commit -m "new feature 2"
  • hg push -r master

Someday laster you can end the error X:

  • hb update bugX
    • ... work on bug X
  • hg commit -m "bugX bug fixed

This fix should now be transferred to the main branch and transferred to the central repo. You can combine it with "hg merge bugX" or even better - reinstall it. When done, remove the bugX bookmark:

  • hg update bugX
  • hg rebase -b bugX -d master
  • hg bookmark -f master
  • hg bookmark -d bugX
  • hg push -r master

"hg bookmark -f master" requires that the main bookmark now points to the last bugX change set that was recreated on top of the main branch (I think this is done automatically using Mercury 2.1).

The same procedure can now be performed with bugY, and you will get a direct history.

As a team, you might even think about moving the main bookmark to the central repository so that it is not supported after pulling (hg push -B master).

This workflow is also described more or less in this blog post .

+1
source

Good, so I think I figured it out. I think I will use the named branches. Thanks for helping everyone.

Here are some errors that I found:

  • Merge your function branch to "default" when you are ready to push - you cannot just redirect your branch to a remote repository
  • When you click, make sure that you select only clicking the "default" branch - if you do not, it will also try to push any other function branches that have not yet been clicked.
  • Hg will complain that your push creates new remote branches - this is normal as long as the branch is already merged locally.

If someone who is looking at this has additional comments and / or suggestions, I will be happy to hear them. I am not 100% satisfied with this decision yet.

0
source

Source: https://habr.com/ru/post/1396257/


All Articles