Esempio n. 1
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")
Esempio n. 2
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", assert_error=True)
        self.assertIn("Repo origin cannot be deduced", 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)
Esempio n. 3
0
File: tools.py Progetto: stkw0/conan
def create_local_git_repo(files=None, branch=None, submodules=None, folder=None, commits=1,
                          tags=None):
    tmp = folder or temp_folder()
    tmp = get_cased_path(tmp)
    if files:
        save_files(tmp, files)
    git = Git(tmp)
    git.run("init .")
    git.run('config user.email "*****@*****.**"')
    git.run('config user.name "Your Name"')

    if branch:
        git.run("checkout -b %s" % branch)

    git.run("add .")
    for i in range(0, commits):
        git.run('commit --allow-empty -m "commiting"')

    tags = tags or []
    for tag in tags:
        git.run("tag %s" % tag)

    if submodules:
        for submodule in submodules:
            git.run('submodule add "%s"' % submodule)
        git.run('commit -m "add submodules"')

    return tmp.replace("\\", "/"), git.get_revision()
Esempio n. 4
0
    def test_local_source(self):
        curdir = self.client.current_folder
        conanfile = base_git.format(url="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("Getting sources from folder: %s" % curdir, self.client.out)

        # Export again but now with absolute reference, so no pointer file is created nor kept
        git = Git(curdir.replace("\\", "/"))
        conanfile = base_git.format(url=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("Getting sources from url: '%s'" % curdir.replace("\\", "/"), self.client.out)
        self.assertIn("SOURCE METHOD CALLED", self.client.out)
Esempio n. 5
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")
Esempio n. 6
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)
Esempio n. 7
0
def create_local_git_repo(files, branch=None):
    tmp = temp_folder()
    save_files(tmp, files)
    git = Git(tmp)
    git.run("init .")
    if branch:
        git.run("checkout -b %s" % branch)
    git.run("add .")
    git.run('config user.email "*****@*****.**"')
    git.run('config user.name "Your Name"')
    git.run('commit -m "message"')
    return tmp.replace("\\", "/"), git.get_revision()
Esempio n. 8
0
 def test_clone_git_shallow_with_local(self):
     path, revision = create_local_git_repo({"repofile": "contents"}, commits=3)
     tmp = temp_folder()
     save(os.path.join(tmp, "localfile"), "contents")
     save(os.path.join(tmp, "indexfile"), "contents")
     git = Git(tmp)
     git.run("init")
     git.run("add indexfile")
     git.clone("file://" + path, branch="master", shallow=True)  # --depth is ignored in local clones
     self.assertTrue(os.path.exists(os.path.join(tmp, "repofile")))
     self.assertTrue(os.path.exists(os.path.join(tmp, "localfile")))
     self.assertTrue(os.path.exists(os.path.join(tmp, "indexfile")))
     self.assertEqual(git.get_revision(), revision)
     self.assertEqual(git.run("rev-list --all --count"), "1")
Esempio n. 9
0
    def test_auto_git(self):
        curdir = self.client.current_folder.replace("\\", "/")
        conanfile = base.format(directory="None", url="auto", revision="auto")
        self.client.save({
            "conanfile.py": conanfile,
            "myfile.txt": "My file is copied"
        })
        self._commit_contents()
        error = self.client.run("export . user/channel", ignore_error=True)
        self.assertTrue(error)
        self.assertIn("Repo origin cannot be deduced by 'auto'",
                      self.client.out)

        self.client.runner('git remote add origin https://myrepo.com.git',
                           cwd=curdir)

        # Create the package, will copy the sources from the local folder
        self.client.run("create . user/channel")
        sources_dir = self.client.client_cache.scm_folder(self.reference)
        self.assertEquals(load(sources_dir), curdir)
        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("Getting sources from folder: %s" % curdir,
                      self.client.out)
        self.assertIn("My file is copied", self.client.out)

        # Export again but now with absolute reference, so no pointer file is created nor kept
        git = Git(curdir)
        self.client.save({
            "conanfile.py":
            base.format(url=curdir, revision=git.get_revision())
        })
        self.client.run("create . user/channel")
        sources_dir = self.client.client_cache.scm_folder(self.reference)
        self.assertFalse(os.path.exists(sources_dir))
        self.assertNotIn("Repo origin deduced by 'auto'", self.client.out)
        self.assertNotIn("Revision deduced by 'auto'", self.client.out)
        self.assertIn("Getting sources from url: '%s'" % curdir,
                      self.client.out)
        self.assertIn("My file is copied", self.client.out)
Esempio n. 10
0
def create_local_git_repo(files=None,
                          branch=None,
                          submodules=None,
                          folder=None):
    tmp = folder or temp_folder()
    if files:
        save_files(tmp, files)
    git = Git(tmp)
    git.run("init .")
    git.run('config user.email "*****@*****.**"')
    git.run('config user.name "Your Name"')

    if branch:
        git.run("checkout -b %s" % branch)

    git.run("add .")
    git.run('commit -m  "commiting"')

    if submodules:
        for submodule in submodules:
            git.run('submodule add "%s"' % submodule)
        git.run('commit -m "add submodules"')

    return tmp.replace("\\", "/"), git.get_revision()