예제 #1
0
 def test_export_master(self):
     url = self.remote_path
     client = GitClient(self.local_path)
     subclient = GitClient(self.sublocal_path)
     subsubclient = GitClient(self.subsublocal_path)
     self.assertFalse(client.path_exists())
     self.assertFalse(client.detect_presence())
     self.assertFalse(os.path.exists(self.export_path))
     self.assertTrue(client.checkout(url))
     self.assertTrue(client.path_exists())
     self.assertTrue(subclient.path_exists())
     self.assertTrue(subsubclient.path_exists())
     tarpath = client.export_repository("master", self.export_path)
     self.assertEqual(tarpath, self.export_path + '.tar.gz')
     os.mkdir(self.export_path)
     with closing(tarfile.open(tarpath, "r:gz")) as tarf:
         tarf.extractall(self.export_path)
     subsubdirdiff = filecmp.dircmp(self.subsubexport_path, self.subsublocal_path, ignore=['.git', '.gitmodules'])
     self.assertEqual(subsubdirdiff.left_only, [])
     self.assertEqual(subsubdirdiff.right_only, [])
     self.assertEqual(subsubdirdiff.diff_files, [])
     subdirdiff = filecmp.dircmp(self.subexport_path, self.sublocal_path, ignore=['.git', '.gitmodules'])
     self.assertEqual(subdirdiff.left_only, [])
     self.assertEqual(subdirdiff.right_only, [])
     self.assertEqual(subdirdiff.diff_files, [])
     dirdiff = filecmp.dircmp(self.export_path, self.local_path, ignore=['.git', '.gitmodules'])
     self.assertEqual(dirdiff.left_only, [])
     self.assertEqual(dirdiff.right_only, [])
     self.assertEqual(dirdiff.diff_files, [])
예제 #2
0
    def test_diff(self):
        url = self.remote_path
        client = GitClient(self.local_path)
        self.assertTrue(client.checkout(url))
        output = client.get_diff()
        self.assertEqual('', output, output)

        with open(os.path.join(self.local_path, 'fixed.txt'), 'a') as f:
            f.write('0123456789abcdef')
        subprocess.check_call("touch new.txt", shell=True, cwd=self.local_path)
        with open(os.path.join(self.sublocal_path, 'subfixed.txt'), 'a') as f:
            f.write('abcdef0123456789')
        subprocess.check_call("touch subnew.txt", shell=True, cwd=self.sublocal_path)
        with open(os.path.join(self.subsublocal_path, 'subsubfixed.txt'), 'a') as f:
            f.write('012345cdef')
        subprocess.check_call("touch subsubnew.txt", shell=True, cwd=self.subsublocal_path)

        output = client.get_diff()
        self.assertEqual(1094, len(output))
        self.assertTrue('diff --git ./fixed.txt ./fixed.txt\nindex e69de29..454f6b3 100644\n--- ./fixed.txt\n+++ ./fixed.txt\n@@ -0,0 +1 @@\n+0123456789abcdef\n\\ No newline at end of file' in output)
        self.assertTrue('diff --git ./submodule/subsubmodule/subsubfixed.txt ./submodule/subsubmodule/subsubfixed.txt\nindex e69de29..1a332dc 100644\n--- ./submodule/subsubmodule/subsubfixed.txt\n+++ ./submodule/subsubmodule/subsubfixed.txt\n@@ -0,0 +1 @@\n+012345cdef\n\\ No newline at end of file' in output)

        output = client.get_diff(basepath=os.path.dirname(self.local_path))
        self.assertEqual(1174, len(output))
        self.assertTrue('diff --git local/fixed.txt local/fixed.txt\nindex e69de29..454f6b3 100644\n--- local/fixed.txt\n+++ local/fixed.txt\n@@ -0,0 +1 @@\n+0123456789abcdef\n\ No newline at end of file' in output, output)
        self.assertTrue('diff --git local/submodule/subsubmodule/subsubfixed.txt local/submodule/subsubmodule/subsubfixed.txt\nindex e69de29..1a332dc 100644\n--- local/submodule/subsubmodule/subsubfixed.txt\n+++ local/submodule/subsubmodule/subsubfixed.txt\n@@ -0,0 +1 @@\n+012345cdef\n\ No newline at end of file' in output, output)
def build_debian_package(package_fetcher, package_name, apt_cache, rd_obj, levels=0, get_dependencies=False):
  unstable_target_distros = { 'groovy': 'quantal', 'hydro': 'raring' }
  target_ubuntu_distro = unstable_target_distros[rd_obj._rosdistro]
  level_prefix = '--' * levels
  print("%s> Building package %s" % (level_prefix, package_name))
  deb_package_name = rd_obj.debianize_package_name(package_name)
  deb_package_version = rd_obj.get_version(package_name, full_version=True) + target_ubuntu_distro
  print("%s--> Checking if installed (%s, %s).." % (level_prefix, deb_package_name, deb_package_version)),
  if deb_package_name in apt_cache:
    installed = apt_cache[deb_package_name].installed
    if installed is not None and installed.version == deb_package_version:
      print("OK")
      print("%s is installed already - remove the package if you want to re-install." % (package_name))
      return True
  print("missing!")
  if get_dependencies:
    dependencies = package_build_order([package_name], distro_name=rd_obj._rosdistro)
    print("%s--> Checking Dependencies:" % (level_prefix))
    for dep_pkg_name in dependencies:
      if dep_pkg_name != package_name:
        print("%s---- %s....." % (level_prefix, dep_pkg_name)),
        debian_pkg_name = rd_obj.debianize_package_name(dep_pkg_name)
        if debian_pkg_name in apt_cache and apt_cache[debian_pkg_name].installed is not None:
          print(" OK! (installed version %s)" % apt_cache[debian_pkg_name].installed.version)
        else:
          print(" Needs build, building...")
          build_debian_package(package_fetcher, dep_pkg_name, apt_cache, rd_obj, levels + 1)
    print("%s<<-- Dependencies OKAY." % (level_prefix))
  print("%s>>> Build debian package %s from repo %s" % (level_prefix, deb_package_name, package_fetcher.url(package_name)))
  repo_path = package_fetcher.checkout_package(package_name)
  client = GitClient(repo_path)
  deb_package_tag = deb_package_name + '_' + rd_obj.get_version(package_name, full_version=True) + '_' + target_ubuntu_distro
  bloom_package_version = 'debian/' + deb_package_tag
  client.update(bloom_package_version)
  installed_builddeps = install_debian_build_dependencies(repo_path)
  if not installed_builddeps:
    raise RosGitBuildError("%s!!! Error building %s from %s: Can't install build-dependencies!" % (level_prefix, deb_package_name, package_fetcher.url(package_name)))
  (returncode, result, message) = run_shell_command('debuild clean', repo_path, shell=True, show_stdout=False)
  if returncode != 0:
    raise RosGitBuildError("%s!!! Error building %s from %s: %s \n %s" % (level_prefix, deb_package_name, package_fetcher.url(package_name), 'debuild clean', message))
  (returncode, result, message) = run_shell_command('debuild binary', repo_path, shell=True, show_stdout=False)
  if returncode != 0:
    raise RosGitBuildError("%s!!! Error building %s from %s: %s \n %s" % (level_prefix, deb_package_name, package_fetcher.url(package_name), 'debuild binary', message))
  deb_files = glob.glob(os.path.join(repo_path, '..', '%s*.deb' % (deb_package_name + '_' + rd_obj.get_version(package_name, full_version=True))))
  if len(deb_files) > 0:
    # install the deb
    from apt.debfile import DebPackage
    deb_pkg = DebPackage(deb_files[0])
    deb_pkg.check()
    packages_needed = ' '.join(deb_pkg.missing_deps)
    (returncode, result, message) = run_shell_command('sudo apt-get -y install %s' % packages_needed, shell=True, show_stdout=True)
    if returncode != 0:
      raise RosGitBuildError("%s!!! Error building %s: can't install dependent packages %s" % (level_prefix, deb_package_name, packages_needed))
    (returncode, result, message) = run_shell_command('sudo dpkg -i %s' % deb_files[0], shell=True, show_stdout=True)
    if returncode != 0:
      raise RosGitBuildError("%s!!! Error building %s from %s: %s \n %s" % (level_prefix, deb_package_name, package_fetcher.url(package_name), 'debuild binary', message))
  else:
    raise RosGitBuildError("%s!!! Can't find a built debian package for %s after the build!" % (level_prefix, deb_package_name))
예제 #4
0
 def test_checkout_branch_with_subs(self):
     url = self.remote_path
     client = GitClient(self.local_path)
     subclient = GitClient(self.sublocal_path)
     subsubclient = GitClient(self.subsublocal_path)
     self.assertFalse(client.path_exists())
     self.assertFalse(client.detect_presence())
     self.assertTrue(client.checkout(url, refname='test_branch'))
     self.assertTrue(client.path_exists())
     self.assertTrue(client.detect_presence())
     self.assertEqual(self.version_init, client.get_version())
     self.assertFalse(subclient.path_exists())
예제 #5
0
    def _get_file(self, _repo_type, repo_url, version, filename):
        """ Fetch the file specificed by filename relative to the root of the repository"""
        name = simplify_repo_name(repo_url)
        repo_path = os.path.join(self._cache_location, name)
        client = GitClient(repo_path)  # using git only
        updated = False
        if client.path_exists():
            if client.get_url() == repo_url:
                if not self._skip_update:
                    logging.disable(logging.WARNING)
                    updated = client.update(version, force_fetch=True)
                    logging.disable(logging.NOTSET)
                else:
                    try:  # catch exception which can be caused by calling internal API
                        logging.disable(logging.WARNING)
                        updated = client._do_update(version)
                        logging.disable(logging.NOTSET)
                    except GitError:
                        updated = False
            if not updated:
                shutil.rmtree(repo_path)
        if not updated:
            logging.disable(logging.WARNING)
            updated = client.checkout(repo_url, version)
            logging.disable(logging.NOTSET)

        if not updated:
            raise VcsError("Impossible to update/checkout repo '%s' with version '%s'." % (repo_url, version))

        full_filename = os.path.join(repo_path, filename)
        if not os.path.exists(full_filename):
            raise VcsError("Requested file '%s' missing from repo '%s' version '%s' (viewed at version '%s').  It was expected at: %s" %
                           (filename, repo_url, version, client.get_version(), full_filename))

        return full_filename
예제 #6
0
    def _get_file(self, repo_type, repo_url, version, filename):
        """ Fetch the file specificed by filename relative to the root of the repository"""
        name = simplify_repo_name(repo_url)
        repo_path = os.path.join(self._cache_location, name)
        #client = VcsClient(repo_type, repo_path)
        client = GitClient(repo_path)  # using git only
        updated = False
        if client.path_exists():
            if client.get_url() == repo_url:
                if not self._skip_update:
                    updated = client.update(version, force_fetch=True)
                else:
                    updated = client._do_update(version)
            if not updated:
                shutil.rmtree(repo_path)
        if not updated:
            updated = client.checkout(repo_url, version, shallow=True)

        if not updated:
            raise VcsError("Impossible to update/checkout repo '%s' with version '%s'." % (repo_url, version))

        full_filename = os.path.join(repo_path, filename)
        if not os.path.exists(full_filename):
            raise VcsError("Requested file '%s' missing from repo '%s' version '%s' (viewed at version '%s').  It was expected at: %s" %
                           (filename, repo_url, version, client.get_version(), full_filename))

        return full_filename
예제 #7
0
    def test_get_url_by_reading(self):
        from vcstools.git import GitClient

        client = GitClient(self.readonly_path)
        self.assertTrue(client.path_exists())
        self.assertTrue(client.detect_presence())
        self.assertEqual(client.get_url(), self.readonly_url)
        self.assertEqual(client.get_version(), self.readonly_version)
        self.assertEqual(client.get_version(self.readonly_version_init[0:6]), self.readonly_version_init)
        self.assertEqual(client.get_version("test_tag"), self.readonly_version_init)
예제 #8
0
    def test_checkout(self):
        from vcstools.git import GitClient
        directory = tempfile.mkdtemp()
        self.directories["checkout_test"] = directory
        local_path = os.path.join(directory, "ros")
        url = self.readonly_url
        client = GitClient(local_path)
        self.assertFalse(client.path_exists())
        self.assertFalse(client.detect_presence())
        self.assertFalse(client.detect_presence())
        self.assertTrue(client.checkout(url))
        self.assertTrue(client.path_exists())
        self.assertTrue(client.detect_presence())
        self.assertEqual(client.get_path(), local_path)
        self.assertEqual(client.get_url(), url)
        self.assertEqual(client.get_branch(), "master")
        self.assertEqual(client.get_branch_parent(), "master")
        #self.assertEqual(client.get_version(), '-r*')

        shutil.rmtree(directory)
        self.directories.pop("checkout_test")
예제 #9
0
    def test_status(self):
        url = self.remote_path
        client = GitClient(self.local_path)
        self.assertTrue(client.checkout(url))
        output = client.get_status()
        self.assertEqual('', output, output)

        with open(os.path.join(self.local_path, 'fixed.txt'), 'a') as f:
            f.write('0123456789abcdef')
        subprocess.check_call("touch new.txt", shell=True, cwd=self.local_path)
        with open(os.path.join(self.sublocal_path, 'subfixed.txt'), 'a') as f:
            f.write('abcdef0123456789')
        subprocess.check_call("touch subnew.txt", shell=True, cwd=self.sublocal_path)
        with open(os.path.join(self.subsublocal_path, 'subsubfixed.txt'), 'a') as f:
            f.write('012345cdef')
        subprocess.check_call("touch subsubnew.txt", shell=True, cwd=self.subsublocal_path)

        output = client.get_status()
        self.assertEqual(' M ./fixed.txt\n M ./submodule\n M ./subfixed.txt\n M ./subsubmodule\n M ./subsubfixed.txt', output.rstrip())

        output = client.get_status(untracked = True)
        self.assertEqual(' M ./fixed.txt\n M ./submodule\n?? ./new.txt\n M ./subfixed.txt\n M ./subsubmodule\n?? ./subnew.txt\n M ./subsubfixed.txt\n?? ./subsubnew.txt', output.rstrip())

        output = client.get_status(basepath=os.path.dirname(self.local_path), untracked = True)
        self.assertEqual(' M local/fixed.txt\n M local/submodule\n?? local/new.txt\n M local/subfixed.txt\n M local/subsubmodule\n?? local/subnew.txt\n M local/subsubfixed.txt\n?? local/subsubnew.txt', output.rstrip())
예제 #10
0
    def setUp(self):
        from vcstools.git import GitClient
        
        directory = tempfile.mkdtemp()
        self.directories = dict(setUp=directory)
        remote_path = os.path.join(directory, "remote")
        os.makedirs(remote_path)
        
        # create a "remote" repo
        subprocess.check_call(["git", "init"], cwd=remote_path)
        subprocess.check_call(["touch", "fixed.txt"], cwd=remote_path)
        subprocess.check_call(["git", "add", "*"], cwd=remote_path)
        subprocess.check_call(["git", "commit", "-m", "initial"], cwd=remote_path)
        subprocess.check_call(["git", "tag", "test_tag"], cwd=remote_path)
        
        po = subprocess.Popen(["git", "log", "-n", "1", "--pretty=format:\"%H\""], cwd=remote_path, stdout=subprocess.PIPE)
        self.readonly_version_init = po.stdout.read().rstrip('"').lstrip('"')
        
        # files to be modified in "local" repo
        subprocess.check_call(["touch", "modified.txt"], cwd=remote_path)
        subprocess.check_call(["touch", "modified-fs.txt"], cwd=remote_path)
        subprocess.check_call(["git", "add", "*"], cwd=remote_path)
        subprocess.check_call(["git", "commit", "-m", "initial"], cwd=remote_path)
        po = subprocess.Popen(["git", "log", "-n", "1", "--pretty=format:\"%H\""], cwd=remote_path, stdout=subprocess.PIPE)
        self.readonly_version_second = po.stdout.read().rstrip('"').lstrip('"')
        
        subprocess.check_call(["touch", "deleted.txt"], cwd=remote_path)
        subprocess.check_call(["touch", "deleted-fs.txt"], cwd=remote_path)
        subprocess.check_call(["git", "add", "*"], cwd=remote_path)
        subprocess.check_call(["git", "commit", "-m", "modified"], cwd=remote_path)
        po = subprocess.Popen(["git", "log", "-n", "1", "--pretty=format:\"%H\""], cwd=remote_path, stdout=subprocess.PIPE)

        self.readonly_version = po.stdout.read().rstrip('"').lstrip('"')
        self.readonly_path = os.path.join(directory, "readonly")
        self.readonly_url = remote_path
        client = GitClient(self.readonly_path)
        self.assertTrue(client.checkout(remote_path, self.readonly_version))
예제 #11
0
    def test_status(self):
        url = self.repo_path
        client = GitClient(self.local_path)
        self.assertTrue(client.checkout(url))
        output = client.get_status(porcelain=True)  # porcelain=True ensures stable format
        self.assertEqual('', output, "Expected empty string, got `{0}`".format(output))

        with open(os.path.join(self.local_path, 'fixed.txt'), 'a') as f:
            f.write('0123456789abcdef')
        subprocess.check_call("touch new.txt", shell=True, cwd=self.local_path)
        with open(os.path.join(self.sublocal_path, 'subfixed.txt'), 'a') as f:
            f.write('abcdef0123456789')
        subprocess.check_call("touch subnew.txt", shell=True, cwd=self.sublocal_path)
        with open(os.path.join(self.subsublocal_path, 'subsubfixed.txt'), 'a') as f:
            f.write('012345cdef')
        subprocess.check_call("touch subsubnew.txt", shell=True, cwd=self.subsublocal_path)

        output = client.get_status(porcelain=True)  # porcelain=True ensures stable format
        self.assertEqual('''\
 M ./fixed.txt
 M ./submodule
 M ./subfixed.txt
 M ./subsubmodule
 M ./subsubfixed.txt''', output.rstrip())

        output = client.get_status(untracked=True, porcelain=True)
        self.assertEqual('''\
 M ./fixed.txt
 M ./submodule
?? ./new.txt
 M ./subfixed.txt
 M ./subsubmodule
?? ./subnew.txt
 M ./subsubfixed.txt
?? ./subsubnew.txt''', output.rstrip())

        output = client.get_status(
            basepath=os.path.dirname(self.local_path),
            untracked=True,
            porcelain=True)
        self.assertEqual('''\
 M local/fixed.txt
 M local/submodule
?? local/new.txt
 M local/subfixed.txt
 M local/subsubmodule
?? local/subnew.txt
 M local/subsubfixed.txt
?? local/subsubnew.txt''', output.rstrip())
  def checkout_package(self, package_name):
    """Fetches and checks out the correct version of a package for the rosdistro"""
    pkg_info = self._rosdist.get_package_checkout_info()[package_name]
    repo_url = pkg_info['url']
    name = os.path.basename(pkg_info['url'])
    repo_path = os.path.join(self.workspace, name)
    client = GitClient(repo_path)
    if client.path_exists():
      tag = pkg_info['version'] if client.is_tag(pkg_info['version']) else pkg_info['full_version']
      if client.get_url() == repo_url:
        # Sometimes debian/rules gets mussed with in the build process.
        # This should translate to 'git checkout debian/rules' which should reset so we can change tags
        client.update('debian/rules', verbose=True)
        updated = client.update(tag, force_fetch=True, verbose=True)
      if not updated:
        print("WARNING: Repo at %s changed url from %s to %s or update failed. Redownloading!" % (repo_path, client.get_url(), repo_url))
        shutil.rmtree(repo_path)
        self.fetch_with_tagcheck(client, pkg_info)

    else:
      self.fetch_with_tagcheck(client, pkg_info)

    return repo_path
예제 #13
0
 def test_export_relative(self):
     url = self.repo_path
     client = GitClient(self.local_path)
     subclient = GitClient(self.sublocal_path)
     subsubclient = GitClient(self.subsublocal_path)
     self.assertFalse(client.path_exists())
     self.assertFalse(client.detect_presence())
     self.assertFalse(os.path.exists(self.export_path))
     self.assertTrue(client.checkout(url, "test_sub_relative"))
     self.assertTrue(client.path_exists())
     self.assertTrue(subclient.path_exists())
     self.assertTrue(subsubclient.path_exists())
     #subprocess.call(["tree", self.root_directory])
     tarpath = client.export_repository("test_sub_relative",
                                        self.export_path)
     self.assertEqual(tarpath, self.export_path + '.tar.gz')
     os.mkdir(self.export_path)
     with closing(tarfile.open(tarpath, "r:gz")) as tarf:
         tarf.extractall(self.export_path)
     subsubdirdiff = filecmp.dircmp(self.subsubexport_path,
                                    self.subsublocal_path,
                                    ignore=['.git', '.gitmodules'])
     self.assertEqual(subsubdirdiff.left_only, [])
     self.assertEqual(subsubdirdiff.right_only, [])
     self.assertEqual(subsubdirdiff.diff_files, [])
     subdirdiff = filecmp.dircmp(self.subexport_path,
                                 self.sublocal_path,
                                 ignore=['.git', '.gitmodules'])
     self.assertEqual(subdirdiff.left_only, [])
     self.assertEqual(subdirdiff.right_only, [])
     self.assertEqual(subdirdiff.diff_files, [])
     dirdiff = filecmp.dircmp(self.export_path,
                              self.local_path,
                              ignore=['.git', '.gitmodules'])
     self.assertEqual(dirdiff.left_only, [])
     self.assertEqual(dirdiff.right_only, [])
     self.assertEqual(dirdiff.diff_files, [])
예제 #14
0
 def test_checkout_branch_with_subs(self):
     url = self.remote_path
     client = GitClient(self.local_path)
     subclient = GitClient(self.sublocal_path)
     subsubclient = GitClient(self.subsublocal_path)
     self.assertFalse(client.path_exists())
     self.assertFalse(client.detect_presence())
     self.assertTrue(client.checkout(url, version='test_branch'))
     self.assertTrue(client.path_exists())
     self.assertTrue(client.detect_presence())
     self.assertEqual(self.version_init, client.get_version())
     self.assertFalse(subclient.path_exists())
예제 #15
0
 def test_switch_branches(self):
     url = self.remote_path
     client = GitClient(self.local_path)
     subclient = GitClient(self.sublocal_path)
     subclient2 = GitClient(self.sublocal2_path)
     subsubclient = GitClient(self.subsublocal_path)
     self.assertFalse(client.path_exists())
     self.assertFalse(client.detect_presence())
     self.assertTrue(client.checkout(url))
     self.assertTrue(client.path_exists())
     self.assertTrue(subclient.path_exists())
     self.assertTrue(subsubclient.path_exists())
     self.assertFalse(subclient2.path_exists())
     new_version = "test_branch2"
     self.assertTrue(client.update(new_version))
     self.assertTrue(subclient2.path_exists())
예제 #16
0
 def testStatusRelPath(self):
     from vcstools.git import GitClient
     client = GitClient(self.readonly_path)
     self.assertTrue(client.path_exists())
     self.assertTrue(client.detect_presence())
     self.assertEquals('A  readonly/added.txt\n D readonly/deleted-fs.txt\nD  readonly/deleted.txt\n M readonly/modified-fs.txt\nM  readonly/modified.txt\n', client.get_status(basepath=os.path.dirname(self.readonly_path)))
예제 #17
0
 def testDiffRelpath(self):
     from vcstools.git import GitClient
     client = GitClient(self.readonly_path)
     self.assertTrue(client.path_exists())
     self.assertTrue(client.detect_presence())
     self.assertEquals('diff --git readonly/added.txt readonly/added.txt\nnew file mode 100644\nindex 0000000..454f6b3\n--- /dev/null\n+++ readonly/added.txt\n@@ -0,0 +1 @@\n+0123456789abcdef\n\\ No newline at end of file\ndiff --git readonly/deleted-fs.txt readonly/deleted-fs.txt\ndeleted file mode 100644\nindex e69de29..0000000\ndiff --git readonly/deleted.txt readonly/deleted.txt\ndeleted file mode 100644\nindex e69de29..0000000\ndiff --git readonly/modified-fs.txt readonly/modified-fs.txt\nindex e69de29..454f6b3 100644\n--- readonly/modified-fs.txt\n+++ readonly/modified-fs.txt\n@@ -0,0 +1 @@\n+0123456789abcdef\n\\ No newline at end of file\ndiff --git readonly/modified.txt readonly/modified.txt\nindex e69de29..454f6b3 100644\n--- readonly/modified.txt\n+++ readonly/modified.txt\n@@ -0,0 +1 @@\n+0123456789abcdef\n\\ No newline at end of file\n', client.get_diff(basepath=os.path.dirname(self.readonly_path)))
예제 #18
0
 def test_get_url_nonexistant(self):
     from vcstools.git import GitClient
     local_path = "/tmp/dummy"
     client = GitClient(local_path)
     self.assertEqual(client.get_url(), None)
예제 #19
0
 def test_switch_branches_retrieve_local_subcommit(self):
     url = self.remote_path
     client = GitClient(self.local_path)
     subclient = GitClient(self.sublocal_path)
     subclient2 = GitClient(self.sublocal2_path)
     subsubclient = GitClient(self.subsublocal_path)
     subsubclient2 = GitClient(self.subsublocal2_path)
     self.assertFalse(client.path_exists())
     self.assertFalse(client.detect_presence())
     self.assertTrue(client.checkout(url))
     self.assertTrue(client.path_exists())
     self.assertTrue(subclient.path_exists())
     self.assertTrue(subsubclient.path_exists())
     self.assertFalse(subclient2.path_exists())
     new_version = "test_branch"
     self.assertTrue(client.update(new_version))
     # checking that update doesnt make submodule disappear (git default behavior)
     self.assertTrue(subclient2.path_exists())
     self.assertTrue(subsubclient2.path_exists())
     self.assertTrue(subclient.path_exists())
     self.assertTrue(subsubclient.path_exists())
     subprocess.check_call("touch submodif.txt", shell=True, cwd=self.sublocal2_path)
     subprocess.check_call("git add submodif.txt", shell=True, cwd=self.sublocal2_path)
     subprocess.check_call("git commit -m submodif", shell=True, cwd=self.sublocal2_path)
     subprocess.check_call("git add submodule2", shell=True, cwd=self.local_path)
     subprocess.check_call("git commit -m submodule2_modif", shell=True, cwd=self.local_path)
     oldnew_version = "master"
     self.assertTrue(client.update(oldnew_version))
     # checking that update doesnt make submodule2 disappear (git default behavior)
     self.assertTrue(subclient2.path_exists())
     self.assertTrue(subsubclient2.path_exists())
     self.assertTrue(subclient.path_exists())
     self.assertTrue(subsubclient.path_exists())
     self.assertTrue(client.update(new_version))
     # checking that update still has submodule with submodif
     self.assertTrue(subclient2.path_exists())
     self.assertTrue(subsubclient2.path_exists())
     self.assertTrue(subclient.path_exists())
     self.assertTrue(subsubclient.path_exists())
     self.assertTrue(os.path.exists(os.path.join(self.sublocal2_path, "submodif.txt")))
예제 #20
0
    def test_export_hash(self):
        url = self.remote_path
        client = GitClient(self.local_path)
        subclient = GitClient(self.sublocal_path)
        subclient2 = GitClient(self.sublocal2_path)
        subsubclient = GitClient(self.subsublocal_path)
        subsubclient2 = GitClient(self.subsublocal2_path)
        self.assertFalse(client.path_exists())
        self.assertFalse(client.detect_presence())
        self.assertFalse(os.path.exists(self.export_path))
        self.assertTrue(client.checkout(url, version='master'))
        self.assertTrue(client.path_exists())
        self.assertTrue(subclient.path_exists())
        self.assertTrue(subsubclient.path_exists())
        self.assertFalse(subclient2.path_exists())
        self.assertFalse(subsubclient2.path_exists())
        # we need first to retrieve locally the hash we want to export
        self.assertTrue(client.update(version=self.version_test))
        self.assertTrue(client.path_exists())
        # git leaves old submodule around by default
        self.assertTrue(subclient.path_exists())
        self.assertTrue(subsubclient.path_exists())
        # new submodule should be there
        self.assertTrue(subclient2.path_exists())
        self.assertTrue(subsubclient2.path_exists())

        tarpath = client.export_repository(self.version_test, self.export_path)
        self.assertEqual(tarpath, self.export_path + '.tar.gz')
        os.mkdir(self.export_path)
        with closing(tarfile.open(tarpath, "r:gz")) as tarf:
            tarf.extractall(self.export_path)

        # Checking that we have only submodule2 in our export
        self.assertFalse(os.path.exists(self.subexport_path))
        self.assertFalse(os.path.exists(self.subsubexport_path))
        self.assertTrue(os.path.exists(self.subexport2_path))
        self.assertTrue(os.path.exists(self.subsubexport2_path))

        # comparing with version_test ( currently checked-out )
        subsubdirdiff = filecmp.dircmp(self.subsubexport2_path, self.subsublocal_path, ignore=['.git', '.gitmodules'])
        self.assertEqual(subsubdirdiff.left_only, [])  # same subsubfixed.txt in both subsubmodule/
        self.assertEqual(subsubdirdiff.right_only, [])
        self.assertEqual(subsubdirdiff.diff_files, [])
        subdirdiff = filecmp.dircmp(self.subexport2_path, self.sublocal_path, ignore=['.git', '.gitmodules'])
        self.assertEqual(subdirdiff.left_only, [])
        self.assertEqual(subdirdiff.right_only, [])
        self.assertEqual(subdirdiff.diff_files, [])
        dirdiff = filecmp.dircmp(self.export_path, self.local_path, ignore=['.git', '.gitmodules'])
        self.assertEqual(dirdiff.left_only, [])
        # submodule is still there on local_path (git default behavior)
        self.assertEqual(dirdiff.right_only, ['submodule'])
        self.assertEqual(dirdiff.diff_files, [])
예제 #21
0
 def testStatusUntracked(self):
     from vcstools.git import GitClient
     client = GitClient(self.readonly_path)
     self.assertTrue(client.path_exists())
     self.assertTrue(client.detect_presence())
     self.assertEquals('A  ./added.txt\n D ./deleted-fs.txt\nD  ./deleted.txt\n M ./modified-fs.txt\nM  ./modified.txt\n?? ./added-fs.txt\n', client.get_status(untracked=True))
def build_debian_package(package_fetcher,
                         package_name,
                         apt_cache,
                         rd_obj,
                         levels=0,
                         get_dependencies=False):
    unstable_target_distros = {'groovy': 'quantal', 'hydro': 'raring'}
    target_ubuntu_distro = unstable_target_distros[rd_obj._rosdistro]
    level_prefix = '--' * levels
    print("%s> Building package %s" % (level_prefix, package_name))
    deb_package_name = rd_obj.debianize_package_name(package_name)
    deb_package_version = rd_obj.get_version(
        package_name, full_version=True) + target_ubuntu_distro
    print("%s--> Checking if installed (%s, %s).." %
          (level_prefix, deb_package_name, deb_package_version)),
    if deb_package_name in apt_cache:
        installed = apt_cache[deb_package_name].installed
        if installed is not None and installed.version == deb_package_version:
            print("OK")
            print(
                "%s is installed already - remove the package if you want to re-install."
                % (package_name))
            return True
    print("missing!")
    if get_dependencies:
        dependencies = package_build_order([package_name],
                                           distro_name=rd_obj._rosdistro)
        print("%s--> Checking Dependencies:" % (level_prefix))
        for dep_pkg_name in dependencies:
            if dep_pkg_name != package_name:
                print("%s---- %s....." % (level_prefix, dep_pkg_name)),
                debian_pkg_name = rd_obj.debianize_package_name(dep_pkg_name)
                if debian_pkg_name in apt_cache and apt_cache[
                        debian_pkg_name].installed is not None:
                    print(" OK! (installed version %s)" %
                          apt_cache[debian_pkg_name].installed.version)
                else:
                    print(" Needs build, building...")
                    build_debian_package(package_fetcher, dep_pkg_name,
                                         apt_cache, rd_obj, levels + 1)
        print("%s<<-- Dependencies OKAY." % (level_prefix))
    print("%s>>> Build debian package %s from repo %s" %
          (level_prefix, deb_package_name, package_fetcher.url(package_name)))
    repo_path = package_fetcher.checkout_package(package_name)
    client = GitClient(repo_path)
    deb_package_tag = deb_package_name + '_' + rd_obj.get_version(
        package_name, full_version=True) + '_' + target_ubuntu_distro
    bloom_package_version = 'debian/' + deb_package_tag
    client.update(bloom_package_version)
    installed_builddeps = install_debian_build_dependencies(repo_path)
    if not installed_builddeps:
        raise RosGitBuildError(
            "%s!!! Error building %s from %s: Can't install build-dependencies!"
            % (level_prefix, deb_package_name,
               package_fetcher.url(package_name)))
    (returncode, result, message) = run_shell_command('debuild clean',
                                                      repo_path,
                                                      shell=True,
                                                      show_stdout=False)
    if returncode != 0:
        raise RosGitBuildError(
            "%s!!! Error building %s from %s: %s \n %s" %
            (level_prefix, deb_package_name, package_fetcher.url(package_name),
             'debuild clean', message))
    (returncode, result, message) = run_shell_command('debuild binary',
                                                      repo_path,
                                                      shell=True,
                                                      show_stdout=False)
    if returncode != 0:
        raise RosGitBuildError(
            "%s!!! Error building %s from %s: %s \n %s" %
            (level_prefix, deb_package_name, package_fetcher.url(package_name),
             'debuild binary', message))
    deb_files = glob.glob(
        os.path.join(
            repo_path, '..',
            '%s*.deb' % (deb_package_name + '_' +
                         rd_obj.get_version(package_name, full_version=True))))
    if len(deb_files) > 0:
        # install the deb
        from apt.debfile import DebPackage
        deb_pkg = DebPackage(deb_files[0])
        deb_pkg.check()
        packages_needed = ' '.join(deb_pkg.missing_deps)
        (returncode, result, message) = run_shell_command(
            'sudo apt-get -y install %s' % packages_needed,
            shell=True,
            show_stdout=True)
        if returncode != 0:
            raise RosGitBuildError(
                "%s!!! Error building %s: can't install dependent packages %s"
                % (level_prefix, deb_package_name, packages_needed))
        (returncode, result,
         message) = run_shell_command('sudo dpkg -i %s' % deb_files[0],
                                      shell=True,
                                      show_stdout=True)
        if returncode != 0:
            raise RosGitBuildError(
                "%s!!! Error building %s from %s: %s \n %s" %
                (level_prefix, deb_package_name,
                 package_fetcher.url(package_name), 'debuild binary', message))
    else:
        raise RosGitBuildError(
            "%s!!! Can't find a built debian package for %s after the build!" %
            (level_prefix, deb_package_name))
예제 #23
0
 def test_get_type_name(self):
     from vcstools.git import GitClient
     local_path = "/tmp/dummy"
     client = GitClient(local_path)
     self.assertEqual(client.get_vcs_type_name(), 'git')
예제 #24
0
    def test_export_hash(self):
        url = self.repo_path
        client = GitClient(self.local_path)
        subclient = GitClient(self.sublocal_path)
        subclient2 = GitClient(self.sublocal2_path)
        subsubclient = GitClient(self.subsublocal_path)
        subsubclient2 = GitClient(self.subsublocal2_path)
        self.assertFalse(client.path_exists())
        self.assertFalse(client.detect_presence())
        self.assertFalse(os.path.exists(self.export_path))
        self.assertTrue(client.checkout(url, version='master'))
        self.assertTrue(client.path_exists())
        self.assertTrue(subclient.path_exists())
        self.assertTrue(subsubclient.path_exists())
        self.assertFalse(subclient2.path_exists())
        self.assertFalse(subsubclient2.path_exists())
        # we need first to retrieve locally the hash we want to export
        self.assertTrue(client.update(version=self.version_test))
        self.assertTrue(client.path_exists())
        # git leaves old submodule around by default
        self.assertTrue(subclient.path_exists())
        self.assertTrue(subsubclient.path_exists())
        # new submodule should be there
        self.assertTrue(subclient2.path_exists())
        self.assertTrue(subsubclient2.path_exists())

        tarpath = client.export_repository(self.version_test, self.export_path)
        self.assertEqual(tarpath, self.export_path + '.tar.gz')
        os.mkdir(self.export_path)
        with closing(tarfile.open(tarpath, "r:gz")) as tarf:
            tarf.extractall(self.export_path)

        # Checking that we have only submodule2 in our export
        self.assertFalse(os.path.exists(self.subexport_path))
        self.assertFalse(os.path.exists(self.subsubexport_path))
        self.assertTrue(os.path.exists(self.subexport2_path))
        self.assertTrue(os.path.exists(self.subsubexport2_path))

        # comparing with version_test ( currently checked-out )
        subsubdirdiff = filecmp.dircmp(self.subsubexport2_path,
                                       self.subsublocal_path,
                                       ignore=['.git', '.gitmodules'])
        self.assertEqual(subsubdirdiff.left_only,
                         [])  # same subsubfixed.txt in both subsubmodule/
        self.assertEqual(subsubdirdiff.right_only, [])
        self.assertEqual(subsubdirdiff.diff_files, [])
        subdirdiff = filecmp.dircmp(self.subexport2_path,
                                    self.sublocal_path,
                                    ignore=['.git', '.gitmodules'])
        self.assertEqual(subdirdiff.left_only, [])
        self.assertEqual(subdirdiff.right_only, [])
        self.assertEqual(subdirdiff.diff_files, [])
        dirdiff = filecmp.dircmp(self.export_path,
                                 self.local_path,
                                 ignore=['.git', '.gitmodules'])
        self.assertEqual(dirdiff.left_only, [])
        # submodule is still there on local_path (git default behavior)
        self.assertEqual(dirdiff.right_only, ['submodule'])
        self.assertEqual(dirdiff.diff_files, [])
예제 #25
0
 def test_switch_branches(self):
     url = self.remote_path
     client = GitClient(self.local_path)
     subclient = GitClient(self.sublocal_path)
     subclient2 = GitClient(self.sublocal2_path)
     subsubclient = GitClient(self.subsublocal_path)
     subsubclient2 = GitClient(self.subsublocal2_path)
     self.assertFalse(client.path_exists())
     self.assertFalse(client.detect_presence())
     self.assertTrue(client.checkout(url))
     self.assertTrue(client.path_exists())
     self.assertTrue(subclient.path_exists())
     self.assertTrue(subsubclient.path_exists())
     self.assertFalse(subclient2.path_exists())
     new_version = "test_branch"
     self.assertTrue(client.update(new_version))
     # checking that update doesnt make submodule disappear (git default behavior)
     self.assertTrue(subclient2.path_exists())
     self.assertTrue(subsubclient2.path_exists())
     self.assertTrue(subclient.path_exists())
     self.assertTrue(subsubclient.path_exists())
     oldnew_version = "master"
     self.assertTrue(client.update(oldnew_version))
     # checking that update doesnt make submodule2 disappear (git default behavior)
     self.assertTrue(subclient2.path_exists())
     self.assertTrue(subsubclient2.path_exists())
     self.assertTrue(subclient.path_exists())
     self.assertTrue(subsubclient.path_exists())
예제 #26
0
 def test_switch_branches(self):
     url = self.repo_path
     client = GitClient(self.local_path)
     subclient = GitClient(self.sublocal_path)
     subclient2 = GitClient(self.sublocal2_path)
     subsubclient = GitClient(self.subsublocal_path)
     subsubclient2 = GitClient(self.subsublocal2_path)
     self.assertFalse(client.path_exists())
     self.assertFalse(client.detect_presence())
     self.assertTrue(client.checkout(url))
     self.assertTrue(client.path_exists())
     self.assertTrue(subclient.path_exists())
     self.assertTrue(subsubclient.path_exists())
     self.assertFalse(subclient2.path_exists())
     new_version = "test_branch"
     self.assertTrue(client.update(new_version))
     # checking that update doesnt make submodule disappear (git default behavior)
     self.assertTrue(subclient2.path_exists())
     self.assertTrue(subsubclient2.path_exists())
     self.assertTrue(subclient.path_exists())
     self.assertTrue(subsubclient.path_exists())
     oldnew_version = "master"
     self.assertTrue(client.update(oldnew_version))
     # checking that update doesnt make submodule2 disappear (git default behavior)
     self.assertTrue(subclient2.path_exists())
     self.assertTrue(subsubclient2.path_exists())
     self.assertTrue(subclient.path_exists())
     self.assertTrue(subsubclient.path_exists())
예제 #27
0
 def test_checkout_master_with_subs(self):
     url = self.remote_path
     client = GitClient(self.local_path)
     subclient = GitClient(self.sublocal_path)
     subsubclient = GitClient(self.subsublocal_path)
     self.assertFalse(client.path_exists())
     self.assertFalse(client.detect_presence())
     self.assertTrue(client.checkout(url))
     self.assertTrue(client.path_exists())
     self.assertTrue(client.detect_presence())
     self.assertEqual(self.version_final, client.get_version())
     self.assertTrue(subclient.path_exists())
     self.assertTrue(subclient.detect_presence())
     self.assertEqual(self.subversion_final, subclient.get_version())
     self.assertTrue(subsubclient.path_exists())
     self.assertTrue(subsubclient.detect_presence())
     self.assertEqual(self.subsubversion_final, subsubclient.get_version())
예제 #28
0
    def test_diff(self):
        url = self.repo_path
        client = GitClient(self.local_path)
        self.assertTrue(client.checkout(url))
        output = client.get_diff()
        self.assertEqual('', output, output)

        with open(os.path.join(self.local_path, 'fixed.txt'), 'a') as f:
            f.write('0123456789abcdef')
        subprocess.check_call("touch new.txt", shell=True, cwd=self.local_path)
        with open(os.path.join(self.sublocal_path, 'subfixed.txt'), 'a') as f:
            f.write('abcdef0123456789')
        subprocess.check_call("touch subnew.txt",
                              shell=True,
                              cwd=self.sublocal_path)
        with open(os.path.join(self.subsublocal_path, 'subsubfixed.txt'),
                  'a') as f:
            f.write('012345cdef')
        subprocess.check_call("touch subsubnew.txt",
                              shell=True,
                              cwd=self.subsublocal_path)

        output = client.get_diff()
        self.assertEqual(1094, len(output))
        self.assertTrue('''\
diff --git ./fixed.txt ./fixed.txt
index e69de29..454f6b3 100644
--- ./fixed.txt
+++ ./fixed.txt
@@ -0,0 +1 @@
+0123456789abcdef
\\ No newline at end of file''' in output)
        self.assertTrue('''\
diff --git ./submodule/subsubmodule/subsubfixed.txt ./submodule/subsubmodule/subsubfixed.txt
index e69de29..1a332dc 100644
--- ./submodule/subsubmodule/subsubfixed.txt
+++ ./submodule/subsubmodule/subsubfixed.txt
@@ -0,0 +1 @@
+012345cdef
\\ No newline at end of file''' in output)

        output = client.get_diff(basepath=os.path.dirname(self.local_path))
        self.assertEqual(1174, len(output))
        self.assertTrue(
            '''\
diff --git local/fixed.txt local/fixed.txt
index e69de29..454f6b3 100644
--- local/fixed.txt
+++ local/fixed.txt
@@ -0,0 +1 @@
+0123456789abcdef
\ No newline at end of file''' in output, output)
        self.assertTrue(
            '''
diff --git local/submodule/subsubmodule/subsubfixed.txt local/submodule/subsubmodule/subsubfixed.txt
index e69de29..1a332dc 100644
--- local/submodule/subsubmodule/subsubfixed.txt
+++ local/submodule/subsubmodule/subsubfixed.txt
@@ -0,0 +1 @@
+012345cdef
\ No newline at end of file''' in output, output)
예제 #29
0
 def test_switch_branches(self):
     url = self.remote_path
     client = GitClient(self.local_path)
     subclient = GitClient(self.sublocal_path)
     subclient2 = GitClient(self.sublocal2_path)
     subsubclient = GitClient(self.subsublocal_path)
     self.assertFalse(client.path_exists())
     self.assertFalse(client.detect_presence())
     self.assertTrue(client.checkout(url))
     self.assertTrue(client.path_exists())
     self.assertTrue(subclient.path_exists())
     self.assertTrue(subsubclient.path_exists())
     self.assertFalse(subclient2.path_exists())
     new_version = "test_branch2"
     self.assertTrue(client.update(new_version))
     self.assertTrue(subclient2.path_exists())
예제 #30
0
 def test_checkout_master_with_subs(self):
     url = self.remote_path
     client = GitClient(self.local_path)
     subclient = GitClient(self.sublocal_path)
     subsubclient = GitClient(self.subsublocal_path)
     self.assertFalse(client.path_exists())
     self.assertFalse(client.detect_presence())
     self.assertTrue(client.checkout(url))
     self.assertTrue(client.path_exists())
     self.assertTrue(client.detect_presence())
     self.assertEqual(self.version_final, client.get_version())
     self.assertTrue(subclient.path_exists())
     self.assertTrue(subclient.detect_presence())
     self.assertEqual(self.subversion_final, subclient.get_version())
     self.assertTrue(subsubclient.path_exists())
     self.assertTrue(subsubclient.detect_presence())
     self.assertEqual(self.subsubversion_final, subsubclient.get_version())
예제 #31
0
 def test_switch_branches_retrieve_local_subcommit(self):
     url = self.repo_path
     client = GitClient(self.local_path)
     subclient = GitClient(self.sublocal_path)
     subclient2 = GitClient(self.sublocal2_path)
     subsubclient = GitClient(self.subsublocal_path)
     subsubclient2 = GitClient(self.subsublocal2_path)
     self.assertFalse(client.path_exists())
     self.assertFalse(client.detect_presence())
     self.assertTrue(client.checkout(url))
     self.assertTrue(client.path_exists())
     self.assertTrue(subclient.path_exists())
     self.assertTrue(subsubclient.path_exists())
     self.assertFalse(subclient2.path_exists())
     new_version = "test_branch"
     self.assertTrue(client.update(new_version))
     # checking that update doesnt make submodule disappear (git default behavior)
     self.assertTrue(subclient2.path_exists())
     self.assertTrue(subsubclient2.path_exists())
     self.assertTrue(subclient.path_exists())
     self.assertTrue(subsubclient.path_exists())
     subprocess.check_call("touch submodif.txt",
                           shell=True,
                           cwd=self.sublocal2_path)
     subprocess.check_call("git add submodif.txt",
                           shell=True,
                           cwd=self.sublocal2_path)
     subprocess.check_call("git commit -m submodif",
                           shell=True,
                           cwd=self.sublocal2_path)
     subprocess.check_call("git add submodule2",
                           shell=True,
                           cwd=self.local_path)
     subprocess.check_call("git commit -m submodule2_modif",
                           shell=True,
                           cwd=self.local_path)
     oldnew_version = "master"
     self.assertTrue(client.update(oldnew_version))
     # checking that update doesnt make submodule2 disappear (git default behavior)
     self.assertTrue(subclient2.path_exists())
     self.assertTrue(subsubclient2.path_exists())
     self.assertTrue(subclient.path_exists())
     self.assertTrue(subsubclient.path_exists())
     self.assertTrue(client.update(new_version))
     # checking that update still has submodule with submodif
     self.assertTrue(subclient2.path_exists())
     self.assertTrue(subsubclient2.path_exists())
     self.assertTrue(subclient.path_exists())
     self.assertTrue(subsubclient.path_exists())
     self.assertTrue(
         os.path.exists(os.path.join(self.sublocal2_path, "submodif.txt")))
예제 #32
0
 def test_checkout_specific_branch_and_update(self):
     from vcstools.git import GitClient
     directory = tempfile.mkdtemp()
     subdir = "checkout_specific_version_test"
     self.directories[subdir] = directory
     local_path = os.path.join(directory, "ros")
     url = self.readonly_url
     branch = "master"
     client = GitClient(local_path)
     self.assertFalse(client.path_exists())
     self.assertFalse(client.detect_presence())
     self.assertTrue(client.checkout(url, branch))
     self.assertTrue(client.path_exists())
     self.assertTrue(client.detect_presence())
     self.assertEqual(client.get_path(), local_path)
     self.assertEqual(client.get_url(), url)
     self.assertEqual(client.get_branch_parent(), branch)
     
     new_branch = 'master'
     self.assertTrue(client.update(new_branch))
     self.assertEqual(client.get_branch_parent(), new_branch)
     
     shutil.rmtree(directory)
     self.directories.pop(subdir)