diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst index ccb944f0..91ffc7a9 100644 --- a/docs/source/changelog.rst +++ b/docs/source/changelog.rst @@ -10,7 +10,6 @@ Release date: TBD New features ------------ -- Fix for submodule check out in :pr:`809` by :user:`davidbrochart`. - Add support for Figshare in :pr:`788` by :user:`nuest`. - Add support for Dataverse in :pr:`739` by :user:`Xarthisius`. @@ -20,7 +19,7 @@ API changes Bug fixes --------- - +- Fix for submodule check out in :pr:`809` by :user:`davidbrochart`. Version 0.10.0 diff --git a/repo2docker/contentproviders/git.py b/repo2docker/contentproviders/git.py index ff68ce9b..71e12d0e 100644 --- a/repo2docker/contentproviders/git.py +++ b/repo2docker/contentproviders/git.py @@ -21,29 +21,24 @@ class Git(ContentProvider): # make a, possibly shallow, clone of the remote repository try: - cmd = ["git", "clone", "--recursive"] + cmd = ["git", "clone"] if ref is None: - # check out of HEAD is performed after the clone is complete cmd.extend(["--depth", "1"]) else: - # don't check out HEAD, the given ref will be checked out later - # this prevents HEAD's submodules to be cloned if ref doesn't have them - cmd.extend(["--no-checkout"]) + cmd.extend(["--branch", ref]) cmd.extend([repo, output_dir]) for line in execute_cmd(cmd, capture=yield_output): yield line except subprocess.CalledProcessError as e: - msg = "Failed to clone repository from {repo}.".format(repo=repo) + msg = "Failed to clone repository from {repo}".format(repo=repo) + if ref is not None: + msg += " (ref {ref})".format(ref=ref) + msg += "." raise ContentProviderException(msg) from e # check out the specific ref given by the user if ref is not None: - # check out ref as it has not been done yet - for line in execute_cmd( - ["git", "checkout", ref], cwd=output_dir, capture=yield_output - ): - yield line hash = check_ref(ref, output_dir) if hash is None: self.log.error( diff --git a/tests/conftest.py b/tests/conftest.py index eefe4fef..a8a2ac34 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -145,6 +145,10 @@ def repo_with_submodule(): submod_sha1_b = _get_sha1(git_b_dir) _add_content_to_git(git_b_dir) + # create a new branch in the parent without any submodule + subprocess.check_call( + ["git", "checkout", "-b", "branch-without-submod"], cwd=git_a_dir + ) # create a new branch in the parent to add the submodule subprocess.check_call( ["git", "checkout", "-b", "branch-with-submod"], cwd=git_a_dir diff --git a/tests/unit/contentproviders/test_git.py b/tests/unit/contentproviders/test_git.py index d5532009..3957a95f 100644 --- a/tests/unit/contentproviders/test_git.py +++ b/tests/unit/contentproviders/test_git.py @@ -23,6 +23,18 @@ def test_submodule_clone(repo_with_submodule): """Test git clone containing a git submodule.""" upstream, expected_sha1_upstream, expected_sha1_submod = repo_with_submodule + # check that checking out a branch where there are no submodule + # indeed doesn't get any submodule, even though they are in master + with TemporaryDirectory() as clone_dir2: + submod_dir = os.path.join(clone_dir2, "submod") # set by fixture + spec = {"repo": upstream, "ref": "branch-without-submod"} + git_content = Git() + for _ in git_content.fetch(spec, clone_dir2): + pass + + assert os.path.exists(os.path.join(clone_dir2, "test")) + assert not os.path.exists(os.path.join(submod_dir, "test")) + with TemporaryDirectory() as clone_dir: submod_dir = os.path.join(clone_dir, "submod") # set by fixture spec = {"repo": upstream}