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

Git.clone change folder to target one #14063

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion conan/tools/scm/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ def clone(self, url, target="", args=None):
url = url.replace("\\", "/") # Windows local directory
mkdir(self.folder)
self._conanfile.output.info("Cloning git repo")
self.run('clone "{}" {} {}'.format(url, " ".join(args), target))
target_path = f'"{target}"' if target else "" # quote in case there are spaces in path
self.run('clone "{}" {} {}'.format(url, " ".join(args), target_path))

def fetch_commit(self, url, commit):
"""
Expand Down
43 changes: 43 additions & 0 deletions conans/test/functional/tools/scm/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,49 @@ def test_clone_checkout(self):
assert c.load("source/src/myfile.h") == "myheader!"
assert c.load("source/CMakeLists.txt") == "mycmake"

def test_clone_target(self):
# Clone to a different target folder
# https://github.com/conan-io/conan/issues/14058
conanfile = textwrap.dedent("""
import os
from conan import ConanFile
from conan.tools.scm import Git
from conan.tools.files import load

class Pkg(ConanFile):
name = "pkg"
version = "0.1"

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

def source(self):
# Alternative, first defining the folder
# git = Git(self, "target")
# git.clone(url="{url}", target=".")
# git.checkout(commit="{commit}")

git = Git(self)
git.clone(url="{url}", target="tar get") # git clone url target
git.folder = "tar get" # cd target
git.checkout(commit="{commit}") # git checkout commit

self.output.info("MYCMAKE: {{}}".format(load(self, "tar get/CMakeLists.txt")))
self.output.info("MYFILE: {{}}".format(load(self, "tar get/src/myfile.h")))
""")
folder = os.path.join(temp_folder(), "myrepo")
url, commit = create_local_git_repo(files={"src/myfile.h": "myheader!",
"CMakeLists.txt": "mycmake"}, folder=folder)
# This second commit will NOT be used, as I will use the above commit in the conanfile
save_files(path=folder, files={"src/myfile.h": "my2header2!"})
git_add_changes_commit(folder=folder)

c = TestClient()
c.save({"conanfile.py": conanfile.format(url=url, commit=commit)})
c.run("create .")
assert "pkg/0.1: MYCMAKE: mycmake" in c.out
assert "pkg/0.1: MYFILE: myheader!" in c.out


@pytest.mark.tool("git")
class TestGitShallowClone:
Expand Down