Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix shallow copy: 1.18.1 #5571

Merged
merged 4 commits into from Aug 2, 2019
Merged
Changes from 3 commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -145,23 +145,30 @@ def clone(self, url, branch=None, args="", shallow=False):
return output

def checkout(self, element, submodule=None):
# Element can be a tag, branch or commit
self.check_repo()
output = self.run('checkout "%s"' % element)
self.checkout_submodules(submodule)
This conversation was marked as resolved by lasote

This comment has been minimized.

Copy link
@jgsogo

jgsogo Aug 2, 2019

Member
Suggested change
self.checkout_submodules(submodule)
output += self.checkout_submodules(submodule)

if submodule:
if submodule == "shallow":
output += self.run("submodule sync")
output += self.run("submodule update --init")
elif submodule == "recursive":
output += self.run("submodule sync --recursive")
output += self.run("submodule update --init --recursive")
else:
raise ConanException("Invalid 'submodule' attribute value in the 'scm'. "
"Unknown value '%s'. Allowed values: ['shallow', 'recursive']"
% submodule)
# Element can be a tag, branch or commit
return output

def checkout_submodules(self, submodule=None):
"""Do the checkout only for submodules"""
if not submodule:
return ""
if submodule == "shallow":
output = self.run("submodule sync")
output += self.run("submodule update --init")
return output
elif submodule == "recursive":
output = self.run("submodule sync --recursive")
output += self.run("submodule update --init --recursive")
return output
else:
raise ConanException("Invalid 'submodule' attribute value in the 'scm'. "
"Unknown value '%s'. Allowed values: ['shallow', 'recursive']"
% submodule)

def excluded_files(self):
ret = []
try:
@@ -89,14 +89,17 @@ def checkout(self):
output = ""
if self._data.type == "git":
try:
output += self.repo.clone(url=self._data.url, branch=self._data.revision, shallow=True)
output += self.repo.clone(url=self._data.url, branch=self._data.revision,
shallow=True)
except subprocess.CalledProcessError:
# remove the .git directory, otherwise, fallback clone cannot be successful
# it's completely safe to do here, as clone without branch expects empty directory
rmdir(os.path.join(self.repo_folder, ".git"))
output += self.repo.clone(url=self._data.url, shallow=False)
output += self.repo.checkout(element=self._data.revision,
submodule=self._data.submodule)
output += self.repo.checkout(element=self._data.revision,
submodule=self._data.submodule)
else:
output += self.repo.checkout_submodules(submodule=self._data.submodule)
else:
output += self.repo.checkout(url=self._data.url, revision=self._data.revision)
return output
@@ -4,6 +4,7 @@
from collections import namedtuple

from nose.plugins.attrib import attr
from parameterized.parameterized import parameterized

from conans.client.tools.scm import Git, SVN
from conans.client.tools.win import get_cased_path
@@ -290,6 +291,41 @@ def source(self):
self.assertTrue(os.path.exists(os.path.join(curdir, "source", "mysub", "myfile.txt")))
self.assertIn("SOURCE METHOD CALLED", self.client.out)

@parameterized.expand([
("local", "v1.0", True),
("local", None, False),
("https://github.com/conan-io/conan.git", "0.22.1", True),
("https://github.com/conan-io/conan.git", "c6cc15fa2f4b576bd70c9df11942e61e5cc7d746", False)])
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, _ = 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 = Git(remote).get_commit()
This conversation was marked as resolved by lasote

This comment has been minimized.

Copy link
@jgsogo

jgsogo Aug 2, 2019

Member

The revision is returned in the _ of your previous call


# 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})
create_local_git_repo(folder=self.client.current_folder, tags=[revision])
This conversation was marked as resolved by lasote

This comment has been minimized.

Copy link
@jgsogo

jgsogo Aug 2, 2019

Member

What is this second repo for?

This comment has been minimized.

Copy link
@lasote

lasote Aug 2, 2019

Author Contributor

for nothing. removing it.

ret_code = self.client.run_command('git remote add origin "{}"'.format(remote))
self.assertEqual(ret_code, 0)
self.client.run("create . user/channel")

def test_install_checked_out(self):
test_server = TestServer()
self.servers = {"myremote": test_server}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.