def testManifestInheritance(self):
        osutils.WriteFile(
            self.active_manifest, """
        <manifest>
          <include name="include-target.xml" />
          <include name="empty.xml" />
          <project name="monkeys" path="baz" remote="foon" revision="master" />
        </manifest>""")
        # First, verify it properly explodes if the include can't be found.
        self.assertRaises(EnvironmentError, git.ManifestCheckout, self.tempdir)

        # Next, verify it can read an empty manifest; this is to ensure
        # that we can point Manifest at the empty manifest without exploding,
        # same for ManifestCheckout; this sort of thing is primarily useful
        # to ensure no step of an include assumes everything is yet assembled.
        empty_path = os.path.join(self.manifest_dir, 'empty.xml')
        osutils.WriteFile(empty_path, '<manifest/>')
        git.Manifest(empty_path)
        git.ManifestCheckout(self.tempdir, manifest_path=empty_path)

        # Next, verify include works.
        osutils.WriteFile(
            os.path.join(self.manifest_dir, 'include-target.xml'), """
        <manifest>
          <remote name="foon" fetch="http://localhost" />
        </manifest>""")
        manifest = git.ManifestCheckout(self.tempdir)
        self.assertEqual(list(manifest.checkouts_by_name), ['monkeys'])
        self.assertEqual(list(manifest.remotes), ['foon'])
Exemple #2
0
  def testApplyAgainstManifest(self):
    git1, git2, _ = self._CommonGitSetup()

    readme_text = 'Dummy README text.'
    readme1 = self.CommitFile(git1, 'README', readme_text)
    readme_text += ' Even more dummy README text.'
    readme2 = self.CommitFile(git1, 'README', readme_text)
    readme_text += ' Even more README text.'
    readme3 = self.CommitFile(git1, 'README', readme_text)

    git1_proj = {
        'path': git1,
        'name': 'chromiumos/chromite',
        'revision': str(readme1.sha1),
        'upstream': 'refs/heads/master',
    }
    git2_proj = {
        'path': git2,
        'name': 'git2',
    }
    basedir = self._CommonRepoSetup(git1_proj, git2_proj)

    self.PatchObject(git.ManifestCheckout, '_GetManifestsBranch',
                     return_value=None)
    manifest = git.ManifestCheckout(basedir)

    readme2.ApplyAgainstManifest(manifest)
    readme3.ApplyAgainstManifest(manifest)

    # Verify that both readme2 and readme3 are on the patch branch.
    cmd = ['git', 'log', '--format=%T',
           '%s..%s' % (readme1.sha1, constants.PATCH_BRANCH)]
    trees = self._run(cmd, git1).splitlines()
    self.assertEqual(trees, [str(readme3.tree_hash), str(readme2.tree_hash)])
Exemple #3
0
def main(argv):
    parser = GetParser()
    options = parser.parse_args(argv)
    repo_dir = git.FindRepoDir(os.getcwd())
    if not repo_dir:
        parser.error("This script must be invoked from within a repository "
                     "checkout.")

    options.git_config = os.path.join(repo_dir, 'manifests.git', 'config')
    options.local_manifest_path = os.path.join(repo_dir, 'local_manifest.xml')

    manifest_sym_path = os.path.join(repo_dir, 'manifest.xml')
    if os.path.basename(os.readlink(manifest_sym_path)) == 'minilayout.xml':
        _AssertNotMiniLayout()

    # For now, we only support the add command.
    assert options.command == 'add'
    if options.workon:
        if options.path is not None:
            parser.error('Adding workon projects do not set project.')
    else:
        if options.remote is None:
            parser.error('Adding non-workon projects requires a remote.')
        if options.path is None:
            parser.error('Adding non-workon projects requires a path.')
    name = options.project
    path = options.path
    revision = options.revision
    if revision is not None:
        if (not git.IsRefsTags(revision) and not git.IsSHA1(revision)):
            revision = git.StripRefsHeads(revision, False)

    main_manifest = git.ManifestCheckout(os.getcwd())
    main_element = main_manifest.FindCheckouts(name)
    if path is not None:
        main_element_from_path = main_manifest.FindCheckoutFromPath(
            path, strict=False)
        if main_element_from_path is not None:
            main_element.append(main_element_from_path)

    local_manifest = LocalManifest.FromPath(options.local_manifest_path)

    if options.workon:
        if not main_element:
            parser.error('No project named %r in the default manifest.' % name)
        _AddProjectsToManifestGroups(
            options, [checkout['name'] for checkout in main_element])

    elif main_element:
        if options.remote is not None:
            # Likely this project wasn't meant to be remote, so workon main element
            print(
                "Project already exists in manifest. Using that as workon project."
            )
            _AddProjectsToManifestGroups(
                options, [checkout['name'] for checkout in main_element])
        else:
            # Conflict will occur; complain.
            parser.error(
                "Requested project name=%r path=%r will conflict with "
                "your current manifest %s" %
                (name, path, main_manifest.manifest_path))

    elif local_manifest.GetProject(name, path=path) is not None:
        parser.error("Requested project name=%r path=%r conflicts with "
                     "your local_manifest.xml" % (name, path))

    else:
        element = local_manifest.AddNonWorkonProject(name=name,
                                                     path=path,
                                                     remote=options.remote,
                                                     revision=revision)
        _AddProjectsToManifestGroups(options, [element.attrib['name']])

        with open(options.local_manifest_path, 'w') as f:
            f.write(local_manifest.ToString())
    return 0