Merge lp:~garyvdm/bzr/commit-BoundBranchOutOfDate into lp:bzr

Proposed by Gary van der Merwe
Status: Merged
Merged at revision: not available
Proposed branch: lp:~garyvdm/bzr/commit-BoundBranchOutOfDate
Merge into: lp:bzr
Diff against target: 75 lines (+15/-7)
4 files modified
NEWS (+7/-0)
bzrlib/builtins.py (+5/-4)
bzrlib/errors.py (+2/-1)
bzrlib/tests/commands/test_commit.py (+1/-2)
To merge this branch: bzr merge lp:~garyvdm/bzr/commit-BoundBranchOutOfDate
Reviewer Review Type Date Requested Status
Martin Pool Approve
Review via email: mp+20393@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Gary van der Merwe (garyvdm) wrote :

In qbzr, we would like to detect when a commit fails because the bound branch is not up to date. But because the Commit.run method returns a very generic BzrCommandError, this cannot be done. This patch changes things so that it returns a more specific BoundBranchOutOfDate.

Revision history for this message
Martin Pool (mbp) wrote :

Nice.

I wonder if the extra message should somehow always be defined in the error, but this is fine for now.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'NEWS'
--- NEWS 2010-03-02 19:50:18 +0000
+++ NEWS 2010-03-03 08:27:18 +0000
@@ -130,12 +130,19 @@
130* ``bzrlib.branchbuilder.BranchBuilder.build_snapshot`` now accepts a130* ``bzrlib.branchbuilder.BranchBuilder.build_snapshot`` now accepts a
131 ``message_callback`` in the same way that commit does. (Robert Collins)131 ``message_callback`` in the same way that commit does. (Robert Collins)
132132
133* ``bzrlib.builtins.Commit.run`` raises ``bzrlib.errors.BoundBranchOutOfDate``
134 rather than ``bzrlib.errors.BzrCommandError`` when the bound branch is out
135 of date. (Gary van der Merwe)
136
133* ``bzrlib.commands.run_bzr`` is more extensible: callers can supply the137* ``bzrlib.commands.run_bzr`` is more extensible: callers can supply the
134 functions to load or disable plugins if they wish to use a different138 functions to load or disable plugins if they wish to use a different
135 plugin mechanism; the --help, --version and no-command name code paths139 plugin mechanism; the --help, --version and no-command name code paths
136 now use the generic pluggable command lookup infrastructure.140 now use the generic pluggable command lookup infrastructure.
137 (Robert Collins)141 (Robert Collins)
138142
143* ``bzrlib.errors.BoundBranchOutOfDate`` has a new field ``extra_help``
144 which can be set to add extra help to the error. (Gary van der Merwe)
145
139* The methods ``BzrDir.create_branch()``, ``BzrDir.destroy_branch()`` and 146* The methods ``BzrDir.create_branch()``, ``BzrDir.destroy_branch()`` and
140 ``BzrDir.open_branch()`` now take an optional ``name`` argument. 147 ``BzrDir.open_branch()`` now take an optional ``name`` argument.
141 (Jelmer Vernooij)148 (Jelmer Vernooij)
142149
=== modified file 'bzrlib/builtins.py'
--- bzrlib/builtins.py 2010-03-02 15:56:28 +0000
+++ bzrlib/builtins.py 2010-03-03 08:27:18 +0000
@@ -3174,10 +3174,11 @@
3174 raise errors.BzrCommandError("Commit refused because there are"3174 raise errors.BzrCommandError("Commit refused because there are"
3175 " unknown files in the working tree.")3175 " unknown files in the working tree.")
3176 except errors.BoundBranchOutOfDate, e:3176 except errors.BoundBranchOutOfDate, e:
3177 raise errors.BzrCommandError(str(e) + "\n"3177 e.extra_help = ("\n"
3178 'To commit to master branch, run update and then commit.\n'3178 'To commit to master branch, run update and then commit.\n'
3179 'You can also pass --local to commit to continue working '3179 'You can also pass --local to commit to continue working '
3180 'disconnected.')3180 'disconnected.')
3181 raise
31813182
31823183
3183class cmd_check(Command):3184class cmd_check(Command):
31843185
=== modified file 'bzrlib/errors.py'
--- bzrlib/errors.py 2010-03-02 19:50:18 +0000
+++ bzrlib/errors.py 2010-03-03 08:27:18 +0000
@@ -1297,12 +1297,13 @@
1297class BoundBranchOutOfDate(BzrError):1297class BoundBranchOutOfDate(BzrError):
12981298
1299 _fmt = ("Bound branch %(branch)s is out of date with master branch"1299 _fmt = ("Bound branch %(branch)s is out of date with master branch"
1300 " %(master)s.")1300 " %(master)s.%(extra_help)s")
13011301
1302 def __init__(self, branch, master):1302 def __init__(self, branch, master):
1303 BzrError.__init__(self)1303 BzrError.__init__(self)
1304 self.branch = branch1304 self.branch = branch
1305 self.master = master1305 self.master = master
1306 self.extra_help = ''
13061307
13071308
1308class CommitToDoubleBoundBranch(BzrError):1309class CommitToDoubleBoundBranch(BzrError):
13091310
=== modified file 'bzrlib/tests/commands/test_commit.py'
--- bzrlib/tests/commands/test_commit.py 2010-02-17 17:11:16 +0000
+++ bzrlib/tests/commands/test_commit.py 2010-03-03 08:27:18 +0000
@@ -53,8 +53,7 @@
53 # commit do not provide a directory parameter, we have to change dir53 # commit do not provide a directory parameter, we have to change dir
54 # manually54 # manually
55 os.chdir('local')55 os.chdir('local')
56 # cmd_commit translates BoundBranchOutOfDate into BzrCommandError56 self.assertRaises(errors.BoundBranchOutOfDate, commit.run,
57 self.assertRaises(errors.BzrCommandError, commit.run,
58 message=u'empty commit', unchanged=True)57 message=u'empty commit', unchanged=True)
59 self.assertEquals(1, len(self.connections))58 self.assertEquals(1, len(self.connections))
6059