示例#1
0
    def testMultipleAndRemovedCheckouts(self):
        """Tests that multiple repository checkouts works, as well as removal of
    orphaned checkouts due to removal from the deps file.
    """
        self._BuildTestRepoPaths()
        os.mkdir(self._cache_dir)
        os.mkdir(self._output_dir)

        checkout_dir_rel2 = os.path.join('repo2', 'nested')
        checkout_dir_abs2 = os.path.join(self._output_dir, checkout_dir_rel2)

        # Create and write the deps file.
        deps_path = os.path.join(self.temp_dir(), 'gitdeps.txt')
        deps = {
            self._checkout_dir_rel: (self._dummy_repo_path, [], 'rev2'),
            checkout_dir_rel2: (self._dummy_repo_path, [], 'rev3')
        }
        _WriteDeps(deps, deps_path)

        # Run the script.
        self._RunScript(output_dir=self._output_dir,
                        deps_paths=[deps_path],
                        verbose=True)

        # Ensure the checkout was created as expected.
        self.assertTrue(os.path.isdir(self._cache_dir))
        self.assertEqual(2, _CountChildDirectories(self._cache_dir))
        self.assertTrue(os.path.isfile(self._junctions_path))
        self.assertTrue(os.path.isdir(self._checkout_dir_abs))
        # pylint: disable=W0212
        self.assertNotEqual(None,
                            gitdeps._GetJunctionInfo(self._checkout_dir_abs))
        self.assertTrue(os.path.isdir(checkout_dir_abs2))
        # pylint: disable=W0212
        self.assertNotEqual(None, gitdeps._GetJunctionInfo(checkout_dir_abs2))

        # Rewrite the deps file, removing the nested junction.
        deps = {
            self._checkout_dir_rel: (self._dummy_repo_path, [], 'rev2'),
        }
        _WriteDeps(deps, deps_path)

        # Run the script.
        self._RunScript(output_dir=self._output_dir,
                        deps_paths=[deps_path],
                        verbose=True)

        # Ensure the checkout was created as expected.
        self.assertTrue(os.path.isdir(self._cache_dir))
        self.assertEqual(1, _CountChildDirectories(self._cache_dir))
        self.assertTrue(os.path.isfile(self._junctions_path))
        self.assertTrue(os.path.isdir(self._checkout_dir_abs))
        self.assertNotEqual(None,
                            gitdeps._GetJunctionInfo(self._checkout_dir_abs))

        # repo2/nested shouldn't exist, but neither should repo2 (as the directory
        # is empty and should have been removed).
        self.assertFalse(os.path.exists(checkout_dir_abs2))
        self.assertFalse(os.path.exists(os.path.dirname(checkout_dir_abs2)))
示例#2
0
  def testMultipleAndRemovedCheckouts(self):
    """Tests that multiple repository checkouts works, as well as removal of
    orphaned checkouts due to removal from the deps file.
    """
    self._BuildTestRepoPaths()
    os.mkdir(self._cache_dir)
    os.mkdir(self._output_dir)

    checkout_dir_rel2 = os.path.join('repo2', 'nested')
    checkout_dir_abs2 = os.path.join(self._output_dir, checkout_dir_rel2)

    # Create and write the deps file.
    deps_path = os.path.join(self.temp_dir(), 'gitdeps.txt')
    deps = {
      self._checkout_dir_rel: (self._dummy_repo_path, [], 'rev2'),
      checkout_dir_rel2: (self._dummy_repo_path, [], 'rev3')
    }
    _WriteDeps(deps, deps_path)

    # Run the script.
    self._RunScript(output_dir=self._output_dir,
                    deps_paths=[deps_path],
                    verbose=True)

    # Ensure the checkout was created as expected.
    self.assertTrue(os.path.isdir(self._cache_dir))
    self.assertEqual(2, _CountChildDirectories(self._cache_dir))
    self.assertTrue(os.path.isfile(self._junctions_path))
    self.assertTrue(os.path.isdir(self._checkout_dir_abs))
    # pylint: disable=W0212
    self.assertNotEqual(None, gitdeps._GetJunctionInfo(self._checkout_dir_abs))
    self.assertTrue(os.path.isdir(checkout_dir_abs2))
    # pylint: disable=W0212
    self.assertNotEqual(None, gitdeps._GetJunctionInfo(checkout_dir_abs2))

    # Rewrite the deps file, removing the nested junction.
    deps = {
      self._checkout_dir_rel: (self._dummy_repo_path, [], 'rev2'),
    }
    _WriteDeps(deps, deps_path)

    # Run the script.
    self._RunScript(output_dir=self._output_dir,
                    deps_paths=[deps_path],
                    verbose=True)

    # Ensure the checkout was created as expected.
    self.assertTrue(os.path.isdir(self._cache_dir))
    self.assertEqual(1, _CountChildDirectories(self._cache_dir))
    self.assertTrue(os.path.isfile(self._junctions_path))
    self.assertTrue(os.path.isdir(self._checkout_dir_abs))
    self.assertNotEqual(None, gitdeps._GetJunctionInfo(self._checkout_dir_abs))

    # repo2/nested shouldn't exist, but neither should repo2 (as the directory
    # is empty and should have been removed).
    self.assertFalse(os.path.exists(checkout_dir_abs2))
    self.assertFalse(os.path.exists(os.path.dirname(checkout_dir_abs2)))
示例#3
0
  def _TestSuccessBasicCheckout(self,
                                create_cache_dir,
                                specify_output_dir,
                                specify_deps_file,
                                pull_full_repo):
    self._BuildTestRepoPaths()

    # Determine 'cwd' and 'output_dir' parameters.
    output_dir = None
    cwd = self._output_dir
    if specify_output_dir:
      output_dir = self._output_dir
      cwd = None

    # Determine the deps file path.
    deps_path = os.path.join(self.temp_dir(), 'gitdeps.txt')
    deps_paths = [deps_path]
    if not specify_deps_file:
      if not cwd:
        cwd = self.temp_dir()
      deps_path = os.path.join(cwd, 'GITDEPS')
      deps_paths = []

    # Create the directories.
    if create_cache_dir:
      os.mkdir(self._cache_dir)
    os.mkdir(self._output_dir)

    directories_to_checkout = [] if pull_full_repo else ['foo']

    # Create and write the deps file.
    deps = {
      self._checkout_dir_rel:
          (self._dummy_repo_path, directories_to_checkout, 'rev2')
    }
    _WriteDeps(deps, deps_path)

    # Run the script.
    self._RunScript(output_dir=output_dir,
                    deps_paths=deps_paths,
                    verbose=True,
                    cwd=cwd)

    # Ensure the checkout was created as expected.
    self.assertTrue(os.path.isdir(self._cache_dir))
    self.assertEqual(1, _CountChildDirectories(self._cache_dir))
    self.assertTrue(os.path.isfile(self._junctions_path))
    self.assertTrue(os.path.isdir(self._checkout_dir_abs))
    # pylint: disable=W0212

    if pull_full_repo:
      self.assertNotEqual(None,
                          gitdeps._GetJunctionInfo(self._checkout_dir_abs))
    else:
      for directory in directories_to_checkout:
        junction = os.path.join(self._checkout_dir_abs, directory)
        self.assertNotEqual(None, gitdeps._GetJunctionInfo(junction))
示例#4
0
    def _TestSuccessBasicCheckout(self, create_cache_dir, specify_output_dir,
                                  specify_deps_file, pull_full_repo):
        self._BuildTestRepoPaths()

        # Determine 'cwd' and 'output_dir' parameters.
        output_dir = None
        cwd = self._output_dir
        if specify_output_dir:
            output_dir = self._output_dir
            cwd = None

        # Determine the deps file path.
        deps_path = os.path.join(self.temp_dir(), 'gitdeps.txt')
        deps_paths = [deps_path]
        if not specify_deps_file:
            if not cwd:
                cwd = self.temp_dir()
            deps_path = os.path.join(cwd, 'GITDEPS')
            deps_paths = []

        # Create the directories.
        if create_cache_dir:
            os.mkdir(self._cache_dir)
        os.mkdir(self._output_dir)

        directories_to_checkout = [] if pull_full_repo else ['foo']

        # Create and write the deps file.
        deps = {
            self._checkout_dir_rel:
            (self._dummy_repo_path, directories_to_checkout, 'rev2')
        }
        _WriteDeps(deps, deps_path)

        # Run the script.
        self._RunScript(output_dir=output_dir,
                        deps_paths=deps_paths,
                        verbose=True,
                        cwd=cwd)

        # Ensure the checkout was created as expected.
        self.assertTrue(os.path.isdir(self._cache_dir))
        self.assertEqual(1, _CountChildDirectories(self._cache_dir))
        self.assertTrue(os.path.isfile(self._junctions_path))
        self.assertTrue(os.path.isdir(self._checkout_dir_abs))
        # pylint: disable=W0212

        if pull_full_repo:
            self.assertNotEqual(
                None, gitdeps._GetJunctionInfo(self._checkout_dir_abs))
        else:
            for directory in directories_to_checkout:
                junction = os.path.join(self._checkout_dir_abs, directory)
                self.assertNotEqual(None, gitdeps._GetJunctionInfo(junction))
示例#5
0
    def _TestSuccessCheckoutReuse(self, reuse_refspec):
        """A test that checks reuse of a cached repository by checking out a
    second time with a different refspec.
    """
        self._TestSuccessBasicCheckout(True, True, True, True)

        # Create and write the deps file.
        deps_path = os.path.join(self.temp_dir(), 'gitdeps.txt')
        deps = {
            self._checkout_dir_rel: (self._dummy_repo_path, [], reuse_refspec)
        }
        _WriteDeps(deps, deps_path)

        # Run the script.
        self._RunScript(output_dir=self._output_dir,
                        deps_paths=[deps_path],
                        verbose=True)

        # Ensure the checkout was created as expected.
        self.assertTrue(os.path.isdir(self._cache_dir))
        self.assertEqual(1, _CountChildDirectories(self._cache_dir))
        self.assertTrue(os.path.isfile(self._junctions_path))
        self.assertTrue(os.path.isdir(self._checkout_dir_abs))
        # pylint: disable=W0212
        self.assertNotEqual(None,
                            gitdeps._GetJunctionInfo(self._checkout_dir_abs))
示例#6
0
  def _TestSuccessCheckoutReuse(self, reuse_refspec):
    """A test that checks reuse of a cached repository by checking out a
    second time with a different refspec.
    """
    self._TestSuccessBasicCheckout(True, True, True, True)

    # Create and write the deps file.
    deps_path = os.path.join(self.temp_dir(), 'gitdeps.txt')
    deps = {
      self._checkout_dir_rel: (self._dummy_repo_path, [], reuse_refspec)
    }
    _WriteDeps(deps, deps_path)

    # Run the script.
    self._RunScript(output_dir=self._output_dir,
                    deps_paths=[deps_path],
                    verbose=True)

    # Ensure the checkout was created as expected.
    self.assertTrue(os.path.isdir(self._cache_dir))
    self.assertEqual(1, _CountChildDirectories(self._cache_dir))
    self.assertTrue(os.path.isfile(self._junctions_path))
    self.assertTrue(os.path.isdir(self._checkout_dir_abs))
    # pylint: disable=W0212
    self.assertNotEqual(None, gitdeps._GetJunctionInfo(self._checkout_dir_abs))