Rev 42: Fix bug #141026, check that the WT is clean before submitting. in http://bazaar.launchpad.net/%7Ebzr/bzr-pqm/devel
John Arbash Meinel
john at arbash-meinel.com
Tue Nov 6 03:41:36 GMT 2007
At http://bazaar.launchpad.net/%7Ebzr/bzr-pqm/devel
------------------------------------------------------------
revno: 42
revision-id:john at arbash-meinel.com-20071106034111-svkxsg2vbn31c93j
parent: john at arbash-meinel.com-20071106030349-d622nrjox9cf4t1z
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: pqm
timestamp: Mon 2007-11-05 21:41:11 -0600
message:
Fix bug #141026, check that the WT is clean before submitting.
modified:
__init__.py __init__.py-20060221052551-30932fa7d369a24b
pqm_submit.py pqm_submit.py-20060221060137-b3a3cdde9f50efab
test_pqm_submit.py test_pqm_submit.py-20060221060137-fb48d47216aa0077
-------------- next part --------------
=== modified file '__init__.py'
--- a/__init__.py 2007-11-06 02:55:32 +0000
+++ b/__init__.py 2007-11-06 03:41:11 +0000
@@ -87,16 +87,17 @@
if location is None:
location = '.'
- # If we are simply specifying '.' then
- # we want to open the local branch.
- # all other uses require an exact path
- if location == '.':
- bzrdir = BzrDir.open_containing('.')[0]
- else:
- bzrdir = BzrDir.open(location)
-
- b = bzrdir.open_branch()
- submit(b, message=message, dry_run=dry_run, public_location=public_location)
+ tree, b, relpath = BzrDir.open_containing_tree_or_branch(location)
+ if relpath and not tree:
+ from bzrlib import errors
+ raise errors.BzrCommandError('No working tree was found, but we'
+ ' were not given the exact path to'
+ ' the branch.\n'
+ ' We found the branch at: %s'
+ % (b.base,))
+ submit(b, message=message, dry_run=dry_run,
+ public_location=public_location,
+ tree=tree)
register_command(cmd_pqm_submit)
=== modified file 'pqm_submit.py'
--- a/pqm_submit.py 2007-11-06 02:48:35 +0000
+++ b/pqm_submit.py 2007-11-06 03:41:11 +0000
@@ -41,13 +41,16 @@
"""A request to perform a PQM merge into a branch."""
def __init__(self, source_branch, public_location=None,
- submit_location=None, message=None):
+ submit_location=None, message=None,
+ tree=None):
"""Create a PQMSubmission object.
:param source_branch: the source branch for the merge
:param public_location: the public location of the source branch
:param submit_location: the location of the target branch
:param message: The message to use when committing this merge
+ :param tree: A WorkingTree or None. If not None the WT will be checked
+ for uncommitted changes.
If any of public_location, submit_location or message are
omitted, they will be calculated from source_branch.
@@ -55,6 +58,7 @@
if source_branch is None:
raise errors.NoMergeSource()
self.source_branch = source_branch
+ self.tree = tree
if public_location is None:
public_location = self.source_branch.get_public_branch()
@@ -102,6 +106,24 @@
if '\n' in self.message:
raise BadCommitMessage(self.message)
+ def check_tree(self):
+ """Check that the working tree has no uncommitted changes."""
+ if self.tree is None:
+ return
+ note('Checking the working tree is clean ...')
+ self.tree.lock_read()
+ try:
+ basis_tree = self.tree.basis_tree()
+ basis_tree.lock_read()
+ try:
+ for change in self.tree._iter_changes(basis_tree):
+ # If we have any changes, the tree is not clean
+ raise errors.UncommittedChanges(self.tree)
+ finally:
+ basis_tree.unlock()
+ finally:
+ self.tree.unlock()
+
def check_public_branch(self):
"""Check that the public branch is up to date with the local copy."""
note('Checking that the public branch is up to date ...')
@@ -139,12 +161,13 @@
return message
-def submit(branch, message, dry_run=False, public_location=None):
+def submit(branch, message, dry_run=False, public_location=None, tree=None):
"""Submit the given branch to the pqm."""
config = branch.get_config()
submission = PQMSubmission(
- source_branch=branch, public_location=public_location, message=message)
+ source_branch=branch, public_location=public_location, message=message,
+ tree=tree)
mail_from = config.get_user_option('pqm_user_email')
if not mail_from:
@@ -157,6 +180,7 @@
mail_to = mail_to.encode('utf8') # same here
submission.check_public_branch()
+ submission.check_tree()
message = submission.to_email(mail_from, mail_to)
=== modified file 'test_pqm_submit.py'
--- a/test_pqm_submit.py 2007-11-06 03:03:49 +0000
+++ b/test_pqm_submit.py 2007-11-06 03:41:11 +0000
@@ -54,6 +54,45 @@
submit_location='submit-branch',
message='foo\nbar')
+ def test_check_tree_clean(self):
+ tree = self.make_branch_and_memory_tree('source')
+ submission = pqm_submit.PQMSubmission(
+ source_branch=tree.branch,
+ public_location=tree.branch.base,
+ submit_location='submit-branch',
+ message='not much to say',
+ tree=tree,
+ )
+ submission.check_tree()
+
+ def test_check_tree_no_tree(self):
+ branch = self.make_branch('source')
+ submission = pqm_submit.PQMSubmission(
+ source_branch=branch,
+ public_location=branch.base,
+ submit_location='submit-branch',
+ message='not much to say',
+ tree=None,
+ )
+ submission.check_tree()
+
+ def test_check_tree_dirty(self):
+ tree = self.make_branch_and_memory_tree('source')
+ tree.lock_write()
+ try:
+ tree.add('')
+
+ submission = pqm_submit.PQMSubmission(
+ source_branch=tree.branch,
+ public_location=tree.branch.base,
+ submit_location='submit-branch',
+ message='not much to say',
+ tree=tree,
+ )
+ self.assertRaises(errors.UncommittedChanges, submission.check_tree)
+ finally:
+ tree.unlock()
+
def test_check_public_branch(self):
tree = self.make_branch_and_memory_tree('source')
source_branch = tree.branch
@@ -268,3 +307,33 @@
self.assertEqual(('jrandom at example.com', ['pqm at example.com']),
call[1:3])
self.assertContainsRe(call[3], EMAIL)
+
+ def test_dirty_pqm_submit(self):
+ source_tree = self.make_branch_and_tree('source')
+ self.build_tree(['source/foo'])
+ source_tree.add(['foo'])
+
+ public_branch = self.make_branch('public')
+ source_tree.branch.set_public_branch(public_branch.base)
+ source_tree.branch.set_submit_branch('http://example.com/submit')
+ config = source_tree.branch.get_config()
+ config.set_user_option('pqm_email', 'PQM <pqm at example.com>')
+ config.set_user_option(
+ 'email', 'J. Random Hacker <jrandom at example.com>')
+
+ out, err, connect_calls, sendmail_calls = \
+ self.run_bzr_fakemail(['pqm-submit', '-m', 'commit message',
+ './source'],
+ retcode=3)
+ self.assertContainsRe(err,
+ r'Working tree ".*/source/" has uncommitted changes\.')
+
+ def test_submit_subdir_of_branch(self):
+ source_branch = self.make_branch('source')
+ source_branch.set_submit_branch('http://example.com/submit')
+ config = source_branch.get_config()
+ out, err, connect_calls, sendmail_calls = \
+ self.run_bzr_fakemail(['pqm-submit', '-m', 'commit message',
+ './source/subdir'],
+ retcode=3)
+ self.assertContainsRe(err, 'bzr: ERROR: No working tree was found')
More information about the bazaar-commits
mailing list