コード例 #1
0
  def testRunHooks(self):
    if not self.enabled:
      return
    self.gclient(['config', self.git_base + 'repo_1', '--name', 'src'])
    self.gclient(['sync', '--deps', 'mac'])
    tree = self.mangle_git_tree(('repo_1@2', 'src'),
                                ('repo_2@1', 'src/repo2'),
                                ('repo_3@2', 'src/repo2/repo_renamed'))
    tree['src/git_hooked1'] = 'git_hooked1'
    tree['src/git_hooked2'] = 'git_hooked2'
    self.assertTree(tree)

    os.remove(join(self.root_dir, 'src', 'git_hooked1'))
    os.remove(join(self.root_dir, 'src', 'git_hooked2'))
    # runhooks runs all hooks even if not matching by design.
    out = self.parseGclient(['runhooks', '--deps', 'mac'],
                            ['running', 'running'])
    self.assertEquals(1, len(out[0]))
    self.assertEquals(1, len(out[1]))
    tree = self.mangle_git_tree(('repo_1@2', 'src'),
                                ('repo_2@1', 'src/repo2'),
                                ('repo_3@2', 'src/repo2/repo_renamed'))
    tree['src/git_hooked1'] = 'git_hooked1'
    tree['src/git_hooked2'] = 'git_hooked2'
    self.assertTree(tree)
コード例 #2
0
    def testRunHooks(self):
        if not self.enabled:
            return
        self.gclient(['config', self.git_base + 'repo_1', '--name', 'src'])
        self.gclient(['sync', '--deps', 'mac'])
        tree = self.mangle_git_tree(('repo_1@2', 'src'),
                                    ('repo_2@1', 'src/repo2'),
                                    ('repo_3@2', 'src/repo2/repo_renamed'))
        tree['src/git_hooked1'] = 'git_hooked1'
        tree['src/git_hooked2'] = 'git_hooked2'
        self.assertTree(tree)

        os.remove(join(self.root_dir, 'src', 'git_hooked1'))
        os.remove(join(self.root_dir, 'src', 'git_hooked2'))
        # runhooks runs all hooks even if not matching by design.
        out = self.parseGclient(['runhooks', '--deps', 'mac'],
                                ['running', 'running'])
        self.assertEquals(1, len(out[0]))
        self.assertEquals(1, len(out[1]))
        tree = self.mangle_git_tree(('repo_1@2', 'src'),
                                    ('repo_2@1', 'src/repo2'),
                                    ('repo_3@2', 'src/repo2/repo_renamed'))
        tree['src/git_hooked1'] = 'git_hooked1'
        tree['src/git_hooked2'] = 'git_hooked2'
        self.assertTree(tree)
コード例 #3
0
 def testDifferentTopLevelDirectory(self):
   # Check that even if the .gclient file does not mention the directory src
   # itself, but it is included via dependencies, the .gclient file is used.
   self.gclient(['config', self.svn_base + 'trunk/src.DEPS'])
   deps = join(self.root_dir, 'src.DEPS')
   os.mkdir(deps)
   write(join(deps, 'DEPS'),
       'deps = { "src": "%strunk/src" }' % (self.svn_base))
   src = join(self.root_dir, 'src')
   os.mkdir(src)
   res = self.gclient(['status', '--jobs', '1'], src)
   self.checkBlock(res[0], [('running', deps), ('running', src)])
コード例 #4
0
 def testDifferentTopLevelDirectory(self):
   # Check that even if the .gclient file does not mention the directory src
   # itself, but it is included via dependencies, the .gclient file is used.
   self.gclient(['config', self.svn_base + 'trunk/src.DEPS'])
   deps = join(self.root_dir, 'src.DEPS')
   os.mkdir(deps)
   write(join(deps, 'DEPS'),
       'deps = { "src": "%strunk/src" }' % (self.svn_base))
   src = join(self.root_dir, 'src')
   os.mkdir(src)
   res = self.gclient(['status', '--jobs', '1'], src)
   self.checkBlock(res[0], [('running', deps), ('running', src)])
コード例 #5
0
    def testPreDepsHooks(self):
        if not self.enabled:
            return
        self.gclient(['config', self.git_base + 'repo_5', '--name', 'src'])
        expectation = [
            ('running', self.root_dir),  # pre-deps hook
        ]
        out = self.parseGclient([
            'sync', '--deps', 'mac', '--jobs=1', '--revision',
            'src@' + self.githash('repo_5', 2)
        ], expectation)
        self.assertEquals(2, len(out[0]))
        self.assertEquals('pre-deps hook', out[0][1])
        tree = self.mangle_git_tree(('repo_5@2', 'src'),
                                    ('repo_1@2', 'src/repo1'),
                                    ('repo_2@1', 'src/repo2'))
        tree['src/git_pre_deps_hooked'] = 'git_pre_deps_hooked'
        self.assertTree(tree)

        os.remove(join(self.root_dir, 'src', 'git_pre_deps_hooked'))

        # Pre-DEPS hooks don't run with runhooks.
        self.gclient(['runhooks', '--deps', 'mac'])
        tree = self.mangle_git_tree(('repo_5@2', 'src'),
                                    ('repo_1@2', 'src/repo1'),
                                    ('repo_2@1', 'src/repo2'))
        self.assertTree(tree)

        # Pre-DEPS hooks run when syncing with --nohooks.
        self.gclient([
            'sync', '--deps', 'mac', '--nohooks', '--revision',
            'src@' + self.githash('repo_5', 2)
        ])
        tree = self.mangle_git_tree(('repo_5@2', 'src'),
                                    ('repo_1@2', 'src/repo1'),
                                    ('repo_2@1', 'src/repo2'))
        tree['src/git_pre_deps_hooked'] = 'git_pre_deps_hooked'
        self.assertTree(tree)

        os.remove(join(self.root_dir, 'src', 'git_pre_deps_hooked'))

        # Pre-DEPS hooks don't run with --noprehooks
        self.gclient([
            'sync', '--deps', 'mac', '--noprehooks', '--revision',
            'src@' + self.githash('repo_5', 2)
        ])
        tree = self.mangle_git_tree(('repo_5@2', 'src'),
                                    ('repo_1@2', 'src/repo1'),
                                    ('repo_2@1', 'src/repo2'))
        self.assertTree(tree)
コード例 #6
0
  def testPreDepsHooks(self):
    if not self.enabled:
      return
    self.gclient(['config', self.git_base + 'repo_5', '--name', 'src'])
    expectation = [
        ('running', self.root_dir),                 # pre-deps hook
    ]
    out = self.parseGclient(['sync', '--deps', 'mac', '--jobs=1',
                             '--revision', 'src@' + self.githash('repo_5', 2)],
                            expectation)
    self.assertEquals(2, len(out[0]))
    self.assertEquals('pre-deps hook', out[0][1])
    tree = self.mangle_git_tree(('repo_5@2', 'src'),
                                ('repo_1@2', 'src/repo1'),
                                ('repo_2@1', 'src/repo2')
                                )
    tree['src/git_pre_deps_hooked'] = 'git_pre_deps_hooked'
    self.assertTree(tree)

    os.remove(join(self.root_dir, 'src', 'git_pre_deps_hooked'))

    # Pre-DEPS hooks don't run with runhooks.
    self.gclient(['runhooks', '--deps', 'mac'])
    tree = self.mangle_git_tree(('repo_5@2', 'src'),
                                ('repo_1@2', 'src/repo1'),
                                ('repo_2@1', 'src/repo2')
                                )
    self.assertTree(tree)

    # Pre-DEPS hooks run when syncing with --nohooks.
    self.gclient(['sync', '--deps', 'mac', '--nohooks',
                  '--revision', 'src@' + self.githash('repo_5', 2)])
    tree = self.mangle_git_tree(('repo_5@2', 'src'),
                                ('repo_1@2', 'src/repo1'),
                                ('repo_2@1', 'src/repo2')
                                )
    tree['src/git_pre_deps_hooked'] = 'git_pre_deps_hooked'
    self.assertTree(tree)

    os.remove(join(self.root_dir, 'src', 'git_pre_deps_hooked'))

    # Pre-DEPS hooks don't run with --noprehooks
    self.gclient(['sync', '--deps', 'mac', '--noprehooks',
                  '--revision', 'src@' + self.githash('repo_5', 2)])
    tree = self.mangle_git_tree(('repo_5@2', 'src'),
                                ('repo_1@2', 'src/repo1'),
                                ('repo_2@1', 'src/repo2')
                                )
    self.assertTree(tree)
コード例 #7
0
  def testSyncJobs(self):
    if not self.enabled:
      return
    self.gclient(['config', self.git_base + 'repo_1', '--name', 'src'])
    # Test unversioned checkout.
    self.parseGclient(
        ['sync', '--deps', 'mac', '--jobs', '8'],
        ['running', 'running'],
        untangle=True)
    # TODO(maruel): http://crosbug.com/3582 hooks run even if not matching, must
    # add sync parsing to get the list of updated files.
    tree = self.mangle_git_tree(('repo_1@2', 'src'),
                                ('repo_2@1', 'src/repo2'),
                                ('repo_3@2', 'src/repo2/repo_renamed'))
    tree['src/git_hooked1'] = 'git_hooked1'
    tree['src/git_hooked2'] = 'git_hooked2'
    self.assertTree(tree)

    # Manually remove git_hooked1 before synching to make sure it's not
    # recreated.
    os.remove(join(self.root_dir, 'src', 'git_hooked1'))

    # Test incremental versioned sync: sync backward.
    # Use --jobs 1 otherwise the order is not deterministic.
    self.parseGclient(
        ['sync', '--revision', 'src@' + self.githash('repo_1', 1),
          '--deps', 'mac', '--delete_unversioned_trees', '--jobs', '1'],
        ['deleting'],
        untangle=True)
    tree = self.mangle_git_tree(('repo_1@1', 'src'),
                                ('repo_2@2', 'src/repo2'),
                                ('repo_3@1', 'src/repo2/repo3'),
                                ('repo_4@2', 'src/repo4'))
    tree['src/git_hooked2'] = 'git_hooked2'
    tree['src/gclient.args'] = '\n'.join([
        '# Generated from \'DEPS\'',
        'false_var = false',
        'true_var = true',
        'str_var = "abc"',
    ])
    self.assertTree(tree)
    # Test incremental sync: delete-unversioned_trees isn't there.
    self.parseGclient(
        ['sync', '--deps', 'mac', '--jobs', '8'],
        ['running', 'running'],
        untangle=True)
    tree = self.mangle_git_tree(('repo_1@2', 'src'),
                                ('repo_2@1', 'src/repo2'),
                                ('repo_3@1', 'src/repo2/repo3'),
                                ('repo_3@2', 'src/repo2/repo_renamed'),
                                ('repo_4@2', 'src/repo4'))
    tree['src/git_hooked1'] = 'git_hooked1'
    tree['src/git_hooked2'] = 'git_hooked2'
    tree['src/gclient.args'] = '\n'.join([
        '# Generated from \'DEPS\'',
        'false_var = false',
        'true_var = true',
        'str_var = "abc"',
    ])
    self.assertTree(tree)
コード例 #8
0
 def testDifferentTopLevelDirectory(self):
     # Check that even if the .gclient file does not mention the directory src
     # itself, but it is included via dependencies, the .gclient file is used.
     self.gclient(['config', self.git_base + 'src.DEPS'])
     deps = join(self.root_dir, 'src.DEPS')
     os.mkdir(deps)
     subprocess2.check_output(['git', 'init'], cwd=deps)
     write(join(deps, 'DEPS'),
           'deps = { "src": "%ssrc" }' % (self.git_base))
     subprocess2.check_output(['git', 'add', 'DEPS'], cwd=deps)
     subprocess2.check_output(['git', 'commit', '-a', '-m', 'DEPS file'],
                              cwd=deps)
     src = join(self.root_dir, 'src')
     os.mkdir(src)
     subprocess2.check_output(['git', 'init'], cwd=src)
     res = self.gclient(['status', '--jobs', '1', '-v'], src)
     self.checkBlock(res[0], [('running', deps), ('running', src)])
コード例 #9
0
    def testSyncNoHistory(self):
        # Create an extra commit in repo_2 and point DEPS to its hash.
        cur_deps = self.FAKE_REPOS.git_hashes['repo_1'][-1][1]['DEPS']
        repo_2_hash_old = self.FAKE_REPOS.git_hashes['repo_2'][1][0][:7]
        self.FAKE_REPOS._commit_git('repo_2', {  # pylint: disable=protected-access
          'last_file': 'file created in last commit',
        })
        repo_2_hash_new = self.FAKE_REPOS.git_hashes['repo_2'][-1][0]
        new_deps = cur_deps.replace(repo_2_hash_old, repo_2_hash_new)
        self.assertNotEqual(new_deps, cur_deps)
        self.FAKE_REPOS._commit_git('repo_1', {  # pylint: disable=protected-access
          'DEPS': new_deps,
          'origin': 'git/repo_1@4\n',
        })

        config_template = ''.join([
            'solutions = [{'
            '  "name"        : "src",'
            '  "url"         : %(git_base)r + "repo_1",'
            '  "deps_file"   : "DEPS",'
            '  "managed"     : True,'
            '}]'
        ])

        self.gclient([
            'config', '--spec', config_template % {
                'git_base': self.git_base
            }
        ])

        self.gclient(['sync', '--no-history', '--deps', 'mac'])
        repo2_root = join(self.root_dir, 'src', 'repo2')

        # Check that repo_2 is actually shallow and its log has only one entry.
        rev_lists = subprocess2.check_output(['git', 'rev-list', 'HEAD'],
                                             cwd=repo2_root).decode('utf-8')
        self.assertEqual(repo_2_hash_new, rev_lists.strip('\r\n'))

        # Check that we have actually checked out the right commit.
        self.assertTrue(os.path.exists(join(repo2_root, 'last_file')))
コード例 #10
0
  def testSyncNoHistory(self):
    if not self.enabled:
      return
    # Create an extra commit in repo_2 and point DEPS to its hash.
    cur_deps = self.FAKE_REPOS.git_hashes['repo_1'][-1][1]['DEPS']
    repo_2_hash_old = self.FAKE_REPOS.git_hashes['repo_2'][1][0][:7]
    self.FAKE_REPOS._commit_git('repo_2', {  # pylint: disable=W0212
      'last_file': 'file created in last commit',
    })
    repo_2_hash_new = self.FAKE_REPOS.git_hashes['repo_2'][-1][0]
    new_deps = cur_deps.replace(repo_2_hash_old, repo_2_hash_new)
    self.assertNotEqual(new_deps, cur_deps)
    self.FAKE_REPOS._commit_git('repo_1', {  # pylint: disable=W0212
      'DEPS': new_deps,
      'origin': 'git/repo_1@4\n',
    })

    config_template = (
"""solutions = [{
"name"        : "src",
"url"         : "%(git_base)srepo_1",
"deps_file"   : "DEPS",
"managed"     : True,
}]""")

    self.gclient(['config', '--spec', config_template % {
      'git_base': self.git_base
    }])

    self.gclient(['sync', '--no-history', '--deps', 'mac'])
    repo2_root = join(self.root_dir, 'src', 'repo2')

    # Check that repo_2 is actually shallow and its log has only one entry.
    rev_lists = subprocess2.check_output(['git', 'rev-list', 'HEAD'],
                                         cwd=repo2_root)
    self.assertEquals(repo_2_hash_new, rev_lists.strip('\r\n'))

    # Check that we have actually checked out the right commit.
    self.assertTrue(os.path.exists(join(repo2_root, 'last_file')))
コード例 #11
0
  def testSyncJobs(self):
    if not self.enabled:
      return
    # TODO(maruel): safesync.
    self.gclient(['config', self.git_base + 'repo_1', '--name', 'src'])
    # Test unversioned checkout.
    self.parseGclient(
        ['sync', '--deps', 'mac', '--jobs', '8'],
        ['running', 'running'],
        untangle=True)
    # TODO(maruel): http://crosbug.com/3582 hooks run even if not matching, must
    # add sync parsing to get the list of updated files.
    tree = self.mangle_git_tree(('repo_1@2', 'src'),
                                ('repo_2@1', 'src/repo2'),
                                ('repo_3@2', 'src/repo2/repo_renamed'))
    tree['src/git_hooked1'] = 'git_hooked1'
    tree['src/git_hooked2'] = 'git_hooked2'
    self.assertTree(tree)

    # Manually remove git_hooked1 before synching to make sure it's not
    # recreated.
    os.remove(join(self.root_dir, 'src', 'git_hooked1'))

    # Test incremental versioned sync: sync backward.
    # Use --jobs 1 otherwise the order is not deterministic.
    self.parseGclient(
        ['sync', '--revision', 'src@' + self.githash('repo_1', 1),
          '--deps', 'mac', '--delete_unversioned_trees', '--jobs', '1'],
        ['deleting'],
        untangle=True)
    tree = self.mangle_git_tree(('repo_1@1', 'src'),
                                ('repo_2@2', 'src/repo2'),
                                ('repo_3@1', 'src/repo2/repo3'),
                                ('repo_4@2', 'src/repo4'))
    tree['src/git_hooked2'] = 'git_hooked2'
    self.assertTree(tree)
    # Test incremental sync: delete-unversioned_trees isn't there.
    self.parseGclient(
        ['sync', '--deps', 'mac', '--jobs', '8'],
        ['running', 'running'],
        untangle=True)
    tree = self.mangle_git_tree(('repo_1@2', 'src'),
                                ('repo_2@1', 'src/repo2'),
                                ('repo_3@1', 'src/repo2/repo3'),
                                ('repo_3@2', 'src/repo2/repo_renamed'),
                                ('repo_4@2', 'src/repo4'))
    tree['src/git_hooked1'] = 'git_hooked1'
    tree['src/git_hooked2'] = 'git_hooked2'
    self.assertTree(tree)
コード例 #12
0
  def testSync(self):
    if not self.enabled:
      return
    # TODO(maruel): safesync.
    self.gclient(['config', self.git_base + 'repo_1', '--name', 'src'])
    # Test unversioned checkout.
    self.parseGclient(
        ['sync', '--deps', 'mac', '--jobs', '1'],
        ['running', 'running'])
    # TODO(maruel): http://crosbug.com/3582 hooks run even if not matching, must
    # add sync parsing to get the list of updated files.
    tree = self.mangle_git_tree(('repo_1@2', 'src'),
                                ('repo_2@1', 'src/repo2'),
                                ('repo_3@2', 'src/repo2/repo_renamed'))
    tree['src/git_hooked1'] = 'git_hooked1'
    tree['src/git_hooked2'] = 'git_hooked2'
    self.assertTree(tree)

    # Manually remove git_hooked1 before synching to make sure it's not
    # recreated.
    os.remove(join(self.root_dir, 'src', 'git_hooked1'))

    # Test incremental versioned sync: sync backward.
    self.parseGclient(
        ['sync', '--jobs', '1', '--revision',
        'src@' + self.githash('repo_1', 1),
        '--deps', 'mac', '--delete_unversioned_trees'],
        ['deleting'])
    tree = self.mangle_git_tree(('repo_1@1', 'src'),
                                ('repo_2@2', 'src/repo2'),
                                ('repo_3@1', 'src/repo2/repo3'),
                                ('repo_4@2', 'src/repo4'))
    tree['src/git_hooked2'] = 'git_hooked2'
    self.assertTree(tree)
    # Test incremental sync: delete-unversioned_trees isn't there.
    self.parseGclient(
        ['sync', '--deps', 'mac', '--jobs', '1'],
        ['running', 'running'])
    tree = self.mangle_git_tree(('repo_1@2', 'src'),
                                ('repo_2@1', 'src/repo2'),
                                ('repo_3@1', 'src/repo2/repo3'),
                                ('repo_3@2', 'src/repo2/repo_renamed'),
                                ('repo_4@2', 'src/repo4'))
    tree['src/git_hooked1'] = 'git_hooked1'
    tree['src/git_hooked2'] = 'git_hooked2'
    self.assertTree(tree)
コード例 #13
0
 def CheckStatusPreMergePoint(self):
   self.assertEqual(gclient_scm.GIT.Capture(['config', 'remote.origin.url'],
                                            self.blink), self.blink_git_url)
   self.assertTrue(os.path.exists(join(self.blink, '.git')))
   self.assertTrue(os.path.exists(join(self.blink, 'OWNERS')))
   with open(join(self.blink, 'OWNERS')) as f:
     owners_content = f.read()
     self.assertEqual('OWNERS-pre', owners_content, 'OWNERS not updated')
   self.assertTrue(os.path.exists(join(self.blink, 'Source', 'exists_always')))
   self.assertTrue(os.path.exists(
       join(self.blink, 'Source', 'exists_before_but_not_after')))
   self.assertFalse(os.path.exists(
       join(self.blink, 'Source', 'exists_after_but_not_before')))
コード例 #14
0
 def CheckStatusPreMergePoint(self):
   self.assertEqual(gclient_scm.GIT.Capture(['config', 'remote.origin.url'],
                                            self.blink), self.blink_git_url)
   self.assertTrue(os.path.exists(join(self.blink, '.git')))
   self.assertTrue(os.path.exists(join(self.blink, 'OWNERS')))
   with open(join(self.blink, 'OWNERS')) as f:
     owners_content = f.read()
     self.assertEqual('OWNERS-pre', owners_content, 'OWNERS not updated')
   self.assertTrue(os.path.exists(join(self.blink, 'Source', 'exists_always')))
   self.assertTrue(os.path.exists(
       join(self.blink, 'Source', 'exists_before_but_not_after')))
   self.assertFalse(os.path.exists(
       join(self.blink, 'Source', 'exists_after_but_not_before')))
コード例 #15
0
 def CheckStatusPostMergePoint(self):
   # Check that the contents still exists
   self.assertTrue(os.path.exists(join(self.blink, 'OWNERS')))
   with open(join(self.blink, 'OWNERS')) as f:
     owners_content = f.read()
     self.assertEqual('OWNERS-post', owners_content, 'OWNERS not updated')
   self.assertTrue(os.path.exists(join(self.blink, 'Source', 'exists_always')))
   # Check that file removed between the branch point are actually deleted.
   self.assertTrue(os.path.exists(
       join(self.blink, 'Source', 'exists_after_but_not_before')))
   self.assertFalse(os.path.exists(
       join(self.blink, 'Source', 'exists_before_but_not_after')))
   # But not the .git folder
   self.assertFalse(os.path.exists(join(self.blink, '.git')))
コード例 #16
0
 def CheckStatusPostMergePoint(self):
   # Check that the contents still exists
   self.assertTrue(os.path.exists(join(self.blink, 'OWNERS')))
   with open(join(self.blink, 'OWNERS')) as f:
     owners_content = f.read()
     self.assertEqual('OWNERS-post', owners_content, 'OWNERS not updated')
   self.assertTrue(os.path.exists(join(self.blink, 'Source', 'exists_always')))
   # Check that file removed between the branch point are actually deleted.
   self.assertTrue(os.path.exists(
       join(self.blink, 'Source', 'exists_after_but_not_before')))
   self.assertFalse(os.path.exists(
       join(self.blink, 'Source', 'exists_before_but_not_after')))
   # But not the .git folder
   self.assertFalse(os.path.exists(join(self.blink, '.git')))
コード例 #17
0
    def testConfig(self):
        # Get any bootstrapping out of the way.
        results = self.gclient(['version'])

        p = join(self.root_dir, '.gclient')

        def test(cmd, expected):
            if os.path.exists(p):
                os.remove(p)
            results = self.gclient(cmd)
            self.check(('', '', 0), results)
            mode = 'r' if sys.version_info.major == 3 else 'rU'
            with open(p, mode) as f:
                actual = {}
                exec(f.read(), {}, actual)
                self.assertEqual(expected, actual)

        test(
            ['config', self.git_base + 'src/'], {
                'solutions': [{
                    'name': 'src',
                    'url': self.git_base + 'src',
                    'deps_file': 'DEPS',
                    'managed': True,
                    'custom_deps': {},
                    'custom_vars': {},
                }],
            })

        test(
            [
                'config', self.git_base + 'repo_1', '--name', 'src',
                '--cache-dir', 'none'
            ], {
                'solutions': [{
                    'name': 'src',
                    'url': self.git_base + 'repo_1',
                    'deps_file': 'DEPS',
                    'managed': True,
                    'custom_deps': {},
                    'custom_vars': {},
                }],
                'cache_dir':
                None
            })

        test(
            [
                'config', 'https://example.com/foo', 'faa', '--cache-dir',
                'something'
            ], {
                'solutions': [{
                    'name': 'foo',
                    'url': 'https://example.com/foo',
                    'deps_file': 'DEPS',
                    'managed': True,
                    'custom_deps': {},
                    'custom_vars': {},
                }],
                'cache_dir':
                'something'
            })

        test(
            ['config', 'https://example.com/foo', '--deps', 'blah'], {
                'solutions': [{
                    'name': 'foo',
                    'url': 'https://example.com/foo',
                    'deps_file': 'blah',
                    'managed': True,
                    'custom_deps': {},
                    'custom_vars': {},
                }]
            })

        test(
            [
                'config', self.git_base + 'src/', '--custom-var',
                'bool_var=True', '--custom-var', 'str_var="abc"'
            ], {
                'solutions': [{
                    'name': 'src',
                    'url': self.git_base + 'src',
                    'deps_file': 'DEPS',
                    'managed': True,
                    'custom_deps': {},
                    'custom_vars': {
                        'bool_var': True,
                        'str_var': 'abc',
                    },
                }]
            })

        test(['config', '--spec', 'bah = ["blah blah"]'],
             {'bah': ["blah blah"]})

        os.remove(p)
        results = self.gclient(['config', 'foo', 'faa', 'fuu'], error_ok=True)
        err = (
            'Usage: gclient.py config [options] [url]\n\n'
            'gclient.py: error: Inconsistent arguments. Use either --spec or one'
            ' or 2 args\n')
        self.check(('', err, 2), results)
        self.assertFalse(os.path.exists(join(self.root_dir, '.gclient')))
コード例 #18
0
    def testConfig(self):
        p = join(self.root_dir, '.gclient')

        def test(cmd, expected):
            if os.path.exists(p):
                os.remove(p)
            results = self.gclient(cmd)
            self.check(('', '', 0), results)
            self.checkString(expected, open(p, 'rU').read())

        test(['config', self.git_base + 'src/'],
             ('solutions = [\n'
              '  { "name"        : "src",\n'
              '    "url"         : "%ssrc",\n'
              '    "deps_file"   : "DEPS",\n'
              '    "managed"     : True,\n'
              '    "custom_deps" : {\n'
              '    },\n'
              '  },\n'
              ']\n'
              'cache_dir = None\n') % self.git_base)

        test(['config', self.git_base + 'repo_1', '--name', 'src'],
             ('solutions = [\n'
              '  { "name"        : "src",\n'
              '    "url"         : "%srepo_1",\n'
              '    "deps_file"   : "DEPS",\n'
              '    "managed"     : True,\n'
              '    "custom_deps" : {\n'
              '    },\n'
              '  },\n'
              ']\n'
              'cache_dir = None\n') % self.git_base)

        test(['config', 'foo', 'faa'], 'solutions = [\n'
             '  { "name"        : "foo",\n'
             '    "url"         : "foo",\n'
             '    "deps_file"   : "DEPS",\n'
             '    "managed"     : True,\n'
             '    "custom_deps" : {\n'
             '    },\n'
             '  },\n'
             ']\n'
             'cache_dir = None\n')

        test(['config', 'foo', '--deps', 'blah'], 'solutions = [\n'
             '  { "name"        : "foo",\n'
             '    "url"         : "foo",\n'
             '    "deps_file"   : "blah",\n'
             '    "managed"     : True,\n'
             '    "custom_deps" : {\n'
             '    },\n'
             '  },\n'
             ']\n'
             'cache_dir = None\n')

        test(['config', '--spec', '["blah blah"]'], '["blah blah"]')

        os.remove(p)
        results = self.gclient(['config', 'foo', 'faa', 'fuu'])
        err = (
            'Usage: gclient.py config [options] [url]\n\n'
            'gclient.py: error: Inconsistent arguments. Use either --spec or one'
            ' or 2 args\n')
        self.check(('', err, 2), results)
        self.assertFalse(os.path.exists(join(self.root_dir, '.gclient')))
コード例 #19
0
  def testConfig(self):
    p = join(self.root_dir, '.gclient')
    def test(cmd, expected):
      if os.path.exists(p):
        os.remove(p)
      results = self.gclient(cmd)
      self.check(('', '', 0), results)
      self.checkString(expected, open(p, 'rU').read())

    test(['config', self.svn_base + 'trunk/src/'],
         ('solutions = [\n'
          '  { "name"        : "src",\n'
          '    "url"         : "%strunk/src",\n'
          '    "deps_file"   : "DEPS",\n'
          '    "managed"     : True,\n'
          '    "custom_deps" : {\n'
          '    },\n'
          '    "safesync_url": "",\n'
          '  },\n'
          ']\n'
          'cache_dir = None\n') % self.svn_base)

    test(['config', self.git_base + 'repo_1', '--name', 'src'],
         ('solutions = [\n'
          '  { "name"        : "src",\n'
          '    "url"         : "%srepo_1",\n'
          '    "deps_file"   : "DEPS",\n'
          '    "managed"     : True,\n'
          '    "custom_deps" : {\n'
          '    },\n'
          '    "safesync_url": "",\n'
          '  },\n'
          ']\n'
          'cache_dir = None\n') % self.git_base)

    test(['config', 'foo', 'faa'],
         'solutions = [\n'
         '  { "name"        : "foo",\n'
         '    "url"         : "foo",\n'
         '    "deps_file"   : "DEPS",\n'
          '    "managed"     : True,\n'
         '    "custom_deps" : {\n'
         '    },\n'
         '    "safesync_url": "faa",\n'
         '  },\n'
         ']\n'
         'cache_dir = None\n')

    test(['config', 'foo', '--deps', 'blah'],
         'solutions = [\n'
         '  { "name"        : "foo",\n'
         '    "url"         : "foo",\n'
         '    "deps_file"   : "blah",\n'
         '    "managed"     : True,\n'
         '    "custom_deps" : {\n'
         '    },\n'
          '    "safesync_url": "",\n'
         '  },\n'
         ']\n'
         'cache_dir = None\n')

    test(['config', '--spec', '["blah blah"]'], '["blah blah"]')

    os.remove(p)
    results = self.gclient(['config', 'foo', 'faa', 'fuu'])
    err = ('Usage: gclient.py config [options] [url] [safesync url]\n\n'
           'gclient.py: error: Inconsistent arguments. Use either --spec or one'
           ' or 2 args\n')
    self.check(('', err, 2), results)
    self.assertFalse(os.path.exists(join(self.root_dir, '.gclient')))
コード例 #20
0
    def testRevertAndStatus(self):
        # Commit new change to repo to make repo_2's hash use a custom_var.
        cur_deps = self.FAKE_REPOS.git_hashes['repo_1'][-1][1]['DEPS']
        repo_2_hash = self.FAKE_REPOS.git_hashes['repo_2'][1][0][:7]
        new_deps = cur_deps.replace('repo_2@%s\'' % repo_2_hash,
                                    'repo_2@\' + Var(\'r2hash\')')
        new_deps = 'vars = {\'r2hash\': \'%s\'}\n%s' % (repo_2_hash, new_deps)
        self.FAKE_REPOS._commit_git('repo_1', {  # pylint: disable=protected-access
          'DEPS': new_deps,
          'origin': 'git/repo_1@3\n',
        })

        config_template = ''.join([
            'solutions = [{'
            '  "name"        : "src",'
            '  "url"         : %(git_base)r + "repo_1",'
            '  "deps_file"   : "DEPS",'
            '  "managed"     : True,'
            '  "custom_vars" : %(custom_vars)s,'
            '}]'
        ])

        self.gclient([
            'config', '--spec', config_template % {
                'git_base': self.git_base,
                'custom_vars': {}
            }
        ])

        # Tested in testSync.
        self.gclient(['sync', '--deps', 'mac'])
        write(join(self.root_dir, 'src', 'repo2', 'hi'), 'Hey!')

        out = self.parseGclient(['status', '--deps', 'mac', '--jobs', '1'], [])
        # TODO(maruel): http://crosbug.com/3584 It should output the unversioned
        # files.
        self.assertEqual(0, len(out))

        # Revert implies --force implies running hooks without looking at pattern
        # matching. For each expected path, 'git reset' and 'git clean' are run, so
        # there should be two results for each. The last two results should reflect
        # writing git_hooked1 and git_hooked2. There's only one result for the third
        # because it is clean and has no output for 'git clean'.
        out = self.parseGclient(['revert', '--deps', 'mac', '--jobs', '1'],
                                ['running', 'running'])
        self.assertEqual(2, len(out))
        tree = self.mangle_git_tree(('repo_1@3', 'src'),
                                    ('repo_2@1', 'src/repo2'),
                                    ('repo_3@2', 'src/repo2/repo_renamed'))
        tree['src/git_hooked1'] = 'git_hooked1'
        tree['src/git_hooked2'] = 'git_hooked2'
        self.assertTree(tree)

        # Make a new commit object in the origin repo, to force reset to fetch.
        self.FAKE_REPOS._commit_git('repo_2', {  # pylint: disable=protected-access
          'origin': 'git/repo_2@3\n',
        })

        self.gclient([
            'config', '--spec', config_template % {
                'git_base': self.git_base,
                'custom_vars': {
                    'r2hash': self.FAKE_REPOS.git_hashes['repo_2'][-1][0]
                }
            }
        ])
        out = self.parseGclient(['revert', '--deps', 'mac', '--jobs', '1'],
                                ['running', 'running'])
        self.assertEqual(2, len(out))
        tree = self.mangle_git_tree(('repo_1@3', 'src'),
                                    ('repo_2@3', 'src/repo2'),
                                    ('repo_3@2', 'src/repo2/repo_renamed'))
        tree['src/git_hooked1'] = 'git_hooked1'
        tree['src/git_hooked2'] = 'git_hooked2'
        self.assertTree(tree)

        results = self.gclient(['status', '--deps', 'mac', '--jobs', '1'])
        out = results[0].splitlines(False)
        # TODO(maruel): http://crosbug.com/3584 It should output the unversioned
        # files.
        self.assertEqual(0, len(out))
コード例 #21
0
  def testRevertAndStatus(self):
    if not self.enabled:
      return

    # Commit new change to repo to make repo_2's hash use a custom_var.
    cur_deps = self.FAKE_REPOS.git_hashes['repo_1'][-1][1]['DEPS']
    repo_2_hash = self.FAKE_REPOS.git_hashes['repo_2'][1][0][:7]
    new_deps = cur_deps.replace('repo_2@%s\'' % repo_2_hash,
                                'repo_2@\' + Var(\'r2hash\')')
    new_deps = 'vars = {\'r2hash\': \'%s\'}\n%s' % (repo_2_hash, new_deps)
    self.FAKE_REPOS._commit_git('repo_1', {  # pylint: disable=W0212
      'DEPS': new_deps,
      'origin': 'git/repo_1@3\n',
    })

    config_template = (
"""solutions = [{
  "name"        : "src",
  "url"         : "%(git_base)srepo_1",
  "deps_file"   : "DEPS",
  "managed"     : True,
  "custom_vars" : %(custom_vars)s,
}]""")

    self.gclient(['config', '--spec', config_template % {
      'git_base': self.git_base,
      'custom_vars': {}
    }])

    # Tested in testSync.
    self.gclient(['sync', '--deps', 'mac'])
    write(join(self.root_dir, 'src', 'repo2', 'hi'), 'Hey!')

    out = self.parseGclient(['status', '--deps', 'mac', '--jobs', '1'], [])
    # TODO(maruel): http://crosbug.com/3584 It should output the unversioned
    # files.
    self.assertEquals(0, len(out))

    # Revert implies --force implies running hooks without looking at pattern
    # matching. For each expected path, 'git reset' and 'git clean' are run, so
    # there should be two results for each. The last two results should reflect
    # writing git_hooked1 and git_hooked2. There's only one result for the third
    # because it is clean and has no output for 'git clean'.
    out = self.parseGclient(['revert', '--deps', 'mac', '--jobs', '1'],
                            ['running', 'running'])
    self.assertEquals(2, len(out))
    tree = self.mangle_git_tree(('repo_1@3', 'src'),
                                ('repo_2@1', 'src/repo2'),
                                ('repo_3@2', 'src/repo2/repo_renamed'))
    tree['src/git_hooked1'] = 'git_hooked1'
    tree['src/git_hooked2'] = 'git_hooked2'
    self.assertTree(tree)

    # Make a new commit object in the origin repo, to force reset to fetch.
    self.FAKE_REPOS._commit_git('repo_2', {  # pylint: disable=W0212
      'origin': 'git/repo_2@3\n',
    })

    self.gclient(['config', '--spec', config_template % {
      'git_base': self.git_base,
      'custom_vars': {'r2hash': self.FAKE_REPOS.git_hashes['repo_2'][-1][0] }
    }])
    out = self.parseGclient(['revert', '--deps', 'mac', '--jobs', '1'],
                            ['running', 'running'])
    self.assertEquals(2, len(out))
    tree = self.mangle_git_tree(('repo_1@3', 'src'),
                                ('repo_2@3', 'src/repo2'),
                                ('repo_3@2', 'src/repo2/repo_renamed'))
    tree['src/git_hooked1'] = 'git_hooked1'
    tree['src/git_hooked2'] = 'git_hooked2'
    self.assertTree(tree)

    results = self.gclient(['status', '--deps', 'mac', '--jobs', '1'])
    out = results[0].splitlines(False)
    # TODO(maruel): http://crosbug.com/3584 It should output the unversioned
    # files.
    self.assertEquals(0, len(out))