Mercurial > hg
comparison mercurial/commands.py @ 35745:3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
This patch adds a new --rev flag to hg branch which can be used to change branch
of revisions. This is motivated from topic extension where you can change topic
on revisions but this one has few restrictions which are:
1) You cannot change branch name in between the stack
2) You cannot change branch name and set it to an existing name
3) You cannot change branch of non-linear set of commits
4) You cannot change branch of merge commits.
Tests are added for the same.
.. feature::
An experimental flag `--rev` to `hg branch` which can be used to change
branch of changesets.
Differential Revision: https://phab.mercurial-scm.org/D1074
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Sun, 15 Oct 2017 23:08:45 +0530 |
parents | 35a0f6f31eef |
children | e5b6ba786d83 |
comparison
equal
deleted
inserted
replaced
35744:8685192a8733 | 35745:3bd8ab4c80a5 |
---|---|
1000 bookmarks.printbookmarks(ui, repo, **opts) | 1000 bookmarks.printbookmarks(ui, repo, **opts) |
1001 | 1001 |
1002 @command('branch', | 1002 @command('branch', |
1003 [('f', 'force', None, | 1003 [('f', 'force', None, |
1004 _('set branch name even if it shadows an existing branch')), | 1004 _('set branch name even if it shadows an existing branch')), |
1005 ('C', 'clean', None, _('reset branch name to parent branch name'))], | 1005 ('C', 'clean', None, _('reset branch name to parent branch name')), |
1006 ('r', 'rev', [], _('change branches of the given revs (EXPERIMENTAL)')), | |
1007 ], | |
1006 _('[-fC] [NAME]')) | 1008 _('[-fC] [NAME]')) |
1007 def branch(ui, repo, label=None, **opts): | 1009 def branch(ui, repo, label=None, **opts): |
1008 """set or show the current branch name | 1010 """set or show the current branch name |
1009 | 1011 |
1010 .. note:: | 1012 .. note:: |
1032 considered closed. | 1034 considered closed. |
1033 | 1035 |
1034 Returns 0 on success. | 1036 Returns 0 on success. |
1035 """ | 1037 """ |
1036 opts = pycompat.byteskwargs(opts) | 1038 opts = pycompat.byteskwargs(opts) |
1039 revs = opts.get('rev') | |
1037 if label: | 1040 if label: |
1038 label = label.strip() | 1041 label = label.strip() |
1039 | 1042 |
1040 if not opts.get('clean') and not label: | 1043 if not opts.get('clean') and not label: |
1044 if revs: | |
1045 raise error.Abort(_("no branch name specified for the revisions")) | |
1041 ui.write("%s\n" % repo.dirstate.branch()) | 1046 ui.write("%s\n" % repo.dirstate.branch()) |
1042 return | 1047 return |
1043 | 1048 |
1044 with repo.wlock(): | 1049 with repo.wlock(): |
1045 if opts.get('clean'): | 1050 if opts.get('clean'): |
1046 label = repo[None].p1().branch() | 1051 label = repo[None].p1().branch() |
1047 repo.dirstate.setbranch(label) | 1052 repo.dirstate.setbranch(label) |
1048 ui.status(_('reset working directory to branch %s\n') % label) | 1053 ui.status(_('reset working directory to branch %s\n') % label) |
1049 elif label: | 1054 elif label: |
1055 | |
1056 scmutil.checknewlabel(repo, label, 'branch') | |
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) | |
1064 | |
1050 if not opts.get('force') and label in repo.branchmap(): | 1065 if not opts.get('force') and label in repo.branchmap(): |
1051 if label not in [p.branch() for p in repo[None].parents()]: | 1066 if label not in [p.branch() for p in repo[None].parents()]: |
1052 raise error.Abort(_('a branch of the same name already' | 1067 raise error.Abort(_('a branch of the same name already' |
1053 ' exists'), | 1068 ' exists'), |
1054 # i18n: "it" refers to an existing branch | 1069 # i18n: "it" refers to an existing branch |
1055 hint=_("use 'hg update' to switch to it")) | 1070 hint=_("use 'hg update' to switch to it")) |
1056 scmutil.checknewlabel(repo, label, 'branch') | 1071 |
1057 repo.dirstate.setbranch(label) | 1072 repo.dirstate.setbranch(label) |
1058 ui.status(_('marked working directory as branch %s\n') % label) | 1073 ui.status(_('marked working directory as branch %s\n') % label) |
1059 | 1074 |
1060 # find any open named branches aside from default | 1075 # find any open named branches aside from default |
1061 others = [n for n, h, t, c in repo.branchmap().iterbranches() | 1076 others = [n for n, h, t, c in repo.branchmap().iterbranches() |