Exemple #1
0
            # negatively cached value still raises
            with self.assertRaisesRegexp(RuntimeError, 'cache\.cachepath'):
                git_cache.Mirror.GetCachePath()
        finally:
            for name, val in zip(('GIT_CACHE_PATH', 'GIT_CONFIG'),
                                 (path, config)):
                if val is None:
                    os.environ.pop(name, None)
                else:
                    os.environ[name] = val


class MirrorTest(unittest.TestCase):
    def test_same_cache_for_authenticated_and_unauthenticated_urls(self):
        # GoB can fetch a repo via two different URLs; if the url contains '/a/'
        # it forces authenticated access instead of allowing anonymous access,
        # even in the case where a repo is public. We want this in order to make
        # sure bots are authenticated and get the right quotas. However, we
        # only want to maintain a single cache for the repo.
        self.assertEqual(
            git_cache.Mirror.UrlToCacheDir(
                'https://chromium.googlesource.com/a/chromium/src.git'),
            'chromium.googlesource.com-chromium-src')


if __name__ == '__main__':
    sys.exit(
        coverage_utils.covered_main(
            (os.path.join(DEPOT_TOOLS_ROOT, 'git_cache.py')),
            required_percentage=0))
Exemple #2
0
  """

    def testMakeWorkdir(self):
        if not hasattr(os, 'symlink'):
            return

        workdir = os.path.join(self._tempdir, 'workdir')
        self.gc.make_workdir(os.path.join(self.repo.repo_path, '.git'),
                             os.path.join(workdir, '.git'))
        EXPECTED_LINKS = [
            'config',
            'info',
            'hooks',
            'logs/refs',
            'objects',
            'refs',
        ]
        for path in EXPECTED_LINKS:
            self.assertTrue(os.path.islink(os.path.join(workdir, '.git',
                                                        path)))
            self.assertEqual(
                os.path.realpath(os.path.join(workdir, '.git', path)),
                os.path.join(self.repo.repo_path, '.git', path))
        self.assertFalse(os.path.islink(os.path.join(workdir, '.git', 'HEAD')))


if __name__ == '__main__':
    sys.exit(
        coverage_utils.covered_main(
            os.path.join(DEPOT_TOOLS_ROOT, 'git_common.py')))
    A B C D E F G M N O
                  M H I J K L
              F foobar1 foobar2
    """)

    output, _ = self.repo.capture_stdio(self.rp.main, ['--lkgr'])
    self.assertIn('to track lkgr [tag] (was tag_F [tag])', output)

    self.assertSchema("""
    A B C D E F G M N O
                  M H I J K L
                  M foobar1 foobar2
    """)

    output, _ = self.repo.capture_stdio(self.rp.main, ['--root'])
    self.assertIn('to track origin/master (was lkgr [tag])', output)

    self.assertSchema("""
    A B C D E F G M N O foobar1 foobar2
                  M H I J K L
    """)


if __name__ == '__main__':
  sys.exit(coverage_utils.covered_main((
    os.path.join(DEPOT_TOOLS_ROOT, 'git_rebase_update.py'),
    os.path.join(DEPOT_TOOLS_ROOT, 'git_new_branch.py'),
    os.path.join(DEPOT_TOOLS_ROOT, 'git_reparent_branch.py'),
    os.path.join(DEPOT_TOOLS_ROOT, 'git_rename_branch.py')
  )))
class GitMutableFunctionsTest(git_test_utils.GitRepoReadWriteTestBase,
                              GitCommonTestBase):
  REPO = ''

  def _intern_data(self, data):
    with tempfile.TemporaryFile() as f:
      f.write(data)
      f.seek(0)
      return self.repo.run(self.gc.intern_f, f)

  def testInternF(self):
    data = 'CoolBobcatsBro'
    data_hash = self._intern_data(data)
    self.assertEquals(git_test_utils.git_hash_data(data), data_hash)
    self.assertEquals(data, self.repo.git('cat-file', 'blob', data_hash).stdout)

  def testMkTree(self):
    tree = {}
    for i in 1, 2, 3:
      name = 'file%d' % i
      tree[name] = ('100644', 'blob', self._intern_data(name))
    tree_hash = self.repo.run(self.gc.mktree, tree)
    self.assertEquals('37b61866d6e061c4ba478e7eb525be7b5752737d', tree_hash)


if __name__ == '__main__':
  sys.exit(coverage_utils.covered_main(
    os.path.join(DEPOT_TOOLS_ROOT, 'git_common.py')
  ))
        },
    }

    def testTwoChangesWithAddedLines(self):
        """Regression test for https://crbug.com/709831.

    Tests a line with multiple ignored edits, and a line number change in
    between (such that the line number in the current revision is bigger than
    the file's line count at the older ignored revision).
    """
        expected_output = [
            self.blame_line('C', ' 1) '),
            self.blame_line('C', ' 2) '),
            self.blame_line('A', ' 3) red'),
            self.blame_line('A', '4*) yellow'),
        ]
        # Due to https://crbug.com/709831, ignoring both B and D would crash,
        # because of C (in between those revisions) which moves Line 2 to Line 4.
        # The algorithm would incorrectly think that Line 4 was still on Line 4 in
        # Commit B, even though it was Line 2 at that time. Its index is out of
        # range in the number of lines in Commit B.
        retval, output = self.run_hyperblame(['B', 'D'], 'file', 'tag_D')
        self.assertEqual(0, retval)
        self.assertEqual(expected_output, output)


if __name__ == '__main__':
    sys.exit(
        coverage_utils.covered_main(
            os.path.join(DEPOT_TOOLS_ROOT, 'git_hyper_blame.py')))
Exemple #6
0
    def testInProcessCache(self):
        self.assertEqual(
            None,
            self.repo.run(self.gn.get_num, binascii.unhexlify(self.repo['A'])))
        self.assertEqual([4], self._git_number([self.repo['E']]))
        self.assertEqual(
            0,
            self.repo.run(self.gn.get_num, binascii.unhexlify(self.repo['A'])))

    def testOnDiskCache(self):
        self.assertEqual(
            None,
            self.repo.run(self.gn.get_num, binascii.unhexlify(self.repo['A'])))
        self.assertEqual([4], self._git_number([self.repo['E']], cache=True))
        self.assertEqual([4], self._git_number([self.repo['E']], cache=True))
        self.gn.clear_caches()
        self.assertEqual(
            0,
            self.repo.run(self.gn.get_num, binascii.unhexlify(self.repo['A'])))
        self.gn.clear_caches()
        self.repo.run(self.gn.clear_caches, True)
        self.assertEqual(
            None,
            self.repo.run(self.gn.get_num, binascii.unhexlify(self.repo['A'])))


if __name__ == '__main__':
    sys.exit(
        coverage_utils.covered_main(
            os.path.join(DEPOT_TOOLS_ROOT, 'git_number.py'), '3.7'))
  def testIntraHunkLineMotion(self):
    """Tests a blame with line motion in the same hunk in the ignored commit."""
    # This test was mostly written as a demonstration of the limitations of the
    # current algorithm (it exhibits non-ideal behaviour).

    # Blame from E, ignoring E.
    # Line 6 was added by E (but ignored, so blame C).
    # Lines 7, 8 were modified by E (but ignored, so blame A).
    # TODO(mgiuca): Ideally, this would blame Line 7 on C, because the line
    # "red" was added by C, and this is just a small change to that line. But
    # the current algorithm can't deal with line motion within a hunk, so it
    # just assumes Line 7 in E ~= Line 7 in D == Line 3 in A (which was "blue").
    expected_output = [self.blame_line('D', ' 1) earth'),
                       self.blame_line('D', ' 2) fire'),
                       self.blame_line('C', ' 3) X'),
                       self.blame_line('C', ' 4) Y'),
                       self.blame_line('A', ' 5) A'),
                       self.blame_line('C', '6*) colors:'),
                       self.blame_line('A', '7*)  red'),
                       self.blame_line('A', '8*)  blue'),
                       self.blame_line('C', ' 9) Z'),
                       ]
    retval, output = self.run_hyperblame(['E'], 'file', 'tag_E')
    self.assertEqual(0, retval)
    self.assertEqual(expected_output, output)


if __name__ == '__main__':
  sys.exit(coverage_utils.covered_main(
    os.path.join(DEPOT_TOOLS_ROOT, 'git_hyper_blame.py')))
  def testInProcessCache(self):
    self.assertEqual(
        None,
        self.repo.run(self.gn.get_num, binascii.unhexlify(self.repo['A'])))
    self.assertEqual([4], self._git_number([self.repo['E']]))
    self.assertEqual(
        0,
        self.repo.run(self.gn.get_num, binascii.unhexlify(self.repo['A'])))

  def testOnDiskCache(self):
    self.assertEqual(
        None,
        self.repo.run(self.gn.get_num, binascii.unhexlify(self.repo['A'])))
    self.assertEqual([4], self._git_number([self.repo['E']], cache=True))
    self.assertEqual([4], self._git_number([self.repo['E']], cache=True))
    self.gn.clear_caches()
    self.assertEqual(
        0,
        self.repo.run(self.gn.get_num, binascii.unhexlify(self.repo['A'])))
    self.gn.clear_caches()
    self.repo.run(self.gn.clear_caches, True)
    self.assertEqual(
        None,
        self.repo.run(self.gn.get_num, binascii.unhexlify(self.repo['A'])))


if __name__ == '__main__':
  sys.exit(coverage_utils.covered_main(
    os.path.join(DEPOT_TOOLS_ROOT, 'git_number.py'),
    '3.7'
  ))
    A B C D E F G M N O
                  M H I J K L
              F foobar1 foobar2
    """)

    output, _ = self.repo.capture_stdio(self.rp.main, ['--lkgr'])
    self.assertIn('to track lkgr [tag] (was tag_F [tag])', output)

    self.assertSchema("""
    A B C D E F G M N O
                  M H I J K L
                  M foobar1 foobar2
    """)

    output, _ = self.repo.capture_stdio(self.rp.main, ['--root'])
    self.assertIn('to track origin/master (was lkgr [tag])', output)

    self.assertSchema("""
    A B C D E F G M N O foobar1 foobar2
                  M H I J K L
    """)


if __name__ == '__main__':
  sys.exit(coverage_utils.covered_main((
    os.path.join(DEPOT_TOOLS_ROOT, 'git_rebase_update.py'),
    os.path.join(DEPOT_TOOLS_ROOT, 'git_new_branch.py'),
    os.path.join(DEPOT_TOOLS_ROOT, 'git_reparent_branch.py'),
    os.path.join(DEPOT_TOOLS_ROOT, 'git_rename_branch.py')
  )))
        self.assertSchema(
            """
    A B C D E F G M N O
                  M H I J K L
                  M foobar1 foobar2
    """
        )

        output, _ = self.repo.capture_stdio(self.rp.main, ["--root"])
        self.assertIn("to track origin/master (was lkgr [tag])", output)

        self.assertSchema(
            """
    A B C D E F G M N O foobar1 foobar2
                  M H I J K L
    """
        )


if __name__ == "__main__":
    sys.exit(
        coverage_utils.covered_main(
            (
                os.path.join(DEPOT_TOOLS_ROOT, "git_rebase_update.py"),
                os.path.join(DEPOT_TOOLS_ROOT, "git_new_branch.py"),
                os.path.join(DEPOT_TOOLS_ROOT, "git_reparent_branch.py"),
                os.path.join(DEPOT_TOOLS_ROOT, "git_rename_branch.py"),
            )
        )
    )
        refs = map(binascii.unhexlify, refs)
        self.repo.run(self.gn.load_generation_numbers, refs)
        if cache:
            self.repo.run(self.gn.finalize, refs)
        return map(self.gn.get_num, refs)

    def testBasic(self):
        self.assertEqual([0], self._git_number([self.repo["A"]]))
        self.assertEqual([2], self._git_number([self.repo["F"]]))
        self.assertEqual([0], self._git_number([self.repo["X"]]))
        self.assertEqual([4], self._git_number([self.repo["E"]]))

    def testInProcessCache(self):
        self.assertEqual(None, self.repo.run(self.gn.get_num, binascii.unhexlify(self.repo["A"])))
        self.assertEqual([4], self._git_number([self.repo["E"]]))
        self.assertEqual(0, self.repo.run(self.gn.get_num, binascii.unhexlify(self.repo["A"])))

    def testOnDiskCache(self):
        self.assertEqual(None, self.repo.run(self.gn.get_num, binascii.unhexlify(self.repo["A"])))
        self.assertEqual([4], self._git_number([self.repo["E"]], cache=True))
        self.assertEqual([4], self._git_number([self.repo["E"]], cache=True))
        self.gn.clear_caches()
        self.assertEqual(0, self.repo.run(self.gn.get_num, binascii.unhexlify(self.repo["A"])))
        self.gn.clear_caches()
        self.repo.run(self.gn.clear_caches, True)
        self.assertEqual(None, self.repo.run(self.gn.get_num, binascii.unhexlify(self.repo["A"])))


if __name__ == "__main__":
    sys.exit(coverage_utils.covered_main(os.path.join(DEPOT_TOOLS_ROOT, "git_number.py"), "3.7"))
Exemple #12
0
    shutil.rmtree(cls.cache_dir, ignore_errors=True)

  def testParseFetchSpec(self):
    testData = [
        ([], []),
        (['master'], [('+refs/heads/master:refs/heads/master',
                       r'\+refs/heads/master:.*')]),
        (['master/'], [('+refs/heads/master:refs/heads/master',
                       r'\+refs/heads/master:.*')]),
        (['+master'], [('+refs/heads/master:refs/heads/master',
                       r'\+refs/heads/master:.*')]),
        (['refs/heads/*'], [('+refs/heads/*:refs/heads/*',
                            r'\+refs/heads/\*:.*')]),
        (['foo/bar/*', 'baz'], [('+refs/heads/foo/bar/*:refs/heads/foo/bar/*',
                                r'\+refs/heads/foo/bar/\*:.*'),
                               ('+refs/heads/baz:refs/heads/baz',
                                r'\+refs/heads/baz:.*')]),
        (['refs/foo/*:refs/bar/*'], [('+refs/foo/*:refs/bar/*',
                                      r'\+refs/foo/\*:.*')])
        ]

    mirror = git_cache.Mirror('test://phony.example.biz')
    for fetch_specs, expected in testData:
      mirror = git_cache.Mirror('test://phony.example.biz', refs=fetch_specs)
      self.assertItemsEqual(mirror.fetch_specs, expected)

if __name__ == '__main__':
  sys.exit(coverage_utils.covered_main((
    os.path.join(DEPOT_TOOLS_ROOT, 'git_cache.py')
  ), required_percentage=0))
      self.repo.git('add', 'some/files/file5')

      # Freeze group 1
      self.assertEquals(self.repo.git('status', '--porcelain').stdout, STATUS_1)
      self.assertIsNone(self.gc.freeze())
      self.assertEquals(self.repo.git('status', '--porcelain').stdout, '')

      # Freeze group 2
      with open('some/files/file2', 'a') as f2:
        print >> f2, 'new! appended line!'
      self.assertEquals(self.repo.git('status', '--porcelain').stdout,
                        ' M some/files/file2\n')
      self.assertIsNone(self.gc.freeze())
      self.assertEquals(self.repo.git('status', '--porcelain').stdout, '')

      # Thaw it out!
      self.assertIsNone(self.gc.thaw())
      self.assertIsNotNone(self.gc.thaw())  # One thaw should thaw everything

      self.assertEquals(self.repo.git('status', '--porcelain').stdout, STATUS_1)

    self.repo.run(inner)


if __name__ == '__main__':
  sys.exit(coverage_utils.covered_main(
    os.path.join(DEPOT_TOOLS_ROOT, 'git_common.py'),
    required_percentage=88.0
  ))