Exemple #1
0
 def calculateFileSets(self, CVS, Git):
     gitignore = ignore.Ignore(Git.log, '.gitignore')
     gitDir = self.ctx.getGitDir()
     bigitrsync = ignore.Ignore(Git.log,
                                CVS.path + '/.bigitrsync',
                                regex=True)
     CVSList = CVS.listContentFiles()
     CVSFileSet = set(CVSList)
     CVSFileSet.discard('.bigitrsync')
     GitList = Git.listContentFiles()
     GitFileSet = set(GitList)
     GitFileSet.discard('.bigitrsync')
     # Sync only explicitly requested files
     GitFileSet = bigitrsync.include(GitFileSet)
     DeletedFiles = CVSFileSet - GitFileSet
     # delete only files matching the sync expressions
     DeletedFiles = bigitrsync.include(DeletedFiles)
     # even if .cvsignore files are deleted in git, do not remove them in CVS
     DeletedFiles -= set(x for x in DeletedFiles
                         if x.split('/')[-1] == '.cvsignore')
     # do not delete from CVS files that are specified in .gitignore
     DeletedFiles = gitignore.filter(DeletedFiles)
     AddedFiles = GitFileSet - CVSFileSet
     CommonFiles = GitFileSet.intersection(CVSFileSet)
     GitDirs = set(os.path.dirname(x) for x in GitFileSet)
     GitDirs = set(x for x in GitDirs if x)
     CVSDirs = set(os.path.dirname(x) for x in CVSFileSet)
     CVSDirs = set(x for x in CVSDirs if x)
     AddedDirs = GitDirs - CVSDirs
     DeletedDirs = CVSDirs - GitDirs
     return GitFileSet, DeletedFiles, AddedFiles, CommonFiles, DeletedDirs, AddedDirs
Exemple #2
0
 def test_include(self):
     'tests explicitly including files instead'
     includefile = self.codedir + '/include'
     file(includefile, 'w').write('.*\\.c\n.*\\.h\n')
     logFile = self.logdir + '/log'
     self.log.stderr = os.open(logFile, os.O_CREAT | os.O_RDWR, 0700)
     i = ignore.Ignore(self.log, includefile, regex=True)
     ret = i.include([
         'foo.c',
         'foo.o',
         '/foo.h',
         '/dir/foo.c',
         '/dir/foo.o',
     ])
     os.close(self.log.stderr)
     self.assertEquals(
         file(logFile).readlines(), [
             'include: .*\\.c includes file foo.c\n',
             'include: .*\\.c includes file /dir/foo.c\n',
             'include: .*\\.h includes file /foo.h\n',
         ])
     self.assertEquals(ret, set([
         'foo.c',
         '/foo.h',
         '/dir/foo.c',
     ]))
Exemple #3
0
 def test_match(self, write):
     i = ignore.Ignore(self.log, self.ignorefile)
     self.assertEquals(i.match('ignores', '*.o', ['foo.c', 'foo.o']),
                       set(('foo.o', )))
     write.assert_called_once_with(mock.ANY,
                                   'ignore: *.o ignores file foo.o\n')
     write.reset_mock()
     self.assertEquals(
         i.match('ignores', '/path/*.o', ['foo.o', '/path/foo.o']),
         set(('/path/foo.o', )))
     write.assert_called_once_with(
         mock.ANY, 'ignore: /path/*.o ignores file /path/foo.o\n')
Exemple #4
0
 def test_filter(self):
     file(self.ignorefile, 'w').write('*.o\n/path/to/foo\n/dir/foo.o\n')
     logFile = self.logdir + '/log'
     self.log.stderr = os.open(logFile, os.O_CREAT | os.O_RDWR, 0700)
     i = ignore.Ignore(self.log, self.ignorefile)
     i.filter([
         'foo.c',
         'foo.o',
         '/path/to/foo',
         '/path/to/bar',
         '/dir/foo.c',
         '/dir/foo.o',
     ])
     os.close(self.log.stderr)
     self.assertEquals(
         file(logFile).readlines(), [
             'ignore: *.o ignores file foo.o\n',
             'ignore: *.o ignores file /dir/foo.o\n',
             'ignore: /path/to/foo ignores file /path/to/foo\n',
             'ignore: /dir/foo.o ignores file /dir/foo.o\n',
         ])
Exemple #5
0
 def test_includeEmpty(self):
     'tests explicitly including files instead'
     includefile = self.codedir + '/include'
     logFile = self.logdir + '/log'
     self.log.stderr = os.open(logFile, os.O_CREAT | os.O_RDWR, 0700)
     i = ignore.Ignore(self.log, includefile, regex=True)
     ret = i.include([
         'foo.c',
         'foo.o',
         '/foo.h',
         '/dir/foo.c',
         '/dir/foo.o',
     ])
     os.close(self.log.stderr)
     self.assertEquals(file(logFile).readlines(), [])
     self.assertEquals(ret, [
         'foo.c',
         'foo.o',
         '/foo.h',
         '/dir/foo.c',
         '/dir/foo.o',
     ])
Exemple #6
0
 def test_init(self):
     file(self.ignorefile, 'w').write('*.o\n#comment\n/path/to/foo\n')
     i = ignore.Ignore(self.log, self.ignorefile)
     self.assertEquals(i.patterns, ['*.o', '/path/to/foo'])
     self.assertEquals(i.fileName, os.path.basename(self.ignorefile))
Exemple #7
0
 def test_empty_init(self, parse):
     i = ignore.Ignore(self.log, self.ignorefile)
     self.assertEquals(i.patterns, None)
     self.assertEquals(i.fileName, os.path.basename(self.ignorefile))
     self.assertEquals(self.log, i.log)
     parse.assert_called_once_with(self.ignorefile)
Exemple #8
0
    def importcvs(self, repository, Git, CVS, cvsbranch, gitbranch):
        gitDir = self.ctx.getGitDir()
        repoName = self.ctx.getRepositoryName(repository)
        repoDir = '/'.join((gitDir, repoName))
        skeleton = self.ctx.getSkeleton(repository)
        exportDir = self.ctx.getCVSExportDir(repository)

        if os.path.exists(exportDir):
            util.removeRecursive(exportDir)
        os.makedirs(exportDir)
        os.chdir(os.path.dirname(exportDir))
        CVS.export(os.path.basename(exportDir))
        cvsignore = ignore.Ignore(Git.log, exportDir + '/.cvsignore')
        # Awaiting use case requiring partial import into Git before
        # writing test cases to implement it for import from CVS into Git
        # bigitrsync = ignore.Ignore(Git.log, gitDir + '/.bigitrsync', regex=True)
        exportedFiles = util.listFiles(exportDir)
        if not exportedFiles:
            raise RuntimeError("CVS branch '%s' for location '%s' contains no files"
                               %(CVS.branch, CVS.location))
        # Sync only explicitly requested files
        # exportedFiles = sorted(list(bigitrsync.include(exportedFiles)))

        os.chdir(exportDir)

        Git.initializeGitRepository()

        os.chdir(repoDir)
        addSkeleton = False
        branches = Git.branches()
        if gitbranch not in branches:
            if 'remotes/origin/' + gitbranch in branches:
                # check out existing remote branch
                Git.checkoutTracking(gitbranch)
            else:
                # check out a new "orphan" branch
                Git.checkoutNewImportBranch(gitbranch)
                addSkeleton = True
        else:
            if Git.branch() != gitbranch:
                Git.checkout(gitbranch)
            Git.fetch()
            Git.mergeFastForward('origin/' + gitbranch)

        # clean up after any garbage left over from previous runs so
        # that we can change branches
        Git.pristine()

        gitFiles = Git.listContentFiles()
        gitFiles = cvsignore.filter(set(gitFiles))
        gitFiles.discard('.bigitrsync')
        # delete only files matching the sync expressions
        # gitFiles = sorted(list(bigitrsync.include(gitFiles)))
        for filename in gitFiles:
            os.remove(filename)

        os.chdir(gitDir)

        util.copyFiles(exportDir, repoDir, exportedFiles)

        if addSkeleton:
            if skeleton:
                skelFiles = util.listFiles(skeleton)
                util.copyFiles(skeleton, repoDir, skelFiles)

        os.chdir(repoDir)
        Git.runImpPreHooks(gitbranch)
        if Git.status():
            # there is some change to commit
            Git.infoStatus()
            Git.infoDiff()
            # store Git.log.lastOutput() to email after successful push
            Git.addAll()

        # Git.addAll() will have regularized line ending differences,
        # and in case that is the only change, we need to check again
        # on status
        if Git.status():
            # FIXME: try to create a commit message that includes all
            # the CVS commit messages since the previous commit, de-duplicated
            Git.commit('import from CVS as of %s' %time.asctime())
            Git.push('origin', gitbranch, gitbranch)
            Git.runImpPostHooks(gitbranch)

        merger = gitmerge.Merger(self.ctx)
        merger.mergeFrom(repository, Git, gitbranch)