[Pkg-bazaar-commits] ./bzr/unstable r979: - fix bugs and add tests for doing commit of selected directories

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


------------------------------------------------------------
revno: 979
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Mon 2005-07-25 18:54:01 -0300
message:
  - fix bugs and add tests for doing commit of selected directories
modified:
  NEWS
  bzrlib/commands.py
  bzrlib/osutils.py
  bzrlib/selftest/versioning.py
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS	2005-07-23 13:53:01 +0000
+++ b/NEWS	2005-07-25 21:54:01 +0000
@@ -38,6 +38,11 @@
 
     * By default the commit command refuses to record a revision with
       no changes unless the ``--unchanged`` option is given.
+      
+      
+  BUG FIXES:
+  
+    * Fix bugs in committing only selected files or within a subdirectory.
 
 
 bzr-0.0.5  2005-06-15

=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py	2005-07-23 14:06:37 +0000
+++ b/bzrlib/commands.py	2005-07-25 21:54:01 +0000
@@ -1184,10 +1184,12 @@
 
 class cmd_commit(Command):
     """Commit changes into a new revision.
+    
+    If no arguments are given, the entire tree is committed.
 
     If selected files are specified, only changes to those files are
-    committed.  If a directory is specified then its contents are also
-    committed.
+    committed.  If a directory is specified then the directory and everything 
+    within it is committed.
 
     A selected-file commit may fail in some cases where the committed
     tree would be invalid, such as trying to commit a file in a
@@ -1201,6 +1203,8 @@
     takes_options = ['message', 'file', 'verbose', 'unchanged']
     aliases = ['ci', 'checkin']
 
+    # TODO: Give better message for -s, --summary, used by tla people
+    
     def run(self, message=None, file=None, verbose=True, selected_list=None,
             unchanged=False):
         from bzrlib.errors import PointlessCommit
@@ -1208,6 +1212,8 @@
 
         ## Warning: shadows builtin file()
         if not message and not file:
+            # FIXME: Ugly; change status code to send to a provided function?
+            
             import cStringIO
             stdout = sys.stdout
             catcher = cStringIO.StringIO()
@@ -1228,6 +1234,12 @@
             message = codecs.open(file, 'rt', bzrlib.user_encoding).read()
 
         b = find_branch('.')
+        if selected_list:
+            selected_list = [b.relpath(s) for s in selected_list]
+        else:
+            selected_list = [b.relpath('.')]
+        if selected_list == ['.']:
+            selected_list = None
 
         try:
             b.commit(message, verbose=verbose,

=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py	2005-07-23 13:59:30 +0000
+++ b/bzrlib/osutils.py	2005-07-25 21:54:01 +0000
@@ -139,6 +139,9 @@
     that . and .. and repeated slashes are eliminated, and the separators
     are canonical for the platform.
     
+    The empty string as a dir name is taken as top-of-tree and matches 
+    everything.
+    
     >>> is_inside('src', 'src/foo.c')
     True
     >>> is_inside('src', 'srccontrol')
@@ -147,13 +150,19 @@
     True
     >>> is_inside('foo.c', 'foo.c')
     True
+    >>> is_inside('foo.c', '')
+    False
+    >>> is_inside('', 'foo.c')
+    True
     """
     # XXX: Most callers of this can actually do something smarter by 
     # looking at the inventory
-
     if dir == fname:
         return True
     
+    if dir == '':
+        return True
+    
     if dir[-1] != os.sep:
         dir += os.sep
     

=== modified file 'bzrlib/selftest/versioning.py'
--- a/bzrlib/selftest/versioning.py	2005-07-25 18:49:38 +0000
+++ b/bzrlib/selftest/versioning.py	2005-07-25 21:54:01 +0000
@@ -17,14 +17,19 @@
 
 """Tests of simple versioning operations"""
 
-
-from bzrlib.selftest import InTempDir
+# TODO: test adding a file whose directory is not versioned
+# TODO: test trying to commit within a directory that is not yet added
+
+
+import os
+from bzrlib.selftest import InTempDir, BzrTestBase
+from bzrlib.branch import Branch
+
 
 class Mkdir(InTempDir):
     def runTest(self): 
         """Basic 'bzr mkdir' operation"""
         from bzrlib.commands import run_bzr
-        import os
 
         run_bzr(['init'])
         run_bzr(['mkdir', 'foo'])
@@ -52,7 +57,6 @@
         branch add doesn't do that.
         """
         from bzrlib.branch import Branch
-        import os
         from bzrlib.errors import NotVersionedError
 
         b = Branch('.', init=True)
@@ -65,9 +69,51 @@
                           'foo/hello')
         
         
-class SubdirCommit(InTempDir):
+class SubdirCommit(BzrTestBase):
     def runTest(self):
-        pass
+        """Test committing a subdirectory, and committing within a directory."""
+        run_bzr = self.run_bzr
+        eq = self.assertEqual
+
+        self.build_tree(['a/', 'b/'])
+        
+        run_bzr('init')
+        b = Branch('.')
+        
+        for fn in ('a/one', 'b/two', 'top'):
+            file(fn, 'w').write('old contents')
+            
+        run_bzr('add')
+        run_bzr('commit', '-m', 'first revision')
+        
+        for fn in ('a/one', 'b/two', 'top'):
+            file(fn, 'w').write('new contents')
+            
+        run_bzr('commit', 'a', '-m', 'commit a only')
+        
+        old = b.revision_tree(b.lookup_revision(1))
+        new = b.revision_tree(b.lookup_revision(2))
+        
+        eq(new.get_file_by_path('b/two').read(), 'old contents')
+        eq(new.get_file_by_path('top').read(), 'old contents')
+        eq(new.get_file_by_path('a/one').read(), 'new contents')
+        
+        os.chdir('a')
+        # commit from here should do nothing
+        run_bzr('commit', '.', '-m', 'commit subdir again', '--unchanged')
+        v3 = b.revision_tree(b.lookup_revision(3))
+        eq(v3.get_file_by_path('b/two').read(), 'old contents')
+        eq(v3.get_file_by_path('top').read(), 'old contents')
+        eq(v3.get_file_by_path('a/one').read(), 'new contents')
+                
+        # commit in subdirectory commits whole tree
+        run_bzr('commit', '-m', 'commit in subdir')
+        v4 = b.revision_tree(b.lookup_revision(4))
+        eq(v4.get_file_by_path('b/two').read(), 'new contents')        
+        eq(v4.get_file_by_path('top').read(), 'new contents')
+        
+        # TODO: factor out some kind of assert_tree_state() method
+        
         
         
 class SubdirAdd(InTempDir):
@@ -76,7 +122,6 @@
         
         from bzrlib.branch import Branch
         from bzrlib.commands import run_bzr
-        import os
         
         eq = self.assertEqual
         ass = self.assert_
@@ -102,10 +147,4 @@
         chdir('..')
         eq(run_bzr(['add']), 0)
         eq(list(b.unknowns()), [])
-           
-
-
-TEST_CLASSES = [
-    Mkdir,
-    AddInUnversioned,
-    ]
+        
\ No newline at end of file



More information about the Pkg-bazaar-commits mailing list