the state of art of named branches

10 views
Skip to first unread message

Uwe Brauer

unread,
Nov 28, 2021, 4:40:15 AM11/28/21
to hg-git, Dan Villiom Podlaski Christiansen

Hi

I just want to talk a bit about my experience using named branches with
hg-git and to add some questions.

I started to use them 2 years ago, using the patch by Manuel Jacob
6942fb0a8c9d

That patch works well, if everybody uses mercurial but pushes and pulls
to a git repository say bitbucket.

It does not work that well if one want so collaborate with other git
users, since, while pushing is ok, pulling results in the standard
vanilla behavior: git branches are imported as heads with bookmarks.

So you might end up with a named branch called feature and a new head on
the default branch with a bookmarks called, well feature.

You can merge these, but that results in a rather ugly graph and might
confuse the git users.


Now Dan's patch (topic branch) 4b51ff13e8f5 is a very different beast.
First you don't have the bit complicated configuration, of Manuel's
patch, but more importantly it imports git branches as named branches,
and that is very very useful.

It also export named branches as git branch.

In its current form there is only one thing to have to keep in mind.
Don't use heads (with bookmarks) on any branch, in that case hg refuses
to push.
I think this is a good idea but should have been added to the
documentation.

However I have some questions.

Delete a git branch in git.

I just run and experiment by removing a test branch and its commit in
git push -f origin c945bf50251150e0d4ad7ee751c7e9615cb4b3e8:master
git branch -rD origin/copyright
git push origin :copyright

And the git branch copyright and all its changeset are gone.

When I pull however the corresponding named branch is not deleted (well
that is impossible but it could have been either closed or a tag should
have been added to indicate that the branch should be stripped.)

Use a git branch with the same name later.

I have not much idea about git, but it seems that the following is
possible in git.

After some commits you merge say the feature branch into master.

Then you continue hacking and pushing to the master branch

At some later point in the feature you create again a feature branch for
hacking, that is however a new branch.

What will happen if I pull from such a git repository

Regards

Uwe Brauer

Dr. Arne Babenhauserheide

unread,
Nov 28, 2021, 5:21:03 AM11/28/21
to hg-...@googlegroups.com, Dan Villiom Podlaski Christiansen, Uwe Brauer

Uwe Brauer <o...@mat.ucm.es> writes:

> Use a git branch with the same name later.
>
> I have not much idea about git, but it seems that the following is
> possible in git.
>
> After some commits you merge say the feature branch into master.
>
> Then you continue hacking and pushing to the master branch
>
> At some later point in the feature you create again a feature branch for
> hacking, that is however a new branch.
>
> What will happen if I pull from such a git repository

You can do the same in Mercurial, but you have to force it: Mark the
branch as closed (with hg commit --close-branch), then merge it. Later
re-use the name.

cd /tmp
hg init closing
cd closing/
echo 1 > 1
hg ci -Am 1
echo 2 > 2
hg ci -Am 2
hg ci --close-branch -m close
hg up default
hg merge feature
hg ci -m merge
echo 3 > 3
hg ci -Am 3
# force creation of a same-named branch
hg branch feature --force
echo 4 > 4
hg ci -Am 4p
hg ci -Am 4 --amend
hg up default
echo 5 > 5
hg ci -Am "5 on default"
hg log -G


@ changeset: 7:5cfc355ea3a6
| tag: tip
| parent: 4:9abef3e9071d
| user: Arne Babenhauserheide <arne...@web.de>
| date: Sun Nov 28 11:19:20 2021 +0100
| summary: 5 on default
|
| o changeset: 6:543b73f6bac5
|/ branch: feature
| parent: 4:9abef3e9071d
| user: Arne Babenhauserheide <arne...@web.de>
| date: Sun Nov 28 11:17:55 2021 +0100
| summary: 4
|
o changeset: 4:9abef3e9071d
| user: Arne Babenhauserheide <arne...@web.de>
| date: Sun Nov 28 11:17:08 2021 +0100
| summary: 3
|
o changeset: 3:7ab1c92c0a0b
|\ parent: 0:d7d8dc2e9e63
| | parent: 2:02f5c584ebce
| | user: Arne Babenhauserheide <arne...@web.de>
| | date: Sun Nov 28 11:17:00 2021 +0100
| | summary: merge
| |
| _ changeset: 2:02f5c584ebce
| | branch: feature
| | user: Arne Babenhauserheide <arne...@web.de>
| | date: Sun Nov 28 11:16:49 2021 +0100
| | summary: close
| |
| o changeset: 1:d1d68b7a26f7
|/ branch: feature
| user: Arne Babenhauserheide <arne...@web.de>
| date: Sun Nov 28 11:16:37 2021 +0100
| summary: 2
|
o changeset: 0:d7d8dc2e9e63
user: Arne Babenhauserheide <arne...@web.de>
date: Sun Nov 28 11:16:12 2021 +0100
summary: 1

Best wishes,
Arne
--
Unpolitisch sein
heißt politisch sein,
ohne es zu merken.
draketo.de
signature.asc

Uwe Brauer

unread,
Nov 28, 2021, 5:29:20 AM11/28/21
to Dr. Arne Babenhauserheide, hg-...@googlegroups.com, Dan Villiom Podlaski Christiansen, Uwe Brauer
Thanks, but a couple of questions

1. Your script cannot work because of
> hg merge feature
and that branch was not created 😝

2. I know how to rename branches using the evolve extension as in
hg init
echo "First" > test.org
hg add test.org
hg commit -u "Bernhard Riemann <bernhard...@gmail.com>" -m "First"
echo "Second" >> test.org
hg commit -u "Bernhard Riemann <bernhard...@gmail.com>" -m "Second"
echo "Third" >> test.org
hg commit -u "Bernhard Riemann <bernhard...@gmail.com>" -m "Third"
echo "Forth" >> test.org
hg commit -m "Fourth"
hg up 0
hg branch feature
hg amend
hg evolve

3. So should I also use the evolve extension in your case?



Dr. Arne Babenhauserheide

unread,
Nov 28, 2021, 9:25:11 AM11/28/21
to hg-...@googlegroups.com, Dan Villiom Podlaski Christiansen, Uwe Brauer

Uwe Brauer <o...@mat.ucm.es> writes:

> [[S/MIME Signed Part:Bad signature from 285DB563F3701BD406D4FD057AA02D6E9200635A /CN=BRAUER UWE RICHARD OTTO - X2064123B/C=ES/SN=BRAUER/GN=UWE RICHARD OTTO/SerialNumber=IDCES-X2064123B]]
>>>> "AB" == Arne Babenhauserheide <arne...@web.de> writes:
>
>> Uwe Brauer <o...@mat.ucm.es> writes:
>
>>> Use a git branch with the same name later.
>>>
>>> I have not much idea about git, but it seems that the following is
>>> possible in git.
>>>
>>> After some commits you merge say the feature branch into master.
>>>
>>> Then you continue hacking and pushing to the master branch
>>>
>>> At some later point in the feature you create again a feature branch for
>>> hacking, that is however a new branch.
>>>
>>> What will happen if I pull from such a git repository
>
>> You can do the same in Mercurial, but you have to force it: Mark the
>> branch as closed (with hg commit --close-branch), then merge it. Later
>> re-use the name.
>
>> cd /tmp
>> hg init closing
>> cd closing/
>> echo 1 > 1
>> hg ci -Am 1
hg branch feature
>> echo 2 > 2
>> hg ci -Am 2
>> hg ci --close-branch -m close
>> hg up default
>> hg merge feature
>> hg ci -m merge
>> echo 3 > 3
>> hg ci -Am 3
>> # force creation of a same-named branch
>> hg branch feature --force
>> echo 4 > 4
>> hg ci -Am 4p
>> hg ci -Am 4 --amend
>> hg up default
>> echo 5 > 5
>> hg ci -Am "5 on default"
>> hg log -G
>
>
> Thanks, but a couple of questions
>
> 1. Your script cannot work because of
> > hg merge feature
> and that branch was not created 😝

Ah, sorry, I missed that command when copying. I now added it above.

> 2. I know how to rename branches using the evolve extension as in
> hg init
> echo "First" > test.org
> hg add test.org
> hg commit -u "Bernhard Riemann <bernhard...@gmail.com>" -m "First"
> echo "Second" >> test.org
> hg commit -u "Bernhard Riemann <bernhard...@gmail.com>" -m "Second"
> echo "Third" >> test.org
> hg commit -u "Bernhard Riemann <bernhard...@gmail.com>" -m "Third"
> echo "Forth" >> test.org
> hg commit -m "Fourth"
> hg up 0
> hg branch feature
> hg amend
> hg evolve
>
> 3. So should I also use the evolve extension in your case?

You could use that to remove the branchname, but I did not.

Sidenote: I’m not sure whether semantics of branches changed in the past
years to make reuse-branchname dangerous.
signature.asc

Uwe Brauer

unread,
Nov 28, 2021, 11:32:32 AM11/28/21
to Dr. Arne Babenhauserheide, hg-...@googlegroups.com, Dan Villiom Podlaski Christiansen, Uwe Brauer

> Uwe Brauer <o...@mat.ucm.es> writes:

> hg branch feature

> Ah, sorry, I missed that command when copying. I now added it above.



> You could use that to remove the branchname, but I did not.

Hm I tried the following without the force option, and it did not work


hg init
echo 1 > 1
hg ci -Am 1
hg branch feature
echo 2 > 2
hg ci -Am 2
hg ci --close-branch -m close
hg up default
hg merge feature
hg ci -m merge
echo 3 > 3
hg ci -Am 3
# force creation of a same-named branch
# hg branch feature --force
hg branch feature
hg amend
hg evolve
echo 4 > 4
hg ci -Am 4p
hg up default
echo 5 > 5
hg ci -Am "5 on default"
hg log -G



> Sidenote: I’m not sure whether semantics of branches changed in the past years to make reuse-branchname dangerous.

Also the question is whether hg-git will or does already support such a
feature.

Dr. Arne Babenhauserheide

unread,
Nov 29, 2021, 1:58:28 AM11/29/21
to hg-...@googlegroups.com, Dan Villiom Podlaski Christiansen, Uwe Brauer

Uwe Brauer <o...@mat.ucm.es> writes:

>> You could use that to remove the branchname, but I did not.
>
> Hm I tried the following without the force option, and it did not work

You’ll likely need to update to the root revision of the branch, then
rename it to default and evolve.

Using the same branch again without force won’t work.
Yes. I would assume that not.
signature.asc
Reply all
Reply to author
Forward
0 new messages