Example #1
0
    def test_user_space_with_local_sources(self):
        output = TestBufferConanOutput()

        # Need a real repo to get a working SCM object
        local_sources_path = os.path.join(self.tmp_dir,
                                          'git_repo').replace('\\', '/')
        create_local_git_repo(files={'file1': "content"},
                              folder=local_sources_path)
        git = Git(local_sources_path)
        url = "https://remote.url"
        git.run("remote add origin \"{}\"".format(url))

        # Mock the conanfile (return scm_data)
        conanfile = mock.MagicMock()
        conanfile.scm = {'type': 'git', 'url': 'auto', 'revision': 'auto'}

        # Mock functions called from inside _run_scm (tests will be here)
        def merge_directories(src, dst, excluded=None):
            src = os.path.normpath(src)
            dst = os.path.normpath(dst)
            self.assertEqual(src.replace('\\', '/'), local_sources_path)
            self.assertEqual(dst, self.src_folder)

        with mock.patch("conans.client.source.merge_directories",
                        side_effect=merge_directories):
            _run_local_scm(conanfile,
                           conanfile_folder=local_sources_path,
                           src_folder=self.src_folder,
                           output=output)

        self.assertIn(
            "getting sources from folder: {}".format(
                local_sources_path).lower(),
            str(output).lower())
Example #2
0
    def test_ignore_dirty_subfolder(self):
        # https://github.com/conan-io/conan/issues/6070
        conanfile = textwrap.dedent("""
            import os
            from conans import ConanFile, tools

            class ConanLib(ConanFile):
                name = "lib"
                version = "0.1"
                short_paths = True
                scm = {
                    "type": "git",
                    "url": "auto",
                    "revision": "auto",
                }

                def build(self):
                    path = os.path.join("base_file.txt")
                    assert os.path.exists(path)
        """)
        self.client.save({
            "test/main/conanfile.py": conanfile,
            "base_file.txt": "foo"
        })
        create_local_git_repo(folder=self.client.current_folder)
        self.client.run_command('git remote add origin https://myrepo.com.git')

        # Introduce changes
        self.client.save({"dirty_file.txt": "foo"})
        # The build() method will verify that the files from the repository are copied ok
        self.client.run("create test/main/conanfile.py user/channel")
        self.assertIn("Package '{}' created".format(NO_SETTINGS_PACKAGE_ID),
                      self.client.out)
Example #3
0
 def test_double_create(self):
     # https://github.com/conan-io/conan/issues/5195#issuecomment-551848955
     self.client = TestClient(default_server_user=True)
     conanfile = str(GenConanfile().with_scm({
         "type": "git",
         "revision": "auto",
         "url": "auto"
     }).with_import("import os").with_import(
         "from conans import tools").with_name("lib").with_version("1.0"))
     conanfile += """
 def build(self):
     contents = tools.load("bla.sh")
     self.output.warn("Bla? {}".format(contents))
     """
     self.client.save({
         "conanfile.py": conanfile,
         "myfile.txt": "My file is copied"
     })
     create_local_git_repo(folder=self.client.current_folder)
     self.client.run_command('git remote add origin https://myrepo.com.git')
     #  modified blah.sh
     self.client.save({"bla.sh": "bla bla"})
     self.client.run("create . user/channel")
     self.assertIn("Bla? bla bla", self.client.out)
     #  modified blah.sh again
     self.client.save({"bla.sh": "bla2 bla2"})
     # Run conan create again
     self.client.run("create . user/channel")
     self.assertIn("Bla? bla2 bla2", self.client.out)
Example #4
0
    def reuse_scm_test(self):
        client = TestClient()
        conanfile = textwrap.dedent("""
            from conans import ConanFile
            class SomeBase(object):
                scm = {"type" : "git",
                       "url" : "somerepo",
                       "revision" : "auto"}

            class MyConanfileBase(SomeBase, ConanFile):
                pass
            """)
        create_local_git_repo({"conanfile.py": conanfile},
                              branch="my_release",
                              folder=client.current_folder)
        client.run("export . base/1.1@user/testing")

        reuse = textwrap.dedent("""
            from conans import ConanFile
            class PkgTest(ConanFile):
                python_requires = "base/1.1@user/testing"
                python_requires_extend = "base.SomeBase"
            """)
        client.save({"conanfile.py": reuse})
        client.run("export . Pkg/0.1@user/testing")
        client.run("get Pkg/0.1@user/testing")
        self.assertNotIn("scm = base.scm", client.out)
        self.assertIn('scm = {"revision":', client.out)
        self.assertIn('"type": "git",', client.out)
        self.assertIn('"url": "somerepo"', client.out)
Example #5
0
 def test_upload_blocking_auto(self):
     client = TestClient(default_server_user=True)
     conanfile = base_git.format(revision="auto", url='"auto"')
     client.save({
         "conanfile.py": conanfile,
         "myfile.txt": "My file is copied"
     })
     create_local_git_repo(folder=client.current_folder)
     client.run_command('git remote add origin https://myrepo.com.git')
     # Dirty file
     client.save({"dirty": "you dirty contents"})
     client.run("create . user/channel")
     self.assertIn(
         "WARN: There are uncommitted changes, skipping the replacement "
         "of 'scm.url' and 'scm.revision' auto fields. "
         "Use --ignore-dirty to force it.", client.out)
     # The upload has to fail, no "auto" fields are allowed
     client.run("upload lib/0.1@user/channel -r default", assert_error=True)
     self.assertIn(
         "ERROR: lib/0.1@user/channel: Upload recipe to 'default' failed:"
         " The recipe contains invalid data in the 'scm' attribute (some 'auto'"
         " values or missing fields 'type', 'url' or 'revision'). Use '--force'"
         " to ignore", client.out)
     # The upload with --force should work
     client.run("upload lib/0.1@user/channel -r default --force")
     self.assertIn("Uploaded conan recipe", client.out)
Example #6
0
    def test_deleted_source_folder(self):
        path, _ = create_local_git_repo({"myfile": "contents"},
                                        branch="my_release")
        conanfile = base_git.format(url=_quoted("auto"), revision="auto")
        self.client.save({
            "conanfile.py": conanfile,
            "myfile.txt": "My file is copied"
        })
        create_local_git_repo(folder=self.client.current_folder)
        self.client.run_command('git remote add origin "%s"' %
                                path.replace("\\", "/"))
        self.client.run_command('git push origin master')
        self.client.run("export . user/channel")

        # delete old source, but it doesn't matter because the sources are in the cache
        rmdir(self.client.current_folder)
        new_curdir = temp_folder()
        self.client.current_folder = new_curdir

        self.client.run("install lib/0.1@user/channel --build")
        self.assertNotIn(
            "Getting sources from url: '%s'" % path.replace("\\", "/"),
            self.client.out)

        # If the remove the source folder, then it is fetched from the "remote" doing an install
        self.client.run("remove lib/0.1@user/channel -f -s")
        self.client.run("install lib/0.1@user/channel --build")
        self.assertIn(
            "SCM: Getting sources from url: '%s'" % path.replace("\\", "/"),
            self.client.out)
Example #7
0
    def test_clone_submodule_git(self):
        subsubmodule, _ = create_local_git_repo({"subsubmodule": "contents"})
        submodule, _ = create_local_git_repo({"submodule": "contents"},
                                             submodules=[subsubmodule])
        path, commit = create_local_git_repo({"myfile": "contents"},
                                             submodules=[submodule])

        def _create_paths():
            tmp = temp_folder()
            submodule_path = os.path.join(
                tmp, os.path.basename(os.path.normpath(submodule)))
            subsubmodule_path = os.path.join(
                submodule_path,
                os.path.basename(os.path.normpath(subsubmodule)))
            return tmp, submodule_path, subsubmodule_path

        # Check old (default) behaviour
        tmp, submodule_path, _ = _create_paths()
        git = Git(tmp)
        git.clone(path)
        self.assertTrue(os.path.exists(os.path.join(tmp, "myfile")))
        self.assertFalse(
            os.path.exists(os.path.join(submodule_path, "submodule")))

        # Check invalid value
        tmp, submodule_path, _ = _create_paths()
        git = Git(tmp)
        git.clone(path)
        with six.assertRaisesRegex(
                self, ConanException,
                "Invalid 'submodule' attribute value in the 'scm'."):
            git.checkout(commit, submodule="invalid")

        # Check shallow
        tmp, submodule_path, subsubmodule_path = _create_paths()
        git = Git(tmp)
        git.clone(path)
        git.checkout(commit, submodule="shallow")
        self.assertTrue(os.path.exists(os.path.join(tmp, "myfile")))
        self.assertTrue(
            os.path.exists(os.path.join(submodule_path, "submodule")))
        self.assertFalse(
            os.path.exists(os.path.join(subsubmodule_path, "subsubmodule")))

        # Check recursive
        tmp, submodule_path, subsubmodule_path = _create_paths()
        git = Git(tmp)
        git.clone(path)
        git.checkout(commit, submodule="recursive")
        self.assertTrue(os.path.exists(os.path.join(tmp, "myfile")))
        self.assertTrue(
            os.path.exists(os.path.join(submodule_path, "submodule")))
        self.assertTrue(
            os.path.exists(os.path.join(subsubmodule_path, "subsubmodule")))
Example #8
0
    def reuse_scm_multiple_conandata_test(self):
        # https://github.com/conan-io/conan/issues/7236
        # This only works when using conandata.yml, conanfile.py replace is broken
        client = TestClient()
        conanfile = textwrap.dedent("""
            from conans import ConanFile
            class SomeBase(object):
                scm = {"type" : "git",
                       "url" : "remote1",
                       "revision" : "auto"}

            class MyConanfileBase(SomeBase, ConanFile):
                pass
            """)
        _, base_rev = create_local_git_repo({"conanfile.py": conanfile},
                                            branch="my_release",
                                            folder=os.path.join(
                                                client.current_folder, "base"))
        client.run("config set general.scm_to_conandata=1")
        client.run("export base base/1.1@user/testing")

        reuse = textwrap.dedent("""
            from conans import ConanFile
            class PkgTest(ConanFile):
                name = "%s"
                python_requires = "base/1.1@user/testing"
                python_requires_extend = "base.SomeBase"
            """)
        _, reuse1_rev = create_local_git_repo(
            {"conanfile.py": reuse % "reuse1"},
            branch="release",
            folder=os.path.join(client.current_folder, "reuse1"))
        _, reuse2_rev = create_local_git_repo(
            {"conanfile.py": reuse % "reuse2"},
            branch="release",
            folder=os.path.join(client.current_folder, "reuse2"))
        client.run("export reuse1 reuse1/1.1@user/testing")
        client.run("export reuse2 reuse2/1.1@user/testing")

        client.run("inspect base/1.1@user/testing -a=scm --json=base.json")
        base_json = json.loads(client.load("base.json"))
        client.run("inspect reuse1/1.1@user/testing -a=scm --json=reuse1.json")
        reuse1_json = json.loads(client.load("reuse1.json"))
        client.run("inspect reuse2/1.1@user/testing -a=scm --json=reuse2.json")
        reuse2_json = json.loads(client.load("reuse2.json"))
        self.assertEqual(base_json["scm"]["revision"], base_rev)
        self.assertEqual(reuse1_json["scm"]["revision"], reuse1_rev)
        self.assertEqual(reuse2_json["scm"]["revision"], reuse2_rev)
        self.assertNotEqual(base_rev, reuse1_rev)
        self.assertNotEqual(base_rev, reuse2_rev)
        self.assertNotEqual(reuse2_rev, reuse1_rev)
Example #9
0
def test_third_party_git_overwrite_build_file():
    """ Same as the above, but using git clone
    The trick: "git clone <url> ." needs an empty directory. No reason why the ``src`` folder should
    be polluted automatically with exports, so just removing things works
    """
    git_repo = temp_folder().replace("\\", "/")
    create_local_git_repo({"CMakeLists.txt": "MISTAKE Cmake"}, folder=git_repo)

    conanfile = textwrap.dedent(r"""
        import os, shutil
        from conan import ConanFile
        from conan.tools.files import save, load

        class Pkg(ConanFile):
            name = "mypkg"
            version = "1.0"
            exports_sources = "CMakeLists.txt"

            def layout(self):
                self.folders.source = "src"
                self.folders.build = "build"

            def source(self):
                self.output.info("CWD: {{}}!".format(os.getcwd()))
                self.output.info("FILES: {{}}!".format(sorted(os.listdir("."))))
                self.run('git clone "{}" .')
                # Now I fix it with one of the exported files
                shutil.copy("../CMakeLists.txt", ".")

            def build(self):
                if "MISTAKE" in load(self, os.path.join(self.source_folder, "CMakeLists.txt")):
                    raise Exception("MISTAKE BUILD!")
        """.format(git_repo))

    client = TestClient()
    client.save({
        "conanfile.py": conanfile,
        "conandata.yml": "",
        "CMakeLists.txt": "My better cmake"
    })
    client.run("install .")
    client.run("source .")
    assert "FILES: []!" in client.out
    client.run("build .")
    assert "conanfile.py (mypkg/1.0): Calling build()" in client.out

    # of course create should work too
    client.run("create .")
    assert "mypkg/1.0: Created package" in client.out
Example #10
0
    def test_local_source(self):
        curdir = self.client.current_folder.replace("\\", "/")
        conanfile = base_git.format(url=_quoted("auto"), revision="auto")
        conanfile += """
    def source(self):
        self.output.warn("SOURCE METHOD CALLED")
"""
        self.client.save({
            "conanfile.py": conanfile,
            "myfile.txt": "My file is copied"
        })
        create_local_git_repo(folder=self.client.current_folder)
        self.client.save({"aditional_file.txt": "contents"})

        self.client.run("source . --source-folder=./source")
        self.assertTrue(
            os.path.exists(os.path.join(curdir, "source", "myfile.txt")))
        self.assertIn("SOURCE METHOD CALLED", self.client.out)
        # Even the not commited files are copied
        self.assertTrue(
            os.path.exists(os.path.join(curdir, "source",
                                        "aditional_file.txt")))
        self.assertIn("SCM: Getting sources from folder: %s" % curdir,
                      str(self.client.out).replace("\\", "/"))

        # Export again but now with absolute reference, so no pointer file is created nor kept
        git = Git(curdir.replace("\\", "/"))
        conanfile = base_git.format(url=_quoted(curdir.replace("\\", "/")),
                                    revision=git.get_revision())
        conanfile += """
    def source(self):
        self.output.warn("SOURCE METHOD CALLED")
"""
        self.client.save({
            "conanfile.py": conanfile,
            "myfile2.txt": "My file is copied"
        })
        create_local_git_repo(folder=self.client.current_folder)
        self.client.run("source . --source-folder=./source2")
        # myfile2 is no in the specified commit
        self.assertFalse(
            os.path.exists(os.path.join(curdir, "source2", "myfile2.txt")))
        self.assertTrue(
            os.path.exists(os.path.join(curdir, "source2", "myfile.txt")))
        self.assertIn(
            "SCM: Getting sources from url: '%s'" % curdir.replace("\\", "/"),
            self.client.out)
        self.assertIn("SOURCE METHOD CALLED", self.client.out)
Example #11
0
    def test_auto_is_replaced(self):
        conanfile = textwrap.dedent("""
            import os
            from conans import ConanFile

            class Recipe(ConanFile):
                scm = {"type": "git", "url": "auto", "revision": "auto"}
        """)
        t = TestClient()
        t.save({'conanfile.py': conanfile})
        _, commit = create_local_git_repo(folder=t.current_folder)
        t.run_command('git remote add origin https://myrepo.com.git')
        t.run("config set general.scm_to_conandata=1")
        t.run("export . name/version@")

        # Check exported files
        package_layout = t.cache.package_layout(self.ref)
        exported_conanfile = load(package_layout.conanfile())
        self.assertEqual(exported_conanfile, conanfile)
        exported_conandata = load(
            os.path.join(package_layout.export(), DATA_YML))
        conan_data = yaml.safe_load(exported_conandata)
        self.assertDictEqual(conan_data['.conan']['scm'], {
            "type": "git",
            "url": 'https://myrepo.com.git',
            "revision": commit
        })

        # Check the recipe gets the proper values
        t.run("inspect name/version@ -a scm")
        self.assertIn("revision: {}".format(commit), t.out)
        self.assertIn("type: git", t.out)
        self.assertIn("url: https://myrepo.com.git", t.out)
Example #12
0
    def test_repeat_clone_changing_subfolder(self):
        tmp = '''
from conans import ConanFile, tools

class ConanLib(ConanFile):
    name = "lib"
    version = "0.1"
    scm = {{
        "type": "git",
        "url": "{url}",
        "revision": "{revision}",
        "subfolder": "onesubfolder"
    }}
'''
        path, commit = create_local_git_repo({"myfile": "contents"},
                                             branch="my_release")
        conanfile = tmp.format(url=path, revision=commit)
        self.client.save({
            "conanfile.py": conanfile,
            "myfile.txt": "My file is copied"
        })
        self.client.run("create . user/channel")
        conanfile = conanfile.replace('"onesubfolder"', '"othersubfolder"')
        self.client.save({"conanfile.py": conanfile})
        self.client.run("create . user/channel")
        folder = self.client.cache.package_layout(self.ref).source()
        self.assertIn("othersubfolder", os.listdir(folder))
        self.assertTrue(
            os.path.exists(os.path.join(folder, "othersubfolder", "myfile")))
Example #13
0
    def git_to_capture_branch_test(self):
        conanfile = """
import re
from conans import ConanFile, tools

def get_version():
    git = tools.Git()
    try:
        branch = git.get_branch()
        branch = re.sub('[^0-9a-zA-Z]+', '_', branch)
        return "%s_%s" % (branch, git.get_revision())
    except:
        return None

class HelloConan(ConanFile):
    name = "Hello"
    version = get_version()

    def build(self):
        assert("r3le_ase__" in self.version)
        assert(len(self.version) == 50)
"""
        path, _ = create_local_git_repo({"conanfile.py": conanfile},
                                        branch="r3le-ase-")
        client = TestClient()
        client.current_folder = path
        client.run("create . user/channel")
Example #14
0
 def test_clone_git_shallow_revision(self):
     path, revision = create_local_git_repo({"myfile": "contents"},
                                            commits=3,
                                            tags=["1.0"],
                                            branch="develop")
     tmp = temp_folder()
     git = Git(tmp)
     if Git.get_version() < "2.13":
         # older Git versions have known bugs with "git fetch origin <sha>":
         # https://github.com/git/git/blob/master/Documentation/RelNotes/2.13.0.txt
         #  * "git fetch" that requests a commit by object name, when the other
         #    side does not allow such an request, failed without much
         #    explanation.
         # https://github.com/git/git/blob/master/Documentation/RelNotes/2.14.0.txt
         # * There is no good reason why "git fetch $there $sha1" should fail
         #    when the $sha1 names an object at the tip of an advertised ref,
         #    even when the other side hasn't enabled allowTipSHA1InWant.
         with self.assertRaises(subprocess.CalledProcessError):
             git.clone("file://" + path, branch=revision, shallow=True)
     else:
         git.clone("file://" + path, branch=revision, shallow=True)
         with self.assertRaises(subprocess.CalledProcessError):
             git.checkout(element="HEAD~1")
         self.assertTrue(os.path.exists(os.path.join(tmp, "myfile")))
         self.assertEqual(git.get_revision(), revision)
         self.assertEqual(git.run("rev-list --all --count"), "1")
Example #15
0
    def test_shallow_clone_remote(self, remote, revision, is_tag):
        # https://github.com/conan-io/conan/issues/5570
        self.client = TestClient()

        # "remote" git
        if remote == "local":
            remote, rev = create_local_git_repo(
                tags=[revision] if is_tag else None,
                files={"conans/model/username.py": "foo"})
            if revision is None:  # Get the generated commit
                revision = rev

        # Use explicit URL to avoid local optimization (scm_folder.txt)
        conanfile = '''
import os
from conans import ConanFile, tools

class ConanLib(ConanFile):
    name = "lib"
    version = "0.1"
    scm = {"type": "git", "url": "%s", "revision": "%s"}

    def build(self):
        assert os.path.exists(os.path.join(self.build_folder, "conans", "model", "username.py"))
''' % (remote, revision)
        self.client.save({"conanfile.py": conanfile})
        self.client.run("create . user/channel")
Example #16
0
    def test_full_scm(self):
        folder = os.path.join(temp_folder(), "myrepo")
        url, commit = create_local_git_repo(files={"conan/conanfile.py": self.conanfile,
                                                   "src/myfile.h": "myheader!",
                                                   "CMakeLists.txt": "mycmake"}, folder=folder)

        c = TestClient(default_server_user=True)
        c.run_command('git clone "{}" .'.format(url))
        c.run("create conan")
        assert "pkg/0.1: MYCMAKE: mycmake" in c.out
        assert "pkg/0.1: MYFILE: myheader!" in c.out
        c.run("upload * --all -c")

        # Do a change and commit, this commit will not be used by package
        save_files(path=folder, files={"src/myfile.h": "my2header2!"})
        git_add_changes_commit(folder=folder)

        # use another fresh client
        c2 = TestClient(servers=c.servers)
        c2.run("install pkg/0.1@ --build=pkg")
        assert "pkg/0.1: MYCMAKE: mycmake" in c2.out
        assert "pkg/0.1: MYFILE: myheader!" in c2.out

        # local flow
        c.run("install conan")
        c.run("build conan")
        assert "conanfile.py (pkg/0.1): MYCMAKE-BUILD: mycmake" in c.out
        assert "conanfile.py (pkg/0.1): MYFILE-BUILD: myheader!" in c.out
Example #17
0
    def test_scm_bad_filename(self):
        # Fixes: #3500
        badfilename = "\xE3\x81\x82badfile.txt"
        path, _ = create_local_git_repo({"goodfile.txt": "good contents"},
                                        branch="my_release")
        save(
            to_file_bytes(os.path.join(self.client.current_folder,
                                       badfilename)), "contents")
        self.client.run_command('git remote add origin "%s"' %
                                path.replace("\\", "/"),
                                cwd=path)

        conanfile = '''
import os
from conans import ConanFile, tools

class ConanLib(ConanFile):
    name = "lib"
    version = "0.1"
    scm = {
        "type": "git",
        "url": "auto",
        "revision": "auto"
    }

    def build(self):
        pass
'''
        self.client.current_folder = path
        self.client.save({"conanfile.py": conanfile})
        self.client.run("create . user/channel")
Example #18
0
    def test_source_method_export_sources_and_scm_mixed(self):
        path, _ = create_local_git_repo({"myfile": "contents"}, branch="my_release")

        conanfile = '''
import os
from conans import ConanFile, tools

class ConanLib(ConanFile):
    name = "lib"
    version = "0.1"
    exports_sources = "file.txt"
    scm = {
        "type": "git",
        "url": "%s",
        "revision": "my_release",
        "subfolder": "src/nested"
    }

    def source(self):
        self.output.warn("SOURCE METHOD CALLED")
        assert(os.path.exists("file.txt"))
        assert(os.path.exists(os.path.join("src", "nested", "myfile")))
        tools.save("cosa.txt", "contents")

    def build(self):
        assert(os.path.exists("file.txt"))
        assert(os.path.exists("cosa.txt"))
        self.output.warn("BUILD METHOD CALLED")
''' % path
        self.client.save({"conanfile.py": conanfile, "file.txt": "My file is copied"})
        self.client.run("create . user/channel")
        self.assertIn("SOURCE METHOD CALLED", self.client.out)
        self.assertIn("BUILD METHOD CALLED", self.client.out)
Example #19
0
    def test_git_delegated_function(self):
        conanfile = """
import os
from conans import ConanFile
from conans.client.tools.scm import Git

def get_revision():
    here = os.path.dirname(__file__)
    git = Git(here)
    return git.get_commit()

def get_url():
    def nested_url():
        here = os.path.dirname(__file__)
        git = Git(here)
        return git.get_remote_url()
    return nested_url()

class MyLib(ConanFile):
    name = "issue"
    version = "3831"
    scm = {'type': 'git', 'url': get_url(), 'revision': get_revision()}

"""
        self.client.save({"conanfile.py": conanfile})
        path, commit = create_local_git_repo(folder=self.client.current_folder)
        self.client.run_command('git remote add origin "%s"' %
                                path.replace("\\", "/"))

        self.client.run("export . user/channel")
        ref = ConanFileReference.loads("issue/3831@user/channel")
        exported_conanfile = self.client.cache.package_layout(ref).conanfile()
        content = load(exported_conanfile)
        self.assertIn(commit, content)
Example #20
0
    def test_source_removed_in_local_cache(self):
        conanfile = '''
from conans import ConanFile, tools

class ConanLib(ConanFile):
    scm = {
        "type": "git",
        "url": "auto",
        "revision": "auto",
    }

    def build(self):
        contents = tools.load("myfile")
        self.output.warn("Contents: %s" % contents)

'''
        path, _ = create_local_git_repo(
            {
                "myfile": "contents",
                "conanfile.py": conanfile
            },
            branch="my_release")
        self.client.current_folder = path
        self.client.run_command('git remote add origin https://myrepo.com.git')
        self.client.run("create . lib/1.0@user/channel")
        self.assertIn("Contents: contents", self.client.out)
        self.client.save({"myfile": "Contents 2"})
        self.client.run("create . lib/1.0@user/channel")
        self.assertIn("Contents: Contents 2", self.client.out)
Example #21
0
    def test_reuse_scm(self):
        client = TestClient()

        conanfile = """from conans import ConanFile
scm = {"type" : "git",
       "url" : "somerepo",
       "revision" : "auto"}

class MyConanfileBase(ConanFile):
    scm = scm
"""
        create_local_git_repo({"conanfile.py": conanfile},
                              branch="my_release",
                              folder=client.current_folder)
        client.run("export . MyConanfileBase/1.1@lasote/testing")
        client.run("get MyConanfileBase/1.1@lasote/testing")
        # The global scm is left as-is
        self.assertIn(
            """scm = {"type" : "git",
       "url" : "somerepo",
       "revision" : "auto"}""", client.out)
        # but the class one is replaced
        self.assertNotIn("scm = scm", client.out)
        self.assertIn('    scm = {"revision":', client.out)
        self.assertIn('"type": "git",', client.out)
        self.assertIn('"url": "somerepo"', client.out)

        reuse = """from conans import python_requires
base = python_requires("MyConanfileBase/1.1@lasote/testing")
class PkgTest(base.MyConanfileBase):
    scm = base.scm
    other = 123
    def _my_method(self):
        pass
"""
        client.save({"conanfile.py": reuse})
        # Commit changes so it replaces and exports the scm data
        client.run_command('git add .')
        client.run_command('git commit -m "Modified conanfile"')

        client.run("export . Pkg/0.1@lasote/testing")
        client.run("get Pkg/0.1@lasote/testing")
        self.assertNotIn("scm = base.scm", client.out)
        self.assertIn('scm = {"revision":', client.out)
        self.assertIn('"type": "git",', client.out)
        self.assertIn('"url": "somerepo"', client.out)
Example #22
0
    def test_auto_git(self):
        curdir = get_cased_path(self.client.current_folder).replace("\\", "/")
        conanfile = base_git.format(directory="None",
                                    url=_quoted("auto"),
                                    revision="auto")
        self.client.save({
            "conanfile.py": conanfile,
            "myfile.txt": "My file is copied"
        })
        create_local_git_repo(folder=self.client.current_folder)
        self.client.run("export . user/channel")
        self.assertIn(
            "WARN: Repo origin cannot be deduced, 'auto' fields won't be replaced",
            self.client.out)

        self.client.run_command('git remote add origin https://myrepo.com.git')

        # Create the package, will copy the sources from the local folder
        self.client.run("create . user/channel")
        self.assertIn("Repo origin deduced by 'auto': https://myrepo.com.git",
                      self.client.out)
        self.assertIn("Revision deduced by 'auto'", self.client.out)
        self.assertIn("SCM: Getting sources from folder: %s" % curdir,
                      self.client.out)
        self.assertIn("My file is copied", self.client.out)

        # check blank lines are respected in replacement
        self.client.run("get lib/0.1@user/channel")
        self.assertIn("""}

    def build(self):""", self.client.out)

        # Export again but now with absolute reference, so no sources are copied from the local dir
        git = Git(curdir)
        self.client.save({
            "conanfile.py":
            base_git.format(url=_quoted(curdir), revision=git.get_revision())
        })
        self.client.run("create . user/channel")
        self.assertNotIn("Repo origin deduced by 'auto'", self.client.out)
        self.assertNotIn("Revision deduced by 'auto'", self.client.out)
        self.assertNotIn("Getting sources from folder: %s" % curdir,
                         self.client.out)
        self.assertIn("SCM: Getting sources from url: '%s'" % curdir,
                      self.client.out)
        self.assertIn("My file is copied", self.client.out)
Example #23
0
 def init_git_repo(self, files=None, branch=None, submodules=None, folder=None, origin_url=None):
     if folder is not None:
         folder = os.path.join(self.current_folder, folder)
     else:
         folder = self.current_folder
     _, commit = create_local_git_repo(files, branch, submodules, folder=folder,
                                       origin_url=origin_url)
     return commit
Example #24
0
 def init_git_repo(self,
                   files=None,
                   branch=None,
                   submodules=None,
                   origin_url=None):
     _, commit = create_local_git_repo(files, branch, submodules,
                                       self.current_folder)
     if origin_url:
         self.run_command('git remote add origin {}'.format(origin_url))
     return commit
Example #25
0
    def setUp(self):
        self.client = TestClient()

        # Create a local repo
        verify_ssl_attrib_str = ""
        if self.verify_ssl is not None:
            verify_ssl_attrib_str = '"verify_ssl": {}'.format(self.verify_ssl)
        files = {'conanfile.py': self.conanfile.format(verify_ssl_attrib=verify_ssl_attrib_str)}
        url, _ = create_local_git_repo(files=files, commits=4, tags=['v0', ])
        self.client.run_command('git clone "{}" .'.format(url))
Example #26
0
    def test_revision_mode_scm(self):
        path, rev = create_local_git_repo(
            files={'conanfile.py': self.conanfile.format(revision_mode="scm")})
        t = TestClient(current_folder=path)

        ref = ConanFileReference.loads("name/version@user/channel")
        t.run("export . {}".format(ref))

        meta = t.cache.package_layout(ref, short_paths=False).load_metadata()
        self.assertEqual(meta.recipe.revision, rev)
Example #27
0
 def test_clone_git_shallow(self, element):
     path, revision = create_local_git_repo({"myfile": "contents"}, commits=3, tags=["1.0"], branch="develop")
     tmp = temp_folder()
     git = Git(tmp)
     git.clone("file://" + path, branch=element, shallow=True)  # --depth is ignored in local clones
     with self.assertRaises(subprocess.CalledProcessError):
         git.checkout(element="HEAD~1")
     self.assertTrue(os.path.exists(os.path.join(tmp, "myfile")))
     self.assertEqual(git.get_revision(), revision)
     self.assertEqual(git.run("rev-list --all --count"), "1")
Example #28
0
    def test_repo_root(self):
        root_path, _ = create_local_git_repo({"myfile": "anything"})

        # Initialized in the root folder
        git = Git(root_path)
        self.assertEqual(root_path, git.get_repo_root())

        # Initialized elsewhere
        subfolder = os.path.join(root_path, 'subfolder')
        os.makedirs(subfolder)
        git = Git(subfolder)
        self.assertEqual(root_path, git.get_repo_root())
Example #29
0
    def test_clone_existing_folder_git(self):
        path, commit = create_local_git_repo({"myfile": "contents"}, branch="my_release")

        tmp = temp_folder()
        save(os.path.join(tmp, "file"), "dummy contents")
        git = Git(tmp)
        git.clone(path, branch="my_release")
        self.assertTrue(os.path.exists(os.path.join(tmp, "myfile")))

        # Checkout a commit
        git.checkout(commit)
        self.assertEqual(git.get_revision(), commit)
    def setUp(self):
        ref = ConanFileReference.loads("name/version@user/channel")
        tmp_dir = temp_folder()

        # Need a real repo to get a working SCM object
        self.conanfile_dir = os.path.join(tmp_dir, 'git_repo').replace('\\', '/')
        self.git = Git(folder=self.conanfile_dir)
        self.origin, self.rev = create_local_git_repo(files={'file1': "content"},
                                                      folder=self.git.folder)

        # Mock the cache item (return the cache_ref_folder)
        self.cache_ref_folder = os.path.join(temp_folder(), ref.dir_repr())