Rename default branch in TortoiseHG - mercurial

Is it possible to rename 'default' to 'production' in TortoiseHG?

You cannot rename a branch in Mercurial (or TortoiseHg for that matter). What you do instead is to start a new branch called production and base it on the current default branch.
You can do this in TortoiseHg 2.0, where you
Click the row representing the working directory
Click the branch button
Click to open a new branch
Fill in the branch name and click OK
Enter a commit message and click Commit.
This will create a new branch with the name production. The old default branch will remain and you can thus put new features there before merging them into production when they're stable.

You cannot do it directly from the Tortoise2.0+ settings, but through the command-line hg.
As documented in hgbook:
Mercurial lets you assign a persistent name to a branch.
There always exists a branch named default. Even before you start naming branches yourself, you can find traces of the default branch if you look for them.
To start working with named branches, use the hg branches command
$ hg branch production
marked working directory as branch production
$ hg branch
production
Check then if that change is reflected in TortoiseHg

Related

Only local branch

I want to have local branch in my cloned repository that will not exist in main repository. To do this I create branch named "new_branch", develop and commit to it. Sometimes I make commites to default branch and after that I make "push -b default" that the branch "new_branch" not appeared in main repository. After the development in "new_branch" finished I make merge to default branch and I want to make push for default branch "push -b default". I get message "abort: push creates new remote branches: new_branch! (use 'hg push --new-branch' to create new remote branches)". Can I have a only local branch in Mercurial?
You can try:
LocalBranch Extension (only Tim Lee fork seems to work with current Mercurial)
MQ (and push without --mq option)
Phases can be used for this in modern Mercurial:
# hg phase --secret -r 7::10
Will mark changes 7 through 10 as secret, as so they won't be pushed, pulled, cloned, etc.
Once you create a branch using hg branch, it is a permanent part of the changeset. It will always require you to push using the --new-branch option. You cannot strip the branch name without modifying history.
If you want give a local name to a branch that does not get propagated when you push, then you should use hg bookmark instead.

In TortoiseHg, how can i "Merge local with selected"?

In effect, I would like to do the opposite of "Merge with local"
To clarify:
We have a release branch and a default branch. When doing bug fixes on the release branch, here's the routine:
Update to the release branch
Implement bug fix, and commit
Update to the default branch
Right-click on the bug fix commit from the release branch, and select "Merge with local..."
Since a lot of work is done on the release branch, it gets tedious to Update between the branches all the time. In previous versions of TortoiseHg, I could select the branch before doing the merge, in effect doing a "Merge local with selected". This would eliminate steps 1 and 3 above.
Is this doable in TortoiseHg anymore?
Three-way merges are basically symmetric: you merge two divergent versions of your code (the two branches) into a single version (the merge commit). There is no technical different between updating to default and merging with release, or doing it the other way around. In particular, the merge conflicts are exactly the same.
In Mercurial, there is an extra twist because of the named branch names: by default, the merge commit will inherit the branch name of its first parent. If you don't update to default before merging, the first parent will thus be release. But you can change the branch name before committing.
On the command line it's just:
$ hg update release
$ hg merge default
$ hg branch default
$ hg commit -m 'Merged release into default'
In the pre-2.0 versions of TortoiseHg you were presented with this dialog to commit the merge:
The button above the commit message saying "branch: release" could be used to change branch of the next commit — the merge commit. In TortoiseHg 2.x the dialog looks like this:
and there's no longer a button for changing branch.
Maybe you can ask the TortoiseHg developers to add the button again, or you can use Henrik Stuart's TortoiseHg if you want a pre-2.0 TortoiseHg that is compatible with modern versions of Mercurial.
I haven't found a way, even command line merge is always with local. I just keep a clone for each branch and switch between clones instead of updating a single clone. For large projects this prevents the usually time-intensive "rebuild all" when changing branches. Adds extra pull step but saves time overall:
In release clone, implement bug fix and commit.
In default clone, pull from release and merge with local.

creating a new branch in mercurial: "abort: push creates new remote head"

I am trying to do something very simple: create a new branch. But I messed up. Where did I make the mistake, and how do I fix it?
I am the only user of Mercurial. I had revision 54 committed and pushed to remote repository. I wanted to create a branch based on revision 53, so I updated my local copy to revision 53, made changes, and committed (ignoring the warning about "it's not the head"). Then when I am trying to push to remote repository, it says
abort: push creates new remote head
Maybe I needed to tell Mercurial that I want to create a new branch? If so, how and at what point?
Thanks!
You tell Mercurial that it can go ahead with
$ hg push --force
You need to force it since multiple (unnamed) heads are normally discouraged. The problem with them is that people that clone the repository wont know which one to use. But since you're the only user you can just go ahead and push.
The alternative is to use a named branch (with hg branch) and then you'll use
$ hg push --new-branch
to allow the creation of a new branch on the remote. Named branches have the advantage that they make it easy to distinguish the two branches. They have the disadvantage that they are permanent. Permanent means that you cannot remove the branch name from the changesets on the branch — the name is literally baked directly into the changeset.
Bookmarks provide a way to have non-permanent branch names, see hg help bookmarks.
Another reason for this error: probably there are some UNMERGED changes form the central repo in your default branch.
hg up default
hg merge
hg ci -m "Merge"
hg pus
I did this. Using TortoiseHg ... this is how I fixed it:
In settings, I enabled the Strip extension then right clicked the branch i did not want, Modified History - strip. If you have pushed, then it needs to be stripped from all other repositories, including workmates who have pulled your unwanted branch.
An alternative is to merge the unwanted branch into your main branch, but do not take any of the changes from that branch - I am unsure of how that mechanism works.

Mercurial: How can I import only some changesets from a repository?

I have a repository, called "my project" based in a framework called "framework". The two of them have each it's repository, unrelated between them, with each branches and tags. I want to receive "framework"'s updates in my repository, but only from "default" branch and not from others. And, of course, I do not want to have "framework"'s tags in my repository, as it is a totally different project.
I have Mercurial HG, and I would like to be able to pull changes from "framework" repository directly from my "Manage repository" page.
Furthermore, I only want to download latest changesets, since I started my project not long ago. And It would be perfect if I could rename the "framework"'s default branch to other name in my repo, e.g. "Framework Changesets".
Note: I do not have write access to the "framework" repository.
I tried to do what mercurial wiki said:
hg pull -f -r default "framework"
It was OK, until I realised I had downloaded all the tags from the "framework" repository, and I had downloaded all the changesets from the remote repository. Furthermore, when in TortoiseHG->Configuration->Synchronization I put the "framework" repository as a remote repository for that project, and pulled from the remote repository, I got all the branches from that repository.
Of course I wasn't able to change default branch name, and updated my default branch, even though I tried to use hg convert --branchmap (but I didn't know how to use it).
Is there any solution to my problem? or even a partial solution?
I think you can address this issue through a combination of these things:
Pulling specific branches
Using the command line: hg pull -r <branch name>
Using TortoiseHg v1.1.X:
Check for incoming changesets by using the button labeled Download and view incoming changesets
Right-click on the tip of the branch you want to pull and select Pull to here
Reject the rest of the changesets using the Reject button
Removing existing tags
You can always hand-edit the .hgtags file to remove tags created on the "framework" branch, but I don't know of a way to pull changesets without the tags.
Changing branch name
Using the mq extension you can change the named branch that your new "framework" changesets live on. See answer to "Apply patches in branch" for instructions on how to do this in TortoiseHg v1.1.X, as well as the CLI. The basic idea here is to create a named branch with the name you want, import all of the "framework" changesets you pulled into a patch queue, and then apply them to the new named branch. They will shed the branch name from "framework" and use the branch name of the branch you applied them to.
If you are going to pull from "framework" more than once, you would need to use the patch queue to move only the new changesets with each pull. It should be easy to see which changesets you haven't moved yet.
We can specify the branch name by appending branch name with a # symbol in the clone url.
e.g.
hg clone --verbose https://user#cloneurl/my_product#MY_BRANCH "C:\myCode"

Apply patches in branch

I receive a patches from a contributor. Apparently, he produces the patches in trunk. However, I would like to commit his changes to a new branch. May I know how I can do so through Tortoise-Hg?
The directions found below assume you want the patches isolated on a named branch.
Using the command-line, it is easy to apply patches to a new named branch. However if you want to do this using TortoiseHg only, you must create the named branch with an empty commit prior to applying the patches.
Using the command-line:
hg branch <branch name>
hg qimport --push <patch-file-1>
hg qimport --push <patch-file-2>
hg qfinish --applied
Using TortoiseHg v1.1.x:
Import the patch files to your patch queue (without applying them).
Create a new named branch using an empty commit:
Open a commit dialog
Click the button labeled "branch: default"
Select "Open a new named branch"
Enter your branch name in the provided text box
Click the OK button.
Enter a commit message (e.g. "Created branch for patches from ") and click "Commit".
Apply the patches in your patch queue (one at a time or all together).
Right-click on the patches in your patch queue and select "Finish Applied"
Using TortoiseHg v2.0.x:
The same process used for TortoiseHg v1.1.x will work. The process to create the named branch with an empty commit is slightly different, but the overall concept is the same.
In TortoiseHg 2.7, update to the branch you want to apply the patch to (or create it if it doesn't exist). Choose Repository > Import and use Browse... to select an individual patch file, or Browse Directory... to import a folder of patches.
The original branch from where the patch came from doesn't matter to hg import unless you use the option --exact. So, you should create the branch you want and apply the patch:
hg branch new_branch
hg import /tmp/patch.txt