comparison mercurial/cmdutil.py @ 44401:92b7caf4cb9e stable

branch: make --force work even when specifying revs The `hg branch` command accepts a `--force` parameter that allows to "set branch name even if it shadows an existing branch". However, before this patch, that didn?t work when specifying revs with `-r`.
author Manuel Jacob <me@manueljacob.de>
date Sun, 01 Mar 2020 19:39:23 +0100
parents b339faf3f843
children d543ef183eb8
comparison
equal deleted inserted replaced
44378:bb58931d0c4f 44401:92b7caf4cb9e
959 return list(choice.values())[0] 959 return list(choice.values())[0]
960 960
961 raise error.UnknownCommand(cmd, allcmds) 961 raise error.UnknownCommand(cmd, allcmds)
962 962
963 963
964 def changebranch(ui, repo, revs, label): 964 def changebranch(ui, repo, revs, label, opts):
965 """ Change the branch name of given revs to label """ 965 """ Change the branch name of given revs to label """
966 966
967 with repo.wlock(), repo.lock(), repo.transaction(b'branches'): 967 with repo.wlock(), repo.lock(), repo.transaction(b'branches'):
968 # abort in case of uncommitted merge or dirty wdir 968 # abort in case of uncommitted merge or dirty wdir
969 bailifchanged(repo) 969 bailifchanged(repo)
977 ) 977 )
978 rewriteutil.precheck(repo, revs, b'change branch of') 978 rewriteutil.precheck(repo, revs, b'change branch of')
979 979
980 root = repo[roots.first()] 980 root = repo[roots.first()]
981 rpb = {parent.branch() for parent in root.parents()} 981 rpb = {parent.branch() for parent in root.parents()}
982 if label not in rpb and label in repo.branchmap(): 982 if (
983 not opts.get(b'force')
984 and label not in rpb
985 and label in repo.branchmap()
986 ):
983 raise error.Abort(_(b"a branch of the same name already exists")) 987 raise error.Abort(_(b"a branch of the same name already exists"))
984 988
985 if repo.revs(b'obsolete() and %ld', revs): 989 if repo.revs(b'obsolete() and %ld', revs):
986 raise error.Abort( 990 raise error.Abort(
987 _(b"cannot change branch of a obsolete changeset") 991 _(b"cannot change branch of a obsolete changeset")