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
1=== modified file 'NEWS'
2--- NEWS 2010-03-02 19:50:18 +0000
3+++ NEWS 2010-03-03 08:27:18 +0000
4@@ -130,12 +130,19 @@
5 * ``bzrlib.branchbuilder.BranchBuilder.build_snapshot`` now accepts a
6 ``message_callback`` in the same way that commit does. (Robert Collins)
7
8+* ``bzrlib.builtins.Commit.run`` raises ``bzrlib.errors.BoundBranchOutOfDate``
9+ rather than ``bzrlib.errors.BzrCommandError`` when the bound branch is out
10+ of date. (Gary van der Merwe)
11+
12 * ``bzrlib.commands.run_bzr`` is more extensible: callers can supply the
13 functions to load or disable plugins if they wish to use a different
14 plugin mechanism; the --help, --version and no-command name code paths
15 now use the generic pluggable command lookup infrastructure.
16 (Robert Collins)
17
18+* ``bzrlib.errors.BoundBranchOutOfDate`` has a new field ``extra_help``
19+ which can be set to add extra help to the error. (Gary van der Merwe)
20+
21 * The methods ``BzrDir.create_branch()``, ``BzrDir.destroy_branch()`` and
22 ``BzrDir.open_branch()`` now take an optional ``name`` argument.
23 (Jelmer Vernooij)
24
25=== modified file 'bzrlib/builtins.py'
26--- bzrlib/builtins.py 2010-03-02 15:56:28 +0000
27+++ bzrlib/builtins.py 2010-03-03 08:27:18 +0000
28@@ -3174,10 +3174,11 @@
29 raise errors.BzrCommandError("Commit refused because there are"
30 " unknown files in the working tree.")
31 except errors.BoundBranchOutOfDate, e:
32- raise errors.BzrCommandError(str(e) + "\n"
33- 'To commit to master branch, run update and then commit.\n'
34- 'You can also pass --local to commit to continue working '
35- 'disconnected.')
36+ e.extra_help = ("\n"
37+ 'To commit to master branch, run update and then commit.\n'
38+ 'You can also pass --local to commit to continue working '
39+ 'disconnected.')
40+ raise
41
42
43 class cmd_check(Command):
44
45=== modified file 'bzrlib/errors.py'
46--- bzrlib/errors.py 2010-03-02 19:50:18 +0000
47+++ bzrlib/errors.py 2010-03-03 08:27:18 +0000
48@@ -1297,12 +1297,13 @@
49 class BoundBranchOutOfDate(BzrError):
50
51 _fmt = ("Bound branch %(branch)s is out of date with master branch"
52- " %(master)s.")
53+ " %(master)s.%(extra_help)s")
54
55 def __init__(self, branch, master):
56 BzrError.__init__(self)
57 self.branch = branch
58 self.master = master
59+ self.extra_help = ''
60
61
62 class CommitToDoubleBoundBranch(BzrError):
63
64=== modified file 'bzrlib/tests/commands/test_commit.py'
65--- bzrlib/tests/commands/test_commit.py 2010-02-17 17:11:16 +0000
66+++ bzrlib/tests/commands/test_commit.py 2010-03-03 08:27:18 +0000
67@@ -53,8 +53,7 @@
68 # commit do not provide a directory parameter, we have to change dir
69 # manually
70 os.chdir('local')
71- # cmd_commit translates BoundBranchOutOfDate into BzrCommandError
72- self.assertRaises(errors.BzrCommandError, commit.run,
73+ self.assertRaises(errors.BoundBranchOutOfDate, commit.run,
74 message=u'empty commit', unchanged=True)
75 self.assertEquals(1, len(self.connections))
76