示例#1
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__()
    def testCheckoutWithSubmodulesOptionNeverSourceAlways(
            self, develop, mkgitrepo, src):
        """
            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.commands import CmdCheckout
        submodule_name = 'submodule_a'
        submodule_a = mkgitrepo(submodule_name)
        submodule_a.add_file('foo')
        egg = mkgitrepo('egg')
        egg.add_file('bar')
        egg.add_submodule(submodule_a, submodule_name)

        egg2 = mkgitrepo('egg2')
        egg2.add_file('bar')
        egg2.add_submodule(submodule_a, submodule_name)

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

            assert log.method_calls == [
                ('info', ("Cloned 'egg' with git from '%s'." % egg.url, ), {}),
                ('info', ("Initialized 'egg' submodule at '%s' with git." %
                          submodule_name, ), {}),
                ('info', ("Cloned 'egg2' with git from '%s'." % egg2.url, ),
                 {})
            ]
        finally:
            _log.__exit__()
示例#3
0
 def testUpdateWithoutRevisionPin(self, develop, mkgitrepo, src):
     from mr.developer.commands import CmdCheckout
     from mr.developer.commands import CmdUpdate
     repository = mkgitrepo('repository')
     repository.add_file('foo')
     repository.add_file('bar')
     develop.sources = {
         'egg': Source(
             kind='git',
             name='egg',
             url=repository.url,
             path=src['egg'])}
     _log = patch('mr.developer.git.logger')
     log = _log.__enter__()
     try:
         CmdCheckout(develop)(develop.parser.parse_args(['co', 'egg']))
         assert set(os.listdir(src['egg'])) == set(('.git', 'bar', 'foo'))
         CmdUpdate(develop)(develop.parser.parse_args(['up', 'egg']))
         assert set(os.listdir(src['egg'])) == set(('.git', 'bar', 'foo'))
         assert log.method_calls == [
             ('info', ("Cloned 'egg' with git from '%s'." % repository.url,), {}),
             ('info', ("Updated 'egg' with git.",), {}),
             ('info', ("Switching to branch 'master'.",), {})]
     finally:
         _log.__exit__()
示例#4
0
    def testUpdateWithoutRevisionPin(self, develop, src, tempdir):
        from mr.developer.commands import CmdCheckout
        from mr.developer.commands import CmdUpdate
        repository = tempdir['repository']
        os.mkdir(repository)
        process = Process(cwd=repository)
        process.check_call("hg init %s" % repository)

        foo = repository['foo']
        foo.create_file('foo')
        process.check_call("hg add %s" % foo, echo=False)
        process.check_call("hg commit %s -m foo -u test" % foo, echo=False)
        bar = repository['bar']
        bar.create_file('bar')
        process.check_call("hg add %s" % bar, echo=False)
        process.check_call("hg commit %s -m bar -u test" % bar, echo=False)
        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__()
示例#5
0
 def testUpdateWithRevisionPin(self, develop, src, tempdir):
     from mr.developer.commands import CmdCheckout
     from mr.developer.commands import CmdUpdate
     process = Process()
     repository = tempdir['repository']
     process.check_call("svnadmin create %s" % repository)
     checkout = tempdir['checkout']
     process.check_call(
         "svn checkout file://%s %s" % (repository, checkout),
         echo=False)
     foo = checkout['foo']
     foo.create_file('foo')
     process.check_call("svn add %s" % foo, echo=False)
     process.check_call("svn commit %s -m foo" % foo, echo=False)
     bar = checkout['bar']
     bar.create_file('bar')
     process.check_call("svn add %s" % bar, echo=False)
     process.check_call("svn commit %s -m bar" % bar, echo=False)
     develop.sources = {
         'egg': Source(
             kind='svn',
             name='egg',
             url='file://%s@1' % repository,
             path=src['egg'])}
     CmdCheckout(develop)(develop.parser.parse_args(['co', 'egg']))
     assert set(os.listdir(src['egg'])) == set(('.svn', 'foo'))
     CmdUpdate(develop)(develop.parser.parse_args(['up', 'egg']))
     assert set(os.listdir(src['egg'])) == set(('.svn', 'foo'))
示例#6
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__()
示例#7
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__()
    def testUpdateWithSubmoduleCheckout(self, develop, mkgitrepo, src):
        """
            Tests the checkout of a module 'egg' with a submodule 'submodule_a' in it.
            Add a new 'submodule_b' to 'egg' and check it doesn't get initialized.
        """
        from mr.developer.commands import CmdCheckout, CmdUpdate
        submodule_name = 'submodule_a'
        submodule = mkgitrepo(submodule_name)
        submodule.add_file('foo')
        egg = mkgitrepo('egg')
        egg.add_file('bar')
        egg.add_submodule(submodule, submodule_name)

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

        submodule_b_name = 'submodule_b'
        submodule_b = mkgitrepo(submodule_b_name)
        submodule_b.add_file('foo_b')
        egg.add_submodule(submodule_b, submodule_b_name)

        log = _log.__enter__()
        try:
            CmdUpdate(develop)(develop.parser.parse_args(['up', 'egg']))
            assert set(os.listdir(src['egg'])) == set(
                ('submodule_a', 'submodule_b', '.git', 'bar', '.gitmodules'))
            assert set(os.listdir(src['egg/%s' % submodule_b_name])) == set()
            assert log.method_calls == [
                ('info', ("Updated 'egg' with git.", ), {}),
                ('info', ("Switching to branch 'master'.", ), {})
            ]
        finally:
            _log.__exit__()
示例#9
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__()
示例#10
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__()
    def testUpdateWithSubmoduleDontUpdatePreviousSubmodules(
            self, develop, mkgitrepo, src):
        """
            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.commands import CmdCheckout, CmdUpdate
        submodule_name = 'submodule_a'
        submodule = mkgitrepo(submodule_name)
        submodule.add_file('foo')
        egg = mkgitrepo('egg')
        egg.add_file('bar')
        egg.add_submodule(submodule, submodule_name)

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

        repo = GitRepo(src['egg/%s' % submodule_name])
        repo.setup_user()
        repo.add_file('newfile')

        log = _log.__enter__()
        try:
            CmdUpdate(develop)(develop.parser.parse_args(['up', '-f', 'egg']))
            assert set(os.listdir(src['egg'])) == set(
                ('submodule_a', '.git', 'bar', '.gitmodules'))
            assert set(os.listdir(src['egg/%s' % submodule_name])) == set(
                ('.git', 'foo', 'newfile'))
            assert log.method_calls == [
                ('info', ("Updated 'egg' with git.", ), {}),
                ('info', ("Switching to branch 'master'.", ), {})
            ]
        finally:
            _log.__exit__()
示例#12
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'))
示例#13
0
    def testUpdateVerbose(self, develop, mkgitrepo, src, capsys):
        from mr.developer.commands import CmdCheckout
        from mr.developer.commands import CmdUpdate
        from mr.developer.commands import CmdStatus
        repository = mkgitrepo('repository')
        repository.add_file('foo')
        repository.add_file('bar')
        repository.add_branch('develop')
        develop.sources = {
            'egg':
            Source(kind='git', name='egg', url=repository.url, path=src['egg'])
        }
        _log = patch('mr.developer.git.logger')
        log = _log.__enter__()
        try:
            CmdCheckout(develop)(develop.parser.parse_args(['co', 'egg',
                                                            '-v']))
            assert set(os.listdir(src['egg'])) == set(('.git', 'bar', 'foo'))
            captured = capsys.readouterr()
            assert captured.out.startswith(
                "Initialized empty Git repository in")
            CmdUpdate(develop)(develop.parser.parse_args(['up', 'egg', '-v']))
            assert set(os.listdir(src['egg'])) == set(('.git', 'bar', 'foo'))
            assert log.method_calls == [
                ('info',
                 ("Cloned 'egg' with git from '%s'." % repository.url, ), {}),
                ('info', ("Updated 'egg' with git.", ), {}),
                ('info',
                 ("Switching to remote branch 'remotes/origin/master'.", ), {})
            ]
            captured = capsys.readouterr()
            older = "* develop\n  remotes/origin/HEAD -> origin/develop\n  remotes/origin/develop\n  remotes/origin/master\nBranch master set up to track remote branch master from origin.\n  develop\n* master\n  remotes/origin/HEAD -> origin/develop\n  remotes/origin/develop\n  remotes/origin/master\nAlready up-to-date.\n\n"
            newer = "* develop\n  remotes/origin/HEAD -> origin/develop\n  remotes/origin/develop\n  remotes/origin/master\nBranch 'master' set up to track remote branch 'master' from 'origin'.\n  develop\n* master\n  remotes/origin/HEAD -> origin/develop\n  remotes/origin/develop\n  remotes/origin/master\nAlready up to date.\n\n"
            # git output varies between versions...
            assert captured.out in [older, newer]
            CmdStatus(develop)(develop.parser.parse_args(['status', '-v']))
            captured = capsys.readouterr()
            assert captured.out == "~   A egg\n      ## master...origin/master\n\n"

        finally:
            _log.__exit__()
示例#14
0
 def testUpdateWithoutRevisionPin(self):
     from mr.developer.commands import CmdCheckout
     from mr.developer.commands import CmdUpdate
     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 %s -m foo" % foo, 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 %s -m bar" % bar, echo=False)
     assert rc == 0
     src = os.path.join(self.tempdir, 'src')
     develop = MockDevelop()
     develop.sources = {
         'egg':
         Source(kind='git',
                name='egg',
                url='file:///%s' % repository,
                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(
             ('.git', 'bar', 'foo'))
         CmdUpdate(develop)(develop.parser.parse_args(['up', 'egg']))
         assert set(os.listdir(os.path.join(src, 'egg'))) == set(
             ('.git', 'bar', 'foo'))
         assert log.method_calls == [
             ('info', ("Cloned 'egg' with git.", ), {}),
             ('info', ("Updated 'egg' with git.", ), {})
         ]
     finally:
         _log.__exit__()
    def testCheckoutWithTwoSubmodules(self, develop, mkgitrepo, src):
        """
            Tests the checkout of a module 'egg' with a submodule 'submodule_a'
            and a submodule 'submodule_b' in it.
        """
        from mr.developer.commands import CmdCheckout
        submodule_name = 'submodule_a'
        submodule = mkgitrepo(submodule_name)
        submodule_b_name = 'submodule_b'
        submodule_b = mkgitrepo(submodule_b_name)

        submodule.add_file('foo')
        submodule_b.add_file('foo_b')
        egg = mkgitrepo('egg')
        egg.add_file('bar')
        egg.add_submodule(submodule, submodule_name)
        egg.add_submodule(submodule_b, submodule_b_name)

        develop.sources = {
            'egg': Source(kind='git', name='egg', url=egg.url, path=src['egg'])
        }
        _log = patch('mr.developer.git.logger')
        log = _log.__enter__()
        try:
            CmdCheckout(develop)(develop.parser.parse_args(['co', 'egg']))
            assert set(os.listdir(src['egg'])) == set(
                ('submodule_a', 'submodule_b', '.git', 'bar', '.gitmodules'))
            assert set(os.listdir(src['egg/%s' % submodule_name])) == set(
                ('.git', 'foo'))
            assert set(os.listdir(src['egg/%s' % submodule_b_name])) == set(
                ('.git', 'foo_b'))
            assert log.method_calls == [
                ('info', ("Cloned 'egg' with git from '%s'." % egg.url, ), {}),
                ('info', ("Initialized 'egg' submodule at '%s' with git." %
                          submodule_name, ), {}),
                ('info', ("Initialized 'egg' submodule at '%s' with git." %
                          submodule_b_name, ), {})
            ]
        finally:
            _log.__exit__()
示例#16
0
    def testUpdateWithoutRevisionPin(self, develop, mkgitrepo, src, capsys):
        from mr.developer.commands import CmdCheckout
        from mr.developer.commands import CmdUpdate
        from mr.developer.commands import CmdStatus
        repository = mkgitrepo('repository')
        repository.add_file('foo')
        repository.add_file('bar')
        repository.add_branch('develop')
        develop.sources = {
            'egg':
            Source(kind='git', name='egg', url=repository.url, path=src['egg'])
        }
        _log = patch('mr.developer.git.logger')
        log = _log.__enter__()
        try:
            CmdCheckout(develop)(develop.parser.parse_args(['co', 'egg']))
            assert set(os.listdir(src['egg'])) == set(('.git', 'bar', 'foo'))
            captured = capsys.readouterr()
            assert captured.out.startswith(
                "Initialized empty Git repository in")
            CmdUpdate(develop)(develop.parser.parse_args(['up', 'egg']))
            assert set(os.listdir(src['egg'])) == set(('.git', 'bar', 'foo'))
            assert log.method_calls == [
                ('info',
                 ("Cloned 'egg' with git from '%s'." % repository.url, ), {}),
                ('info', ("Updated 'egg' with git.", ), {}),
                ('info',
                 ("Switching to remote branch 'remotes/origin/master'.", ), {})
            ]
            captured = capsys.readouterr()
            assert captured.out == ""
            CmdStatus(develop)(develop.parser.parse_args(['status', '-v']))
            captured = capsys.readouterr()
            assert captured.out == "~   A egg\n      ## master...origin/master\n\n"

        finally:
            _log.__exit__()
示例#17
0
    def testCheckoutWithSubmodulesOptionNever(self):
        """
            Tests the checkout of a module 'egg' with a submodule 'submodule_a' in it
            without initializing the submodule, restricted by global 'never'
        """

        from mr.developer.commands 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)

        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'))
        }
        _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()
            assert log.method_calls == [('info', ("Cloned 'egg' with git.", ),
                                         {})]
        finally:
            _log.__exit__()
示例#18
0
 def testUpdateWithoutRevisionPin(self, develop, src, tempdir):
     from mr.developer.commands import CmdCheckout
     from mr.developer.commands import CmdUpdate
     process = Process()
     repository = tempdir['repository']
     process.check_call("svnadmin create %s" % repository)
     checkout = tempdir['checkout']
     process.check_call(
         "svn checkout file://%s %s" % (repository, checkout),
         echo=False)
     foo = checkout['foo']
     foo.create_file('foo')
     process.check_call("svn add %s" % foo, echo=False)
     process.check_call("svn commit %s -m foo" % foo, echo=False)
     bar = checkout['bar']
     bar.create_file('bar')
     process.check_call("svn add %s" % bar, echo=False)
     process.check_call("svn commit %s -m bar" % bar, echo=False)
     develop.sources = {
         'egg': Source(
             kind='svn',
             name='egg',
             url='file://%s' % repository,
             path=src['egg'])}
     _log = patch('mr.developer.svn.logger')
     log = _log.__enter__()
     try:
         CmdCheckout(develop)(develop.parser.parse_args(['co', 'egg']))
         assert set(os.listdir(src['egg'])) == set(('.svn', 'bar', 'foo'))
         CmdUpdate(develop)(develop.parser.parse_args(['up', 'egg']))
         assert set(os.listdir(src['egg'])) == set(('.svn', 'bar', 'foo'))
         assert log.method_calls == [
             ('info', ("Checked out 'egg' with subversion.",), {}),
             ('info', ("Updated 'egg' with subversion.",), {})]
     finally:
         _log.__exit__()
示例#19
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']))
        """)
示例#20
0
    def testUpdateWithRevisionPin(self):
        from mr.developer.commands import CmdCheckout
        from mr.developer.commands import CmdUpdate
        from mr.developer.commands 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']))

        # switch implicitly to master branch
        develop.sources = {
            'egg':
            Source(kind='git',
                   name='egg',
                   url='%s' % repository,
                   path=os.path.join(src, 'egg'))
        }
        CmdUpdate(develop)(develop.parser.parse_args(['up', 'egg']))
        assert set(os.listdir(os.path.join(src, 'egg'))) == set(
            ('.git', 'bar', 'foo'))

        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']))
        """)
示例#21
0
    def testUpdateWithRevisionPin(self, develop, mkgitrepo, src):
        from mr.developer.commands import CmdCheckout
        from mr.developer.commands import CmdUpdate
        from mr.developer.commands import CmdStatus
        repository = mkgitrepo('repository')
        rev = self.createDefaultContent(repository)

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

        shutil.rmtree(src['egg'])

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

        # switch implicitly to master branch
        develop.sources = {
            'egg':
            Source(kind='git',
                   name='egg',
                   url='%s' % repository.base,
                   path=src['egg'])
        }
        CmdUpdate(develop)(develop.parser.parse_args(['up', 'egg']))
        assert set(os.listdir(src['egg'])) == set(('.git', 'bar', 'foo'))

        # Switch to specific revision, then switch back to master branch.
        develop.sources = {
            'egg':
            Source(kind='git',
                   name='egg',
                   rev=rev,
                   url='%s' % repository.base,
                   path=src['egg'])
        }
        CmdUpdate(develop)(develop.parser.parse_args(['up', 'egg']))
        assert set(os.listdir(src['egg'])) == set(('.git', 'foo', 'foo2'))
        develop.sources = {
            'egg':
            Source(kind='git',
                   name='egg',
                   url='%s' % repository.base,
                   path=src['egg'])
        }
        CmdUpdate(develop)(develop.parser.parse_args(['up', 'egg']))
        assert set(os.listdir(src['egg'])) == set(('.git', 'bar', 'foo'))

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

        # we can't use both rev and branch
        with pytest.raises(SystemExit):
            develop.sources = {
                'egg':
                Source(kind='git',
                       name='egg',
                       branch='test',
                       rev=rev,
                       url='%s' % repository.base,
                       path=src['egg-failed'])
            }
            CmdCheckout(develop)(develop.parser.parse_args(['co', 'egg']))
示例#22
0
    def testUpdateWithRevisionPin(self):
        from mr.developer.commands import CmdCheckout
        from mr.developer.commands import CmdUpdate
        from mr.developer.commands import CmdStatus
        repository = self.createRepo('repository')
        rev = self.createDefaultContent(repository)
        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']))

        # switch implicitly to master branch
        develop.sources = {
            'egg':
            Source(kind='git',
                   name='egg',
                   url='%s' % repository,
                   path=os.path.join(src, 'egg'))
        }
        CmdUpdate(develop)(develop.parser.parse_args(['up', 'egg']))
        assert set(os.listdir(os.path.join(src, 'egg'))) == set(
            ('.git', 'bar', 'foo'))

        # Switch to specific revision, then switch back to master branch.
        develop.sources = {
            'egg':
            Source(kind='git',
                   name='egg',
                   rev=rev,
                   url='%s' % repository,
                   path=os.path.join(src, 'egg'))
        }
        CmdUpdate(develop)(develop.parser.parse_args(['up', 'egg']))
        assert set(os.listdir(os.path.join(src, 'egg'))) == set(
            ('.git', 'foo', 'foo2'))
        develop.sources = {
            'egg':
            Source(kind='git',
                   name='egg',
                   url='%s' % repository,
                   path=os.path.join(src, 'egg'))
        }
        CmdUpdate(develop)(develop.parser.parse_args(['up', 'egg']))
        assert set(os.listdir(os.path.join(src, 'egg'))) == set(
            ('.git', 'bar', 'foo'))

        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']))
        """)
示例#23
0
    def testUpdateWithRevisionPin(self, develop, src, tempdir):
        from mr.developer.commands import CmdCheckout
        from mr.developer.commands import CmdUpdate
        repository = tempdir['repository']
        os.mkdir(repository)
        process = Process(cwd=repository)
        lines = process.check_call("hg init %s" % repository)
        foo = repository['foo']
        foo.create_file('foo')
        lines = process.check_call("hg add %s" % foo, echo=False)

        # create branch for testing
        lines = process.check_call("hg branch test", echo=False)

        lines = process.check_call("hg commit %s -m foo -u test" % foo,
                                   echo=False)

        # get comitted rev
        lines = process.check_call("hg log %s" % foo, echo=False)

        try:
            # XXX older version
            rev = lines[0].split()[1].split(b(':'))[1]
        except Exception:
            rev = lines[0].split()[1]

        # return to default branch
        lines = process.check_call("hg branch default", echo=False)

        bar = repository['bar']
        bar.create_file('bar')
        lines = process.check_call("hg add %s" % bar, echo=False)
        lines = process.check_call("hg commit %s -m bar -u test" % bar,
                                   echo=False)

        # 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
        with 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']))