[Pkg-bazaar-commits] ./bzr/unstable r885: - commit command refuses unless something is changed or --unchanged is given

Martin Pool mbp at sourcefrog.net
Fri Apr 10 08:21:20 UTC 2009


------------------------------------------------------------
revno: 885
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Mon 2005-07-11 13:40:02 +1000
message:
  - commit command refuses unless something is changed or --unchanged is given
modified:
  NEWS
  bzrlib/commands.py
  bzrlib/commit.py
  bzrlib/errors.py
  bzrlib/selftest/blackbox.py
  bzrlib/selftest/whitebox.py
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS	2005-07-07 02:07:03 +0000
+++ b/NEWS	2005-07-11 03:40:02 +0000
@@ -27,6 +27,9 @@
       John A Meinel.  Old format is available with the ``--long`` or
       ``-l`` option, patched by William Dod?.
 
+    * By default the commit command refuses to record a revision with
+      no changes unless the ``--unchanged`` option is given.
+
 
 bzr-0.0.5  2005-06-15
   

=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py	2005-07-08 06:54:58 +0000
+++ b/bzrlib/commands.py	2005-07-11 03:40:02 +0000
@@ -1095,11 +1095,12 @@
     TODO: Strict commit that fails if there are unknown or deleted files.
     """
     takes_args = ['selected*']
-    takes_options = ['message', 'file', 'verbose']
+    takes_options = ['message', 'file', 'verbose', 'unchanged']
     aliases = ['ci', 'checkin']
 
-    def run(self, message=None, file=None, verbose=True, selected_list=None):
-        from bzrlib.commit import commit
+    def run(self, message=None, file=None, verbose=True, selected_list=None,
+            unchanged=False):
+        from bzrlib.errors import PointlessCommit
         from bzrlib.osutils import get_text_message
 
         ## Warning: shadows builtin file()
@@ -1124,7 +1125,14 @@
             message = codecs.open(file, 'rt', bzrlib.user_encoding).read()
 
         b = find_branch('.')
-        commit(b, message, verbose=verbose, specific_files=selected_list)
+
+        try:
+            b.commit(message, verbose=verbose,
+                     specific_files=selected_list,
+                     allow_pointless=unchanged)
+        except PointlessCommit:
+            raise BzrCommandError("no changes to commit",
+                                  ["use --unchanged to commit anyhow"])
 
 
 class cmd_check(Command):
@@ -1344,6 +1352,7 @@
     'verbose':                None,
     'version':                None,
     'email':                  None,
+    'unchanged':              None,
     'update':                 None,
     'long':                   None,
     'root':                   str,

=== modified file 'bzrlib/commit.py'
--- a/bzrlib/commit.py	2005-07-11 03:27:43 +0000
+++ b/bzrlib/commit.py	2005-07-11 03:40:02 +0000
@@ -25,7 +25,7 @@
            verbose=True,
            specific_files=None,
            rev_id=None,
-           allow_empty=True):
+           allow_pointless=True):
     """Commit working copy as a new revision.
 
     The basic approach is to add all the file texts into the
@@ -42,8 +42,8 @@
     be robust against files disappearing, moving, etc.  So the
     whole thing is a bit hard.
 
-    This raises EmptyCommit if there are no changes, no new merges,
-    and allow_empty is false.
+    This raises PointlessCommit if there are no changes, no new merges,
+    and allow_pointless  is false.
 
     timestamp -- if not None, seconds-since-epoch for a
          postdated/predated commit.
@@ -63,7 +63,7 @@
 
     from bzrlib.osutils import local_time_offset, username
     from bzrlib.branch import gen_file_id
-    from bzrlib.errors import BzrError, EmptyCommit
+    from bzrlib.errors import BzrError, PointlessCommit
     from bzrlib.revision import Revision, RevisionReference
     from bzrlib.trace import mutter, note
     from bzrlib.xml import pack_xml
@@ -97,8 +97,8 @@
                                     specific_files,
                                     verbose)
 
-        if not (any_changes or allow_empty or pending_merges):
-            raise EmptyCommit()
+        if not (any_changes or allow_pointless or pending_merges):
+            raise PointlessCommit()
 
         for file_id in missing_ids:
             # Any files that have been deleted are now removed from the

=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py	2005-07-11 03:27:43 +0000
+++ b/bzrlib/errors.py	2005-07-11 03:40:02 +0000
@@ -68,5 +68,5 @@
             Exception.__init__(self)
 
 
-class EmptyCommit(Exception):
+class PointlessCommit(Exception):
     """Commit failed because nothing was changed."""

=== modified file 'bzrlib/selftest/blackbox.py'
--- a/bzrlib/selftest/blackbox.py	2005-07-06 05:24:29 +0000
+++ b/bzrlib/selftest/blackbox.py	2005-07-11 03:40:02 +0000
@@ -72,6 +72,16 @@
 
 
 
+class EmptyCommit(InTempDir):
+    def runTest(self):
+        self.runcmd("bzr init")
+        self.build_tree(['hello.txt'])
+        self.runcmd("bzr commit -m empty", retcode=1)
+        self.runcmd("bzr add hello.txt")
+        self.runcmd("bzr commit -m added")
+
+
+
 class OldTests(InTempDir):
     # old tests moved from ./testbzr
     def runTest(self):
@@ -256,13 +266,13 @@
         runcmd('bzr pull ../branch2')
         chdir('.bzr')
         runcmd('bzr pull')
-        runcmd('bzr commit -m empty')
+        runcmd('bzr commit --unchanged -m empty')
         runcmd('bzr pull')
         chdir('../../branch2')
         runcmd('bzr pull')
-        runcmd('bzr commit -m empty')
+        runcmd('bzr commit --unchanged -m empty')
         chdir('../branch1')
-        runcmd('bzr commit -m empty')
+        runcmd('bzr commit --unchanged -m empty')
         runcmd('bzr pull', retcode=1)
         chdir ('..')
 
@@ -372,4 +382,5 @@
                 InvalidCommands,
                 RevertCommand,
                 OldTests,
+                EmptyCommit,
                 ]

=== modified file 'bzrlib/selftest/whitebox.py'
--- a/bzrlib/selftest/whitebox.py	2005-07-11 03:29:50 +0000
+++ b/bzrlib/selftest/whitebox.py	2005-07-11 03:40:02 +0000
@@ -22,36 +22,36 @@
 
 class NoChanges(InTempDir):
     def runTest(self):
-        from bzrlib.errors import EmptyCommit
+        from bzrlib.errors import PointlessCommit
         
         b = Branch('.', init=True)
 
         self.build_tree(['hello.txt'])
 
-        self.assertRaises(EmptyCommit,
+        self.assertRaises(PointlessCommit,
                           b.commit,
                           'commit without adding',
-                          allow_empty=False)
+                          allow_pointless=False)
 
-        b.commit('commit empty tree',
-                 allow_empty=True)
+        b.commit('commit pointless tree',
+                 allow_pointless=True)
 
         b.add('hello.txt')
         
         b.commit('commit first added file',
-                 allow_empty=False)
+                 allow_pointless=False)
         
-        self.assertRaises(EmptyCommit,
+        self.assertRaises(PointlessCommit,
                           b.commit,
                           'commit after adding file',
-                          allow_empty=False)
+                          allow_pointless=False)
         
         b.commit('commit pointless revision with one file',
-                 allow_empty=True)
+                 allow_pointless=True)
 
         b.add_pending_merge('mbp at 892739123-2005-123123')
         b.commit('commit new merge with no text changes',
-                 allow_empty=False)
+                 allow_pointless=False)
         
 
 



More information about the Pkg-bazaar-commits mailing list