Ejemplo n.º 1
0
    def __init__(self, repository):
        from os.path import split
        from bzrlib import version_info, IGNORE_FILENAME

        if version_info > (0,9):
            from bzrlib.ignores import add_runtime_ignores, parse_ignore_file
        else:
            from bzrlib import DEFAULT_IGNORE

        WorkingDir.__init__(self, repository)
        # TODO: check if there is a "repository" in the configuration,
        # and use it as a bzr repository
        self.ignored = []
        self._working_tree = None

        # The bzr repository may have some plugins that needs to be activated
        load_plugins()

        try:
            bzrdir = BzrDir.open(self.repository.basedir)
            wt = self._working_tree = bzrdir.open_workingtree()

            # read .bzrignore for _addSubtree()
            if wt.has_filename(IGNORE_FILENAME):
                f = wt.get_file_byname(IGNORE_FILENAME)
                if version_info > (0,9):
                    self.ignored.extend(parse_ignore_file(f))
                else:
                    self.ignored.extend([ line.rstrip("\n\r") for line in f.readlines() ])
                f.close()
        except errors.NotBranchError, errors.NoWorkingTree:
            pass
Ejemplo n.º 2
0
 def test_parse_non_utf8(self):
     """Lines with non utf 8 characters should be discarded."""
     ignored = ignores.parse_ignore_file(StringIO(
             'utf8filename_a\n'
             'invalid utf8\x80\n'
             'utf8filename_b\n'
             ))
     self.assertEqual(set([
                     'utf8filename_a',
                     'utf8filename_b',
                    ]), ignored)
Ejemplo n.º 3
0
 def test_parse_non_utf8(self):
     """Lines with non utf 8 characters should be discarded."""
     ignored = ignores.parse_ignore_file(StringIO(
             'utf8filename_a\n'
             'invalid utf8\x80\n'
             'utf8filename_b\n'
             ))
     self.assertEqual(set([
                     'utf8filename_a',
                     'utf8filename_b',
                    ]), ignored)
Ejemplo n.º 4
0
    def test_create_if_missing(self):
        # $HOME should be set to '.'
        ignore_path = config.user_ignore_config_filename()
        self.failIfExists(ignore_path)
        user_ignores = ignores.get_user_ignores()
        self.assertEqual(set(ignores.USER_DEFAULTS), user_ignores)

        self.failUnlessExists(ignore_path)
        f = open(ignore_path, 'rb')
        try:
            entries = ignores.parse_ignore_file(f)
        finally:
            f.close()
        self.assertEqual(set(ignores.USER_DEFAULTS), entries)
Ejemplo n.º 5
0
    def test_create_if_missing(self):
        # $HOME should be set to '.'
        ignore_path = config.user_ignore_config_filename()
        self.assertPathDoesNotExist(ignore_path)
        user_ignores = ignores.get_user_ignores()
        self.assertEqual(set(ignores.USER_DEFAULTS), user_ignores)

        self.assertPathExists(ignore_path)
        f = open(ignore_path, 'rb')
        try:
            entries = ignores.parse_ignore_file(f)
        finally:
            f.close()
        self.assertEqual(set(ignores.USER_DEFAULTS), entries)
Ejemplo n.º 6
0
 def test_parse_fancy(self):
     ignored = ignores.parse_ignore_file(StringIO(
             './rootdir\n'
             'randomfile*\n'
             'path/from/ro?t\n'
             'unicode\xc2\xb5\n' # u'\xb5'.encode('utf8')
             'dos\r\n'
             '\n' # empty line
             '#comment\n'
             ' xx \n' # whitespace
             ))
     self.assertEqual(set(['./rootdir',
                       'randomfile*',
                       'path/from/ro?t',
                       u'unicode\xb5',
                       'dos',
                       ' xx ',
                      ]), ignored)
Ejemplo n.º 7
0
 def test_parse_fancy(self):
     ignored = ignores.parse_ignore_file(
         StringIO('./rootdir\n'
                  'randomfile*\n'
                  'path/from/ro?t\n'
                  'unicode\xc2\xb5\n'  # u'\xb5'.encode('utf8')
                  'dos\r\n'
                  '\n'  # empty line
                  '#comment\n'
                  ' xx \n'  # whitespace
                  ))
     self.assertEqual(
         set([
             './rootdir',
             'randomfile*',
             'path/from/ro?t',
             u'unicode\xb5',
             'dos',
             ' xx ',
         ]), ignored)
Ejemplo n.º 8
0
 def test_parse_empty(self):
     ignored = ignores.parse_ignore_file(StringIO(''))
     self.assertEqual(set([]), ignored)
Ejemplo n.º 9
0
 def test_parse_empty(self):
     ignored = ignores.parse_ignore_file(StringIO(''))
     self.assertEqual(set([]), ignored)