comparison mercurial/commands.py @ 35746:e5b6ba786d83

branch: allow changing branch name to existing name if possible With the functionality added in previous patch we can change branches of a revision but not everytime even if it's possible to do so. For example cosider the following case: o 3 added a (foo) o 2 added b (foo) o 1 added c (bar) o 0 added d (bar) Here if I want to change the branch of rev 2,3 to bar, it was not possible and it will say, "a branch with same name exists". This patch allows us to change branch of 2,3 to bar. The underlying logic for changing branch finds the changesets from the revs passed which have no parents in revs. We only support revsets which have only one such root, so to support this we check whether the parent of the root has the same name as that of the new name and if so, we can use the new name to change branches. Differential Revision: https://phab.mercurial-scm.org/D1913
author Pulkit Goyal <7895pulkit@gmail.com>
date Fri, 19 Jan 2018 18:45:20 +0530
parents 3bd8ab4c80a5
children 6d65cef5b038
comparison
equal deleted inserted replaced
35745:3bd8ab4c80a5 35746:e5b6ba786d83
1053 ui.status(_('reset working directory to branch %s\n') % label) 1053 ui.status(_('reset working directory to branch %s\n') % label)
1054 elif label: 1054 elif label:
1055 1055
1056 scmutil.checknewlabel(repo, label, 'branch') 1056 scmutil.checknewlabel(repo, label, 'branch')
1057 if revs: 1057 if revs:
1058 # XXX: we should allow setting name to existing branch if the
1059 # branch of root of the revs is same as the new branch name
1060 if label in repo.branchmap():
1061 raise error.Abort(_('a branch of the same'
1062 ' name already exists'))
1063 return cmdutil.changebranch(ui, repo, revs, label) 1058 return cmdutil.changebranch(ui, repo, revs, label)
1064 1059
1065 if not opts.get('force') and label in repo.branchmap(): 1060 if not opts.get('force') and label in repo.branchmap():
1066 if label not in [p.branch() for p in repo[None].parents()]: 1061 if label not in [p.branch() for p in repo[None].parents()]:
1067 raise error.Abort(_('a branch of the same name already' 1062 raise error.Abort(_('a branch of the same name already'