diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -774,6 +774,35 @@ def backout(ui, repo, rev, **opts): ui.status(_('(use "backout --merge" ' 'if you want to auto-merge)\n')) +def branch(ui, repo, label=None): + """set or show the current branch name + + With , set the current branch name. Otherwise, show the + current branch name. + """ + + if label is not None: + repo.opener("branch", "w").write(label) + else: + b = repo.workingctx().branch() + if b: + ui.write("%s\n" % b) + +def branches(ui, repo): + """list repository named branches + + List the repository's named branches. + """ + b = repo.branchtags() + l = [(-repo.changelog.rev(n), n, t) for t,n in b.items()] + l.sort() + for r, n, t in l: + hexfunc = ui.debugflag and hex or short + if ui.quiet: + ui.write("%s\n" % t) + else: + ui.write("%-30s %s:%s\n" % (t, -r, hexfunc(n))) + def bundle(ui, repo, fname, dest=None, **opts): """create a changegroup file @@ -2850,6 +2879,8 @@ table = { ('u', 'user', '', _('record user as committer')), ] + walkopts, _('hg backout [OPTION]... REV')), + "branch": (branch, [], _('hg branch [NAME]')), + "branches": (branches, [], _('hg branches')), "bundle": (bundle, [('f', 'force', None, diff --git a/tests/test-debugcomplete.out b/tests/test-debugcomplete.out --- a/tests/test-debugcomplete.out +++ b/tests/test-debugcomplete.out @@ -4,6 +4,8 @@ addremove annotate archive backout +branch +branches bundle cat clone diff --git a/tests/test-globalopts.out b/tests/test-globalopts.out --- a/tests/test-globalopts.out +++ b/tests/test-globalopts.out @@ -120,6 +120,8 @@ list of commands (use "hg help -v" to sh annotate show changeset information per file line archive create unversioned archive of a repository revision backout reverse effect of earlier changeset + branch set or show the current branch name + branches list repository named branches bundle create a changegroup file cat output the latest or given revisions of files clone make a copy of an existing repository @@ -168,6 +170,8 @@ list of commands (use "hg help -v" to sh annotate show changeset information per file line archive create unversioned archive of a repository revision backout reverse effect of earlier changeset + branch set or show the current branch name + branches list repository named branches bundle create a changegroup file cat output the latest or given revisions of files clone make a copy of an existing repository diff --git a/tests/test-help.out b/tests/test-help.out --- a/tests/test-help.out +++ b/tests/test-help.out @@ -43,6 +43,8 @@ list of commands (use "hg help -v" to sh annotate show changeset information per file line archive create unversioned archive of a repository revision backout reverse effect of earlier changeset + branch set or show the current branch name + branches list repository named branches bundle create a changegroup file cat output the latest or given revisions of files clone make a copy of an existing repository @@ -87,6 +89,8 @@ list of commands (use "hg help -v" to sh annotate show changeset information per file line archive create unversioned archive of a repository revision backout reverse effect of earlier changeset + branch set or show the current branch name + branches list repository named branches bundle create a changegroup file cat output the latest or given revisions of files clone make a copy of an existing repository diff --git a/tests/test-newbranch b/tests/test-newbranch --- a/tests/test-newbranch +++ b/tests/test-newbranch @@ -2,27 +2,32 @@ hg init t cd t +hg branches echo foo > a hg add a hg ci -m "initial" -d "0 0" -echo foo > .hg/branch +hg branch foo +hg branch hg ci -m "add branch name" -d "0 0" -echo bar > .hg/branch +hg branch bar hg ci -m "change branch name" -d "0 0" -rm .hg/branch +hg branch "" hg ci -m "clear branch name" -d "0 0" hg co foo -cat .hg/branch +hg branch echo bleah > a hg ci -m "modify a branch" -d "0 0" hg merge -cat .hg/branch +hg branch HG_MERGE=true hg ci -m "merge" -d "0 0" hg log +hg branches +hg branches -q + echo % test for invalid branch cache hg rollback hg tip diff --git a/tests/test-newbranch.out b/tests/test-newbranch.out --- a/tests/test-newbranch.out +++ b/tests/test-newbranch.out @@ -1,3 +1,4 @@ +foo 0 files updated, 0 files merged, 0 files removed, 0 files unresolved foo 0 files updated, 0 files merged, 0 files removed, 0 files unresolved @@ -41,6 +42,10 @@ user: test date: Thu Jan 01 00:00:00 1970 +0000 summary: initial +foo 5:dc140083783b +bar 2:ed2bbf4e0102 +foo +bar % test for invalid branch cache rolling back last transaction changeset: 4:98d14f698afe