Example #1
0
    def testUpdateWithSubmodule(self):
        """
            Tests the checkout of a module 'egg' with a submodule 'submodule_a' in it.
            Add a new 'submodule_b' to 'egg' and check it succesfully initializes.
        """
        from mr.developer.develop import CmdCheckout, CmdUpdate
        submodule_name = 'submodule_a'
        submodule = self.createRepo(submodule_name)
        self.addFileToRepo(submodule, 'foo')
        egg = self.createRepo('egg')
        self.addFileToRepo(egg, 'bar')
        self.addSubmoduleToRepo(egg, submodule, submodule_name)

        src = os.path.join(self.tempdir, 'src')
        develop = MockDevelop()
        develop.sources = {
            'egg':
            Source(kind='git',
                   name='egg',
                   url='file:///%s' % egg,
                   path=os.path.join(src, 'egg'))
        }
        _log = patch('mr.developer.git.logger')
        log = _log.__enter__()
        try:
            CmdCheckout(develop)(develop.parser.parse_args(['co', 'egg']))
            assert set(os.listdir(os.path.join(src, 'egg'))) == set(
                ('submodule_a', '.git', 'bar', '.gitmodules'))
            assert set(os.listdir(os.path.join(
                src, 'egg/%s' % submodule_name))) == set(('.git', 'foo'))
            assert log.method_calls == [
                ('info', ("Cloned 'egg' with git.", ), {}),
                ('info', ("Initialized 'egg' submodule at '%s' with git." %
                          submodule_name, ), {})
            ]
        finally:
            _log.__exit__()

        submodule_b_name = 'submodule_b'
        submodule_b = self.createRepo(submodule_b_name)
        self.addFileToRepo(submodule_b, 'foo_b')
        self.addSubmoduleToRepo(egg, submodule_b, submodule_b_name)

        log = _log.__enter__()
        try:
            CmdUpdate(develop)(develop.parser.parse_args(['up', 'egg']))
            assert set(os.listdir(os.path.join(src, 'egg'))) == set(
                ('submodule_a', 'submodule_b', '.git', 'bar', '.gitmodules'))
            assert set(
                os.listdir(os.path.join(src,
                                        'egg/%s' % submodule_b_name))) == set(
                                            ('.git', 'foo_b'))
            assert log.method_calls == [
                ('info', ("Updated 'egg' with git.", ), {}),
                ('info', ("Initialized 'egg' submodule at '%s' with git." %
                          submodule_b_name, ), {})
            ]
        finally:
            _log.__exit__()
Example #2
0
    def testCheckoutWithSubmodulesOptionNeverSourceAlways(self):
        """
            Tests the checkout of a module 'egg' with a submodule 'submodule_a' in it
            and a module 'egg2' with the same submodule, initializing only the submodule
            on egg that has the 'always' option
        """

        from mr.developer.develop import CmdCheckout
        submodule_name = 'submodule_a'
        submodule_a = self.createRepo(submodule_name)
        self.addFileToRepo(submodule_a, 'foo')
        egg = self.createRepo('egg')
        self.addFileToRepo(egg, 'bar')
        self.addSubmoduleToRepo(egg, submodule_a, submodule_name)

        egg2 = self.createRepo('egg2')
        self.addFileToRepo(egg2, 'bar')
        self.addSubmoduleToRepo(egg2, submodule_a, submodule_name)

        src = os.path.join(self.tempdir, 'src')
        develop = MockDevelop()
        develop.update_git_submodules = 'never'
        develop.sources = {
            'egg':
            Source(kind='git',
                   name='egg',
                   url='file:///%s' % egg,
                   path=os.path.join(src, 'egg'),
                   submodules='always'),
            'egg2':
            Source(kind='git',
                   name='egg2',
                   url='file:///%s' % egg2,
                   path=os.path.join(src, 'egg2'))
        }
        _log = patch('mr.developer.git.logger')
        log = _log.__enter__()
        try:
            CmdCheckout(develop)(develop.parser.parse_args(['co', 'egg']))
            assert set(os.listdir(os.path.join(src, 'egg'))) == set(
                ('submodule_a', '.git', 'bar', '.gitmodules'))
            assert set(os.listdir(os.path.join(
                src, 'egg/%s' % submodule_name))) == set(('foo', '.git'))
            assert set(os.listdir(os.path.join(src, 'egg2'))) == set(
                ('submodule_a', '.git', 'bar', '.gitmodules'))
            assert set(
                os.listdir(os.path.join(src,
                                        'egg2/%s' % submodule_name))) == set()

            assert log.method_calls == [
                ('info', ("Cloned 'egg' with git.", ), {}),
                ('info', ("Initialized 'egg' submodule at '%s' with git." %
                          submodule_name, ), {}),
                ('info', ("Cloned 'egg2' with git.", ), {})
            ]
        finally:
            _log.__exit__()
Example #3
0
    def testUpdateWithSubmoduleDontUpdatePreviousSubmodules(self):
        """
            Tests the checkout of a module 'egg' with a submodule 'submodule_a' in it.
            Commits changes in the detached submodule, and checks update didn't break
            the changes.
        """
        from mr.developer.develop import CmdCheckout, CmdUpdate
        submodule_name = 'submodule_a'
        submodule = self.createRepo(submodule_name)
        self.addFileToRepo(submodule, 'foo')
        egg = self.createRepo('egg')
        self.addFileToRepo(egg, 'bar')
        self.addSubmoduleToRepo(egg, submodule, submodule_name)

        src = os.path.join(self.tempdir, 'src')
        develop = MockDevelop()
        develop.sources = {
            'egg':
            Source(kind='git',
                   name='egg',
                   url='file:///%s' % egg,
                   path=os.path.join(src, 'egg'))
        }
        _log = patch('mr.developer.git.logger')
        log = _log.__enter__()
        try:
            CmdCheckout(develop)(develop.parser.parse_args(['co', 'egg']))
            assert set(os.listdir(os.path.join(src, 'egg'))) == set(
                ('submodule_a', '.git', 'bar', '.gitmodules'))
            assert set(os.listdir(os.path.join(
                src, 'egg/%s' % submodule_name))) == set(('.git', 'foo'))
            assert log.method_calls == [
                ('info', ("Cloned 'egg' with git.", ), {}),
                ('info', ("Initialized 'egg' submodule at '%s' with git." %
                          submodule_name, ), {})
            ]
        finally:
            _log.__exit__()

        self.gitConfigUser(os.path.join(src, 'egg/%s' % submodule_name))
        self.addFileToRepo(os.path.join(src, 'egg/%s' % submodule_name),
                           'newfile')

        log = _log.__enter__()
        try:
            CmdUpdate(develop)(develop.parser.parse_args(['up', '-f', 'egg']))
            assert set(os.listdir(os.path.join(src, 'egg'))) == set(
                ('submodule_a', '.git', 'bar', '.gitmodules'))
            assert set(os.listdir(os.path.join(src, 'egg/%s' %
                                               submodule_name))) == set(
                                                   ('.git', 'foo', 'newfile'))
            assert log.method_calls == [('info', ("Updated 'egg' with git.", ),
                                         {})]
        finally:
            _log.__exit__()
Example #4
0
 def testUpdateWithoutRevisionPin(self):
     from mr.developer.develop import CmdCheckout
     from mr.developer.develop import CmdUpdate
     process = Process()
     repository = os.path.join(self.tempdir, 'repository')
     rc, lines = process.popen(
         "svnadmin create %s" % repository)
     assert rc == 0
     checkout = os.path.join(self.tempdir, 'checkout')
     rc, lines = process.popen(
         "svn checkout file://%s %s" % (repository, checkout),
         echo=False)
     assert rc == 0
     foo = os.path.join(checkout, 'foo')
     self.mkfile(foo, 'foo')
     rc, lines = process.popen(
         "svn add %s" % foo,
         echo=False)
     assert rc == 0
     rc, lines = process.popen(
         "svn commit %s -m foo" % foo,
         echo=False)
     assert rc == 0
     bar = os.path.join(checkout, 'bar')
     self.mkfile(bar, 'bar')
     rc, lines = process.popen(
         "svn add %s" % bar,
         echo=False)
     assert rc == 0
     rc, lines = process.popen(
         "svn commit %s -m bar" % bar,
         echo=False)
     assert rc == 0
     src = os.path.join(self.tempdir, 'src')
     develop = MockDevelop()
     develop.sources = {
         'egg': Source(
             kind='svn',
             name='egg',
             url='file://%s' % repository,
             path=os.path.join(src, 'egg'))}
     _log = patch('mr.developer.svn.logger')
     log = _log.__enter__()
     try:
         CmdCheckout(develop)(develop.parser.parse_args(['co', 'egg']))
         assert set(os.listdir(os.path.join(src, 'egg'))) == set(('.svn', 'bar', 'foo'))
         CmdUpdate(develop)(develop.parser.parse_args(['up', 'egg']))
         assert set(os.listdir(os.path.join(src, 'egg'))) == set(('.svn', 'bar', 'foo'))
         assert log.method_calls == [
             ('info', ("Checked out 'egg' with subversion.",), {}),
             ('info', ("Updated 'egg' with subversion.",), {})]
     finally:
         _log.__exit__()
Example #5
0
    def testUpdateWithoutRevisionPin(self):
        from mr.developer.develop import CmdCheckout
        from mr.developer.develop import CmdUpdate
        repository = os.path.join(self.tempdir, 'repository')
        os.mkdir(repository)
        process = Process(cwd=repository)
        rc, lines = process.popen(
            "hg init %s" % repository)
        assert rc == 0

        foo = os.path.join(repository, 'foo')
        self.mkfile(foo, 'foo')
        rc, lines = process.popen(
            "hg add %s" % foo,
            echo=False)
        assert rc == 0
        rc, lines = process.popen(
            "hg commit %s -m foo -u test" % foo,
            echo=False)
        assert rc == 0
        bar = os.path.join(repository, 'bar')
        self.mkfile(bar, 'bar')
        rc, lines = process.popen(
            "hg add %s" % bar,
            echo=False)
        assert rc == 0
        rc, lines = process.popen(
            "hg commit %s -m bar -u test" % bar,
            echo=False)
        assert rc == 0
        src = os.path.join(self.tempdir, 'src')
        os.mkdir(src)
        develop = MockDevelop()
        develop.sources = {
            'egg': Source(
                kind='hg',
                name='egg',
                url='%s' % repository,
                path=os.path.join(src, 'egg'))}
        _log = patch('mr.developer.mercurial.logger')
        log = _log.__enter__()
        try:
            CmdCheckout(develop)(develop.parser.parse_args(['co', 'egg']))
            assert set(os.listdir(os.path.join(src, 'egg'))) == set(('.hg', 'bar', 'foo'))
            CmdUpdate(develop)(develop.parser.parse_args(['up', 'egg']))
            assert set(os.listdir(os.path.join(src, 'egg'))) == set(('.hg', 'bar', 'foo'))
            assert log.method_calls == [
                ('info', ("Cloned 'egg' with mercurial.",), {}),
                ('info', ("Updated 'egg' with mercurial.",), {}),
                ('info', ("Switched 'egg' to default.",), {})]
        finally:
            _log.__exit__()
Example #6
0
 def testUpdateWithRevisionPin(self):
     from mr.developer.develop import CmdCheckout
     from mr.developer.develop import CmdUpdate
     process = Process()
     repository = os.path.join(self.tempdir, 'repository')
     rc, lines = process.popen(
         "svnadmin create %s" % repository)
     assert rc == 0
     checkout = os.path.join(self.tempdir, 'checkout')
     rc, lines = process.popen(
         "svn checkout file://%s %s" % (repository, checkout),
         echo=False)
     assert rc == 0
     foo = os.path.join(checkout, 'foo')
     self.mkfile(foo, 'foo')
     rc, lines = process.popen(
         "svn add %s" % foo,
         echo=False)
     assert rc == 0
     rc, lines = process.popen(
         "svn commit %s -m foo" % foo,
         echo=False)
     assert rc == 0
     bar = os.path.join(checkout, 'bar')
     self.mkfile(bar, 'bar')
     rc, lines = process.popen(
         "svn add %s" % bar,
         echo=False)
     assert rc == 0
     rc, lines = process.popen(
         "svn commit %s -m bar" % bar,
         echo=False)
     assert rc == 0
     src = os.path.join(self.tempdir, 'src')
     develop = MockDevelop()
     develop.sources = {
         'egg': Source(
             kind='svn',
             name='egg',
             url='file://%s@1' % repository,
             path=os.path.join(src, 'egg'))}
     CmdCheckout(develop)(develop.parser.parse_args(['co', 'egg']))
     assert set(os.listdir(os.path.join(src, 'egg'))) == set(('.svn', 'foo'))
     CmdUpdate(develop)(develop.parser.parse_args(['up', 'egg']))
     assert set(os.listdir(os.path.join(src, 'egg'))) == set(('.svn', 'foo'))
Example #7
0
    def testUpdateWithRevisionPin(self):
        from mr.developer.develop import CmdCheckout
        from mr.developer.develop import CmdUpdate
        repository = os.path.join(self.tempdir, 'repository')
        os.mkdir(repository)
        process = Process(cwd=repository)
        rc, lines = process.popen("hg init %s" % repository)
        assert rc == 0
        foo = os.path.join(repository, 'foo')
        self.mkfile(foo, 'foo')
        rc, lines = process.popen("hg add %s" % foo, echo=False)
        assert rc == 0

        # create branch for testing
        rc, lines = process.popen("hg branch test", echo=False)
        assert rc == 0

        rc, lines = process.popen("hg commit %s -m foo -u test" % foo,
                                  echo=False)
        assert rc == 0

        # get comitted rev
        rc, lines = process.popen("hg log %s" % foo, echo=False)
        assert rc == 0
        rev = lines[0].split()[1].split(b(':'))[1]

        # return to default branch
        rc, lines = process.popen("hg branch default", echo=False)
        assert rc == 0

        bar = os.path.join(repository, 'bar')
        self.mkfile(bar, 'bar')
        rc, lines = process.popen("hg add %s" % bar, echo=False)
        assert rc == 0
        rc, lines = process.popen("hg commit %s -m bar -u test" % bar,
                                  echo=False)
        assert rc == 0
        src = os.path.join(self.tempdir, 'src')
        os.mkdir(src)
        develop = MockDevelop()

        # check rev
        develop.sources = {
            'egg':
            Source(kind='hg',
                   name='egg',
                   rev=rev,
                   url='%s' % repository,
                   path=os.path.join(src, 'egg'))
        }
        CmdCheckout(develop)(develop.parser.parse_args(['co', 'egg']))
        assert set(os.listdir(os.path.join(src, 'egg'))) == set(('.hg', 'foo'))
        CmdUpdate(develop)(develop.parser.parse_args(['up', 'egg']))
        assert set(os.listdir(os.path.join(src, 'egg'))) == set(('.hg', 'foo'))

        # check branch
        develop.sources = {
            'egg':
            Source(kind='hg',
                   name='egg',
                   branch='test',
                   url='%s' % repository,
                   path=os.path.join(src, 'egg'))
        }
        CmdCheckout(develop)(develop.parser.parse_args(['co', 'egg']))
        assert set(os.listdir(os.path.join(src, 'egg'))) == set(('.hg', 'foo'))
        CmdUpdate(develop)(develop.parser.parse_args(['up', 'egg']))
        assert set(os.listdir(os.path.join(src, 'egg'))) == set(('.hg', 'foo'))

        # we can't use both rev and branch
        pytest.raises(
            SystemExit, """
            develop.sources = {
                'egg': Source(
                    kind='hg',
                    name='egg',
                    branch='test',
                    rev=rev,
                    url='%s' % repository,
                    path=os.path.join(src, 'egg-failed'))}
            CmdCheckout(develop)(develop.parser.parse_args(['co', 'egg']))
        """)
Example #8
0
    def testUpdateWithRevisionPin(self):
        from mr.developer.develop import CmdCheckout
        from mr.developer.develop import CmdUpdate
        from mr.developer.develop import CmdStatus
        repository = self.createRepo('repository')
        process = Process(cwd=repository)
        foo = os.path.join(repository, 'foo')
        self.mkfile(foo, 'foo')
        rc, lines = process.popen("git add %s" % foo, echo=False)
        assert rc == 0

        rc, lines = process.popen("git commit -m 'Initial'", echo=False)
        assert rc == 0

        # create branch for testing
        rc, lines = process.popen("git checkout -b test", echo=False)
        assert rc == 0

        foo2 = os.path.join(repository, 'foo2')
        self.mkfile(foo2, 'foo2')
        rc, lines = process.popen("git add %s" % foo2, echo=False)
        assert rc == 0

        rc, lines = process.popen("git commit -m foo", echo=False)
        assert rc == 0

        # get comitted rev
        rc, lines = process.popen("git log", echo=False)
        assert rc == 0
        rev = lines[0].split()[1]

        # return to default branch
        rc, lines = process.popen("git checkout master", echo=False)
        assert rc == 0

        bar = os.path.join(repository, 'bar')
        self.mkfile(bar, 'bar')
        rc, lines = process.popen("git add %s" % bar, echo=False)
        assert rc == 0
        rc, lines = process.popen("git commit -m bar", echo=False)
        assert rc == 0
        src = os.path.join(self.tempdir, 'src')
        os.mkdir(src)
        develop = MockDevelop()
        develop.sources_dir = src

        # check rev
        develop.sources = {
            'egg':
            Source(kind='git',
                   name='egg',
                   rev=rev,
                   url='%s' % repository,
                   path=os.path.join(src, 'egg'))
        }
        CmdCheckout(develop)(develop.parser.parse_args(['co', 'egg']))
        assert set(os.listdir(os.path.join(src, 'egg'))) == set(
            ('.git', 'foo', 'foo2'))
        CmdUpdate(develop)(develop.parser.parse_args(['up', 'egg']))
        assert set(os.listdir(os.path.join(src, 'egg'))) == set(
            ('.git', 'foo', 'foo2'))

        shutil.rmtree(os.path.join(src, 'egg'))

        # check branch
        develop.sources = {
            'egg':
            Source(kind='git',
                   name='egg',
                   branch='test',
                   url='%s' % repository,
                   path=os.path.join(src, 'egg'))
        }
        CmdCheckout(develop)(develop.parser.parse_args(['co', 'egg']))
        assert set(os.listdir(os.path.join(src, 'egg'))) == set(
            ('.git', 'foo', 'foo2'))
        CmdUpdate(develop)(develop.parser.parse_args(['up', 'egg']))
        assert set(os.listdir(os.path.join(src, 'egg'))) == set(
            ('.git', 'foo', 'foo2'))

        CmdStatus(develop)(develop.parser.parse_args(['status']))

        # we can't use both rev and branch
        pytest.raises(
            SystemExit, """
            develop.sources = {
                'egg': Source(
                    kind='git',
                    name='egg',
                    branch='test',
                    rev=rev,
                    url='%s' % repository,
                    path=os.path.join(src, 'egg-failed'))}
            CmdCheckout(develop)(develop.parser.parse_args(['co', 'egg']))
        """)