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: Correct test #11573

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 10 additions & 9 deletions conans/test/functional/tools/scm/test_git.py
Expand Up @@ -474,40 +474,41 @@ class Pkg(ConanFile):
version = "0.1"

def export(self):
git = Git(self, os.path.dirname(self.recipe_folder))
git = Git(self, self.recipe_folder)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But your git repo is not the folder in which the conanfile.py lives, it is the parent folder. So the os.path.dirname() is necessary to use the Git repo folder.

url, commit = git.get_url_and_commit()
# We store the current url and commit in conandata.yml
update_conandata(self, {"sources": {"commit": commit, "url": url}})
self.output.info("URL: {}".format(url))
self.output.info("COMMIT: {}".format(commit))

def layout(self):
pass # self.folders.source = "source"
self.folders.source = "project"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or if not the source folder would be ., not project (as project only happens if the repo folder is the parent one)


def source(self):
assert "project" not in os.getcwd(), f"Current working directory contains 'self.folders.sources', {os.getcwd()}."
git = Git(self)
sources = self.conan_data["sources"]
url = sources["url"]
commit = sources["commit"]
git.clone(url=url, target=".")
git.checkout(commit=commit)
self.output.info("MYCMAKE: {}".format(load(self, "CMakeLists.txt")))
self.output.info("MYFILE: {}".format(load(self, "src/myfile.h")))
self.output.info("MYCMAKE: {}".format(load(self, "project/src/CMakeLists.txt")))
self.output.info("MYFILE: {}".format(load(self, "project/src/myfile.h")))
""")

def test_conanfile_subfolder(self):
"""
A local repo, without remote, will have commit, but no URL
"""
c = TestClient()
c.save({"conan/conanfile.py": self.conanfile,
"CMakeLists.txt": "mycmakelists",
"src/myfile.h": "myheader"})
c.save({"project/conanfile.py": self.conanfile,
"project/CMakeLists.txt": "mycmakelists",
"project/src/myfile.h": "myheader"})
commit = c.init_git_repo()
c.run("export conan")
c.run("export project")
assert "pkg/0.1: COMMIT: {}".format(commit) in c.out
assert "pkg/0.1: URL: {}".format(c.current_folder.replace("\\", "/")) in c.out

c.run("create conan")
c.run("create project")
assert "pkg/0.1: MYCMAKE: mycmakelists" in c.out
assert "pkg/0.1: MYFILE: myheader" in c.out