Merge lp:~vila/bzr/284038-push-strict into lp:~bzr/bzr/trunk-old

Proposed by Vincent Ladeuil
Status: Merged
Merged at revision: not available
Proposed branch: lp:~vila/bzr/284038-push-strict
Merge into: lp:~bzr/bzr/trunk-old
Diff against target: 235 lines
To merge this branch: bzr merge lp:~vila/bzr/284038-push-strict
Reviewer Review Type Date Requested Status
John A Meinel Needs Fixing
Review via email: mp+8005@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Vincent Ladeuil (vila) wrote :

This complements my first attempt to fix the bug while also fixing bugs #322808 and #65286,
by making --strict defaults to true.

Changing the default value revealed a bug in the previous implementation as push can be used without
a working tree.

Also the --strict option is meaningless if the --revision option is used.

Previous reviews mentioned introducing:
- a way to query config files for a bool option,
- a new method on working tree for checking changes.

Since both are also needed for bug #206577, I'd like to postpone these modifications until both fixes
have landed.

Revision history for this message
John A Meinel (jameinel) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Vincent Ladeuil wrote:
> Vincent Ladeuil has proposed merging lp:~vila/bzr/284038-push-strict into lp:bzr.
>
> Requested reviews:
> bzr-core (bzr-core)
>
> This complements my first attempt to fix the bug while also fixing bugs #322808 and #65286,
> by making --strict defaults to true.
>
> Changing the default value revealed a bug in the previous implementation as push can be used without
> a working tree.
>
> Also the --strict option is meaningless if the --revision option is used.
>
> Previous reviews mentioned introducing:
> - a way to query config files for a bool option,
> - a new method on working tree for checking changes.
>
> Since both are also needed for bug #206577, I'd like to postpone these modifications until both fixes
> have landed.
>

To start with, I don't remember an agreement that strict should be the
default.

+ The ``push_strict`` option can be declared in a configuration
+ file. option is used.

^- The news entry needs a bit of updating. Something like:

The configuration option ``push_strict`` can be used to set the default
for this behavior.

...

+ if (tree is not None and revision_id is None
+ and (strict is None or strict)): # Default to True:
+ changes = tree.changes_from(tree.basis_tree())
+ if changes.has_changed() or len(tree.get_parent_ids()) > 1:
+ raise errors.UncommittedChanges(tree)

Rather than doing 'strict is None', just set:

def run(..., strict=True):

if we want that to be the default.

So provided that there was actually agreement that strict should be the
default, the patch seems ok with some small tweaks.

I'll note that "commit" is not strict by default, and I've often used
push before commit, especially if I'm about to switch.

I could agree that strict=True is the 'safer' default for most people,
so having to edit a config to turn it off is the "power-user" approach.

I suppose we could land it and see what we think...

 vote needs_fixing

Mostly I want to make sure that we did actually agree that we should
default to strict.

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkpIwN8ACgkQJdeBCYSNAAOuRQCdEXhhM7Z9KVXOjQZYAMKJPpYV
S9EAoJ90HFDdgbzP7/JRf4JM4YxO4B0N
=uiFO
-----END PGP SIGNATURE-----

review: Needs Fixing
Revision history for this message
Vincent Ladeuil (vila) wrote :

>>>>> "jam" == John A Meinel <email address hidden> writes:

<snip/>

    jam> To start with, I don't remember an agreement that strict
    jam> should be the default.

https://bugs.edge.launchpad.net/bzr/+bug/322808/comments/2
https://bugs.edge.launchpad.net/bzr/+bug/65286/comments/1
https://bugs.edge.launchpad.net/bzr/+bug/65286/comments/2

I interpreted that as an agreement, I also agree with the idea
that it may be confusing for new users if left off by default.

    jam> + The ``push_strict`` option can be declared in a configuration
    jam> + file. option is used.

    jam> ^- The news entry needs a bit of updating. Something like:

    jam> The configuration option ``push_strict`` can be used to set the default
    jam> for this behavior.

Right.

    jam> ...

    jam> + if (tree is not None and revision_id is None
    jam> + and (strict is None or strict)): # Default to True:
    jam> + changes = tree.changes_from(tree.basis_tree())
    jam> + if changes.has_changed() or len(tree.get_parent_ids()) > 1:
    jam> + raise errors.UncommittedChanges(tree)

    jam> Rather than doing 'strict is None', just set:

    jam> def run(..., strict=True):

    jam> if we want that to be the default.

No, because if we do that, we can't distinguish anymore between
the config file variable and the command-line option (the later
should still override the former).

    jam> So provided that there was actually agreement that strict should be the
    jam> default, the patch seems ok with some small tweaks.

    jam> I'll note that "commit" is not strict by default, and
    jam> I've often used push before commit, especially if I'm
    jam> about to switch.

Feel free to add 'push_strict=False' in your bazaar.conf file,
you're not a *new* user :-)

    jam> I could agree that strict=True is the 'safer' default
    jam> for most people, so having to edit a config to turn it
    jam> off is the "power-user" approach.

Indeed.

Since my other merge proposal (for send/bundle --strict) will
raise, at least, the exact same questions, I'll wait for your
answer here before landing.

        Vincent

Revision history for this message
Vincent Ladeuil (vila) wrote :

>>>>> "jam" == John A Meinel <email address hidden> writes:

<snip/>

    jam> To start with, I don't remember an agreement that strict
    jam> should be the default.

https://bugs.edge.launchpad.net/bzr/+bug/322808/comments/2
https://bugs.edge.launchpad.net/bzr/+bug/65286/comments/1
https://bugs.edge.launchpad.net/bzr/+bug/65286/comments/2

I interpreted that as an agreement, I also agree with the idea
that it may be confusing for new users if left off by default.

    jam> + The ``push_strict`` option can be declared in a configuration
    jam> + file. option is used.

    jam> ^- The news entry needs a bit of updating. Something like:

    jam> The configuration option ``push_strict`` can be used to set the default
    jam> for this behavior.

Right.

    jam> ...

    jam> + if (tree is not None and revision_id is None
    jam> + and (strict is None or strict)): # Default to True:
    jam> + changes = tree.changes_from(tree.basis_tree())
    jam> + if changes.has_changed() or len(tree.get_parent_ids()) > 1:
    jam> + raise errors.UncommittedChanges(tree)

    jam> Rather than doing 'strict is None', just set:

    jam> def run(..., strict=True):

    jam> if we want that to be the default.

No, because if we do that, we can't distinguish anymore between
the config file variable and the command-line option (the later
should still override the former).

    jam> So provided that there was actually agreement that strict should be the
    jam> default, the patch seems ok with some small tweaks.

    jam> I'll note that "commit" is not strict by default, and
    jam> I've often used push before commit, especially if I'm
    jam> about to switch.

Feel free to add 'push_strict=False' in your bazaar.conf file,
you're not a *new* user :-)

    jam> I could agree that strict=True is the 'safer' default
    jam> for most people, so having to edit a config to turn it
    jam> off is the "power-user" approach.

Indeed.

Since my other merge proposal (for send/bundle --strict) will
raise, at least, the exact same questions, I'll wait for your
answer here before landing.

        Vincent

Revision history for this message
John A Meinel (jameinel) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Vincent Ladeuil wrote:
> Vincent Ladeuil has proposed merging lp:~vila/bzr/284038-push-strict into lp:bzr.
>
> Requested reviews:
> bzr-core (bzr-core)
>
> This complements my first attempt to fix the bug while also fixing bugs #322808 and #65286,
> by making --strict defaults to true.
>
> Changing the default value revealed a bug in the previous implementation as push can be used without
> a working tree.
>
> Also the --strict option is meaningless if the --revision option is used.
>
> Previous reviews mentioned introducing:
> - a way to query config files for a bool option,
> - a new method on working tree for checking changes.
>
> Since both are also needed for bug #206577, I'd like to postpone these modifications until both fixes
> have landed.
>

Also...

We should *definitely* be checking:

 tree.last_revision() == tree.branch.last_revision()

And possibly consider what to do in the case of bound branches and
heavyweight checkouts.
I'm not *as* concerned about the latter, but because in the former case,
IIRC we will actually be pushing "tree.branch.last_revision()" *not*
tree.last_revision()...

So certainly '--strict' should fail if the tree and branch aren't at the
same rev.

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkpIxUIACgkQJdeBCYSNAAPc/wCfVTwT8aIl1QBDg4ho7rv/C1zI
3e4AniMO3HZD1SgHyMKOAG0uXZY0qs2g
=Qf45
-----END PGP SIGNATURE-----

Revision history for this message
Vincent Ladeuil (vila) wrote :

>>>>> "jam" == John A Meinel <email address hidden> writes:

<snip/>

    jam> Also...

    jam> We should *definitely* be checking:

    jam> tree.last_revision() == tree.branch.last_revision()

    jam> And possibly consider what to do in the case of bound
    jam> branches and heavyweight checkouts. I'm not *as*
    jam> concerned about the latter, but because in the former
    jam> case, IIRC we will actually be pushing
    jam> "tree.branch.last_revision()" *not*
    jam> tree.last_revision()...

Hmm, so far --strict is defined as triggering if there are
*uncommitted* changes, you're stretching the definition here...

    jam> So certainly '--strict' should fail if the tree and
    jam> branch aren't at the same rev.

I'm not sure I agree with you (nor that I disagree), but I think
that's worth filing a different bug.

       Vincent

Revision history for this message
John A Meinel (jameinel) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Vincent Ladeuil wrote:
>>>>>> "jam" == John A Meinel <email address hidden> writes:
>
> <snip/>
>
> jam> Also...
>
> jam> We should *definitely* be checking:
>
> jam> tree.last_revision() == tree.branch.last_revision()
>
> jam> And possibly consider what to do in the case of bound
> jam> branches and heavyweight checkouts. I'm not *as*
> jam> concerned about the latter, but because in the former
> jam> case, IIRC we will actually be pushing
> jam> "tree.branch.last_revision()" *not*
> jam> tree.last_revision()...
>
> Hmm, so far --strict is defined as triggering if there are
> *uncommitted* changes, you're stretching the definition here...

So I can agree that it is a different bug except:

1) I think 'bzr push --strict' is about 'push should push the state I
*think* I have'. And uncommitted changes, (uncommitted merges), and a
tree last revision being out of sync with the branch's revision, are all
cases where the push isn't pushing what the user expected.

2) I think the source of '--strict' is MySQL fallout from switching from
BK where a merge had autocommit so "bk merge; bk push" did something,
while with bzr you need "bzr merge; bzr commit; bzr push".

The fact that they haven't run into issues with a workingtree being out
of sync with the branch is more luck than noticing that we have a
serious flaw.

3) The fix is fairly trivial, the bug is somewhat serious, and you're
already working on the code. Yes it is feature creep, but it is a small
amount for something worthwhile (IMO).

>
> jam> So certainly '--strict' should fail if the tree and
> jam> branch aren't at the same rev.
>
> I'm not sure I agree with you (nor that I disagree), but I think
> that's worth filing a different bug.
>
> Vincent
>

I read your links, and while there wasn't a general discussion on it,
Martin at least seems to agree it should be the default. I'm just a bit
extra sensitive to commandline behavioral changes. Since suddenly
something that used to work won't anymore.

Also, note that "UncommittedChanges" has no help text to tell the user
that they can use "--no-strict" in order to push anyway. I don't know if
that matters or not. But since we are explictly changing a behavior, it
is good to help users find out how to get their old behavior back.

Anyway, you can probably merge this as is, though I'd like it if you
added a tree.last_revision() check.

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkpI7LsACgkQJdeBCYSNAANHawCgzbfvzWlHnaFF07twKpOsj9Dd
dioAoLoZtL3GnDb1V05wi0kQyjDaeE0y
=a+Cd
-----END PGP SIGNATURE-----

Revision history for this message
Vincent Ladeuil (vila) wrote :
Download full text (3.9 KiB)

>>>>> "jam" == John A Meinel writes:

    jam> Vincent Ladeuil wrote:
    >>>>>>> "jam" == John A Meinel writes:
    >>
    >> <snip/>
    >>
    jam> Also...
    jam> We should *definitely* be checking:
    jam> tree.last_revision() == tree.branch.last_revision()

    jam> And possibly consider what to do in the case of bound
    jam> branches and heavyweight checkouts. I'm not *as*
    jam> concerned about the latter, but because in the former
    jam> case, IIRC we will actually be pushing
    jam> "tree.branch.last_revision()" *not*
    jam> tree.last_revision()...
    >>
    >> Hmm, so far --strict is defined as triggering if there are
    >> *uncommitted* changes, you're stretching the definition here...

    jam> So I can agree that it is a different bug except:

    jam> 1) I think 'bzr push --strict' is about 'push should
    jam> push the state I *think* I have'.

I understood that :)

    jam> And uncommitted changes, (uncommitted merges), and a
    jam> tree last revision being out of sync with the branch's
    jam> revision, are all cases where the push isn't pushing
    jam> what the user expected.

Right. You're right. I agree with the rationale, but... I don't
clearly understand when a user can find itself in this
situation... I can see one case for a bound branch, except that I
can't commit in that situation so I have nothing to push... Or
maybe you mean a commit --local ? But in that case push should
already fail with "diverged branches" (strict or no strict) no ?

    jam> 2) I think the source of '--strict' is MySQL fallout
    jam> from switching from BK where a merge had autocommit so
    jam> "bk merge; bk push" did something, while with bzr you
    jam> need "bzr merge; bzr commit; bzr push".

<snip/>

I agree here too, mysql workflow wasn't my main reason for
agreeing about making --strict the default. In fact my first fix
addressed mysql workflow *without* making it he default.

I think the default should be strict because uneducated users
will easily forget to commit before pushing, and even experienced
ones may prefer, for some branches, to work in strict mode.

    jam> 3) The fix is fairly trivial, the bug is somewhat
    jam> serious, and you're already working on the code. Yes it
    jam> is feature creep, but it is a small amount for something
    jam> worthwhile (IMO).

I don't have a problem with working more on that, but I just
don't know how to write the tests (the what, not the how).

    jam> I read your links, and while there wasn't a general
    jam> discussion on it, Martin at least seems to agree it
    jam> should be the default.

Sorry to have jumped to that conclusion without discussing it
first then.

    jam> I'm just a bit extra sensitive to commandline behavioral
    jam> changes. Since suddenly something that used to work
    jam> won't anymore.

Well, I thought about that and I came to the conclusion that it's
pretty rare than one find itself in the situation to push while
having uncommitted changes. At least to me, it sounds like
advanced usage and I don't mind having to add an option in that
case, even if I didn't have to do it before, especially since I
can configure that behavior at ...

Read more...

Revision history for this message
John A Meinel (jameinel) wrote :
Download full text (4.8 KiB)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Vincent Ladeuil wrote:
>>>>>> "jam" == John A Meinel writes:
>
> jam> Vincent Ladeuil wrote:
> >>>>>>> "jam" == John A Meinel writes:
> >>
> >> <snip/>
> >>
> jam> Also...
> jam> We should *definitely* be checking:
> jam> tree.last_revision() == tree.branch.last_revision()
>
> jam> And possibly consider what to do in the case of bound
> jam> branches and heavyweight checkouts. I'm not *as*
> jam> concerned about the latter, but because in the former
> jam> case, IIRC we will actually be pushing
> jam> "tree.branch.last_revision()" *not*
> jam> tree.last_revision()...
> >>
> >> Hmm, so far --strict is defined as triggering if there are
> >> *uncommitted* changes, you're stretching the definition here...
>
> jam> So I can agree that it is a different bug except:
>
> jam> 1) I think 'bzr push --strict' is about 'push should
> jam> push the state I *think* I have'.
>
> I understood that :)
>
> jam> And uncommitted changes, (uncommitted merges), and a
> jam> tree last revision being out of sync with the branch's
> jam> revision, are all cases where the push isn't pushing
> jam> what the user expected.
>
> Right. You're right. I agree with the rationale, but... I don't
> clearly understand when a user can find itself in this
> situation... I can see one case for a bound branch, except that I
> can't commit in that situation so I have nothing to push... Or
> maybe you mean a commit --local ? But in that case push should
> already fail with "diverged branches" (strict or no strict) no ?
>
> jam> 2) I think the source of '--strict' is MySQL fallout
> jam> from switching from BK where a merge had autocommit so
> jam> "bk merge; bk push" did something, while with bzr you
> jam> need "bzr merge; bzr commit; bzr push".
>
> <snip/>
>
> I agree here too, mysql workflow wasn't my main reason for
> agreeing about making --strict the default. In fact my first fix
> addressed mysql workflow *without* making it he default.
>
> I think the default should be strict because uneducated users
> will easily forget to commit before pushing, and even experienced
> ones may prefer, for some branches, to work in strict mode.
>
> jam> 3) The fix is fairly trivial, the bug is somewhat
> jam> serious, and you're already working on the code. Yes it
> jam> is feature creep, but it is a small amount for something
> jam> worthwhile (IMO).
>
> I don't have a problem with working more on that, but I just
> don't know how to write the tests (the what, not the how).
>
> jam> I read your links, and while there wasn't a general
> jam> discussion on it, Martin at least seems to agree it
> jam> should be the default.
>
> Sorry to have jumped to that conclusion without discussing it
> first then.
>
> jam> I'm just a bit extra sensitive to commandline behavioral
> jam> changes. Since suddenly something that used to work
> jam> won't anymore.
>
> Well, I thought about that and I came to the conclusion that it's
> pretty rare than one find itself in the situation to push whi...

Read more...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'NEWS'
--- NEWS 2009-06-30 05:34:47 +0000
+++ NEWS 2009-06-30 08:35:22 +0000
@@ -21,9 +21,10 @@
21New Features21New Features
22************22************
2323
24* ``bzr push`` now checks if uncommitted changes are present in the working24* ``bzr push`` now aborts if uncommitted changes (including pending merges)
25 tree if the ``--strict`` option is used.25 are present in the working tree (if one is present) and no revision is
26 (Vincent Ladeuil, #284038)26 speficied. The ``push_strict`` option can be declared in a configuration
27 file. option is used. (Vincent Ladeuil, #284038, #322808, #65286)
2728
2829
29Bug Fixes30Bug Fixes
3031
=== modified file 'bzrlib/builtins.py'
--- bzrlib/builtins.py 2009-06-26 03:44:30 +0000
+++ bzrlib/builtins.py 2009-06-30 08:35:22 +0000
@@ -1057,16 +1057,17 @@
1057 strict = bools[strict.lower()]1057 strict = bools[strict.lower()]
1058 except KeyError:1058 except KeyError:
1059 strict = None1059 strict = None
1060 if strict:
1061 changes = tree.changes_from(tree.basis_tree())
1062 if changes.has_changed():
1063 raise errors.UncommittedChanges(tree)
1064 # Get the tip's revision_id1060 # Get the tip's revision_id
1065 revision = _get_one_revision('push', revision)1061 revision = _get_one_revision('push', revision)
1066 if revision is not None:1062 if revision is not None:
1067 revision_id = revision.in_history(br_from).rev_id1063 revision_id = revision.in_history(br_from).rev_id
1068 else:1064 else:
1069 revision_id = None1065 revision_id = None
1066 if (tree is not None and revision_id is None
1067 and (strict is None or strict)): # Default to True:
1068 changes = tree.changes_from(tree.basis_tree())
1069 if changes.has_changed() or len(tree.get_parent_ids()) > 1:
1070 raise errors.UncommittedChanges(tree)
10701071
1071 # Get the stacked_on branch, if any1072 # Get the stacked_on branch, if any
1072 if stacked_on is not None:1073 if stacked_on is not None:
10731074
=== modified file 'bzrlib/tests/blackbox/test_push.py'
--- bzrlib/tests/blackbox/test_push.py 2009-06-22 08:14:24 +0000
+++ bzrlib/tests/blackbox/test_push.py 2009-06-30 08:35:22 +0000
@@ -35,6 +35,28 @@
35from bzrlib.transport import memory35from bzrlib.transport import memory
3636
3737
38def load_tests(standard_tests, module, loader):
39 """Multiply tests for the push command."""
40 result = loader.suiteClass()
41
42 # one for each king of change
43 changes_tests, remaining_tests = tests.split_suite_by_condition(
44 standard_tests, tests.condition_isinstance((
45 TestPushStrictWithChanges,
46 )))
47 changes_scenarios = [
48 ('uncommitted',
49 dict(_changes_type= '_uncommitted_changes')),
50 ('pending_merges',
51 dict(_changes_type= '_pending_merges')),
52 ]
53 tests.multiply_tests(changes_tests, changes_scenarios, result)
54 # No parametrization for the remaining tests
55 result.addTests(remaining_tests)
56
57 return result
58
59
38class TestPush(tests.TestCaseWithTransport):60class TestPush(tests.TestCaseWithTransport):
3961
40 def test_push_error_on_vfs_http(self):62 def test_push_error_on_vfs_http(self):
@@ -569,72 +591,112 @@
569class TestPushStrict(tests.TestCaseWithTransport):591class TestPushStrict(tests.TestCaseWithTransport):
570592
571 def make_local_branch_and_tree(self):593 def make_local_branch_and_tree(self):
572 tree = self.make_branch_and_tree('local')594 self.tree = self.make_branch_and_tree('local')
573 self.build_tree_contents([('local/file', 'initial')])595 self.build_tree_contents([('local/file', 'initial')])
574 tree.add('file')596 self.tree.add('file')
575 tree.commit('adding file', rev_id='from-1')597 self.tree.commit('adding file', rev_id='added')
576 return tree
577
578 def make_local_branch_and_tree_with_changes(self):
579 tree = self.make_local_branch_and_tree()
580 # Make some changes
581 self.build_tree_contents([('local/file', 'modified')])598 self.build_tree_contents([('local/file', 'modified')])
582 return tree599 self.tree.commit('modify file', rev_id='modified')
583600
584 def set_config_push_strict(self, tree, value):601 def set_config_push_strict(self, value):
585 # set config var (any of bazaar.conf, locations.conf, branch.conf602 # set config var (any of bazaar.conf, locations.conf, branch.conf
586 # should do)603 # should do)
587 conf = tree.branch.get_config()604 conf = self.tree.branch.get_config()
588 conf.set_user_option('push_strict', value)605 conf.set_user_option('push_strict', value)
589606
590 def assertPushFails(self, location, *args):607 def assertPushFails(self, args):
591 self.run_bzr_error(['Working tree ".*/local/"'608 self.run_bzr_error(['Working tree ".*/local/"'
592 ' has uncommitted changes.$',],609 ' has uncommitted changes.$',],
593 ['push', '../' + location] + list(args),610 ['push', '../to'] + args,
594 working_dir='local', retcode=3)611 working_dir='local', retcode=3)
595612
596 def assertPushSucceeds(self, location, *args):613 def assertPushSucceeds(self, args, pushed_revid=None):
597 self.run_bzr(['push', '../' + location] + list(args),614 self.run_bzr(['push', '../to'] + args,
598 working_dir='local')615 working_dir='local')
599 tree_to = workingtree.WorkingTree.open(location)616 if pushed_revid is None:
617 pushed_revid = 'modified'
618 tree_to = workingtree.WorkingTree.open('to')
600 repo_to = tree_to.branch.repository619 repo_to = tree_to.branch.repository
601 self.assertTrue(repo_to.has_revision('from-1'))620 self.assertTrue(repo_to.has_revision(pushed_revid))
602 self.assertEqual(tree_to.branch.last_revision_info()[1], 'from-1')621 self.assertEqual(tree_to.branch.last_revision_info()[1], pushed_revid)
603622
604 def test_push_default(self):623
605 tree = self.make_local_branch_and_tree_with_changes()624
606 self.assertPushSucceeds('to')625class TestPushStrictWithoutChanges(TestPushStrict):
607626
608 def test_push_no_strict_with_changes(self):627 def setUp(self):
609 tree = self.make_local_branch_and_tree_with_changes()628 super(TestPushStrictWithoutChanges, self).setUp()
610 self.assertPushSucceeds('to', '--no-strict')629 self.make_local_branch_and_tree()
630
631 def test_push_default(self):
632 self.assertPushSucceeds([])
633
634 def test_push_strict(self):
635 self.assertPushSucceeds(['--strict'])
636
637 def test_push_no_strict(self):
638 self.assertPushSucceeds(['--no-strict'])
639
640 def test_push_config_var_strict(self):
641 self.set_config_push_strict('true')
642 self.assertPushSucceeds([])
643
644 def test_push_config_var_no_strict(self):
645 self.set_config_push_strict('false')
646 self.assertPushSucceeds([])
647
648
649class TestPushStrictWithChanges(TestPushStrict):
650
651 _changes_type = None # Set by load_tests
652
653 def setUp(self):
654 super(TestPushStrictWithChanges, self).setUp()
655 getattr(self, self._changes_type)()
656
657 def _uncommitted_changes(self):
658 self.make_local_branch_and_tree()
659 # Make a change without committing it
660 self.build_tree_contents([('local/file', 'in progress')])
661
662 def _pending_merges(self):
663 self.make_local_branch_and_tree()
664 # Create 'other' branch containing a new file
665 other_bzrdir = self.tree.bzrdir.sprout('other')
666 other_tree = other_bzrdir.open_workingtree()
667 self.build_tree_contents([('other/other-file', 'other')])
668 other_tree.add('other-file')
669 other_tree.commit('other commit', rev_id='other')
670 # Merge and revert, leaving a pending merge
671 self.tree.merge_from_branch(other_tree.branch)
672 self.tree.revert(filenames=['other-file'], backups=False)
673
674 def test_push_default(self):
675 self.assertPushFails([])
676
677 def test_push_with_revision(self):
678 self.assertPushSucceeds(['-r', 'revid:added'], pushed_revid='added')
679
680 def test_push_no_strict(self):
681 self.assertPushSucceeds(['--no-strict'])
611682
612 def test_push_strict_with_changes(self):683 def test_push_strict_with_changes(self):
613 tree = self.make_local_branch_and_tree_with_changes()684 self.assertPushFails(['--strict'])
614 self.assertPushFails('to', '--strict')
615
616 def test_push_strict_without_changes(self):
617 tree = self.make_local_branch_and_tree()
618 self.assertPushSucceeds('to', '--strict')
619685
620 def test_push_respect_config_var_strict(self):686 def test_push_respect_config_var_strict(self):
621 tree = self.make_local_branch_and_tree_with_changes()687 self.set_config_push_strict('true')
622 self.set_config_push_strict(tree, 'true')688 self.assertPushFails([])
623 self.assertPushFails('to')
624689
625 def test_push_bogus_config_var_ignored(self):690 def test_push_bogus_config_var_ignored(self):
626 tree = self.make_local_branch_and_tree_with_changes()691 self.set_config_push_strict("I don't want you to be strict")
627 self.set_config_push_strict(tree, "I don't want you to be strict")692 self.assertPushFails([])
628 self.assertPushSucceeds('to')
629693
630 def test_push_no_strict_command_line_override_config(self):694 def test_push_no_strict_command_line_override_config(self):
631 tree = self.make_local_branch_and_tree_with_changes()695 self.set_config_push_strict('yES')
632 self.set_config_push_strict(tree, 'yES')696 self.assertPushFails([])
633 self.assertPushFails('to')697 self.assertPushSucceeds(['--no-strict'])
634 self.assertPushSucceeds('to', '--no-strict')
635698
636 def test_push_strict_command_line_override_config(self):699 def test_push_strict_command_line_override_config(self):
637 tree = self.make_local_branch_and_tree_with_changes()700 self.set_config_push_strict('oFF')
638 self.set_config_push_strict(tree, 'oFF')701 self.assertPushFails(['--strict'])
639 self.assertPushFails('to', '--strict')702 self.assertPushSucceeds([])
640 self.assertPushSucceeds('to')