-
Notifications
You must be signed in to change notification settings - Fork 993
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New
revision_mode = scm_folder
for monorepos (#13562)
* changing revision_mode=scm base folder * wip
- Loading branch information
1 parent
5cf93ae
commit e33561a
Showing
3 changed files
with
54 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,66 @@ | ||
import textwrap | ||
import unittest | ||
import os | ||
|
||
import pytest | ||
|
||
from conans.model.recipe_ref import RecipeReference | ||
from conans.test.assets.genconanfile import GenConanfile | ||
from conans.test.utils.scm import git_add_changes_commit | ||
from conans.test.utils.tools import TestClient | ||
|
||
|
||
class ExportMetadataTest(unittest.TestCase): | ||
conanfile = textwrap.dedent(""" | ||
from conan import ConanFile | ||
@pytest.mark.tool("git") | ||
class TestRevisionModeSCM: | ||
|
||
class Lib(ConanFile): | ||
revision_mode = "{revision_mode}" | ||
""") | ||
def test_revision_mode_scm(self): | ||
t = TestClient() | ||
conanfile = str(GenConanfile().with_class_attribute('revision_mode = "scm"')) | ||
commit = t.init_git_repo({'conanfile.py': conanfile}) | ||
|
||
summary_hash = "bfe8b4a6a2a74966c0c4e0b34705004a" | ||
t.run(f"export . --name=pkg --version=0.1") | ||
|
||
@pytest.mark.tool("git") | ||
def test_revision_mode_scm(self): | ||
ref = RecipeReference.loads("pkg/0.1") | ||
latest_rev = t.cache.get_latest_recipe_reference(ref) | ||
assert latest_rev.revision == commit | ||
|
||
# Now it will fail if dirty | ||
t.save({"conanfile.py": conanfile + "\n#comment"}) | ||
t.run(f"export . --name=pkg --version=0.1", assert_error=True) | ||
assert "Can't have a dirty repository using revision_mode='scm' and doing" in t.out | ||
# Commit to fix | ||
commit2 = git_add_changes_commit(t.current_folder, msg="fix") | ||
t.run(f"export . --name=pkg --version=0.1") | ||
latest_rev = t.cache.get_latest_recipe_reference(ref) | ||
assert latest_rev.revision == commit2 | ||
|
||
def test_revision_mode_scm_subfolder(self): | ||
""" emulates a mono-repo with 2 subprojects, when a change is done in a subproject | ||
it gets a different folder commit | ||
""" | ||
t = TestClient() | ||
commit = t.init_git_repo({'conanfile.py': self.conanfile.format(revision_mode="scm")}) | ||
conanfile = str(GenConanfile().with_class_attribute('revision_mode = "scm_folder"')) | ||
commit = t.init_git_repo({'pkga/conanfile.py': conanfile, | ||
'pkgb/conanfile.py': conanfile}) | ||
|
||
ref = RecipeReference.loads("name/version@user/channel") | ||
t.run(f"export . --name={ref.name} --version={ref.version} --user={ref.user} --channel={ref.channel}") | ||
t.save({"pkgb/conanfile.py": conanfile + "\n#comment"}) | ||
commit_b = git_add_changes_commit(os.path.join(t.current_folder, "pkgb"), msg="fix") | ||
|
||
# pkga still gets the initial commit, as it didn't change its contents | ||
t.run(f"export pkga --name=pkga --version=0.1") | ||
ref = RecipeReference.loads("pkga/0.1") | ||
latest_rev = t.cache.get_latest_recipe_reference(ref) | ||
assert latest_rev.revision == commit | ||
|
||
self.assertEqual(latest_rev.revision, commit) | ||
# but pkgb will get the commit of the new changed folder | ||
t.run(f"export pkgb --name=pkgb --version=0.1") | ||
ref = RecipeReference.loads("pkgb/0.1") | ||
latest_rev = t.cache.get_latest_recipe_reference(ref) | ||
assert latest_rev.revision == commit_b | ||
|
||
def test_auto_revision_without_commits(self): | ||
"""If we have a repo but without commits, it has to fail when the revision_mode=scm""" | ||
t = TestClient() | ||
t.run_command('git init .') | ||
t.save({"conanfile.py": GenConanfile("lib", "0.1").with_revision_mode("scm")}) | ||
t.run("export .", assert_error=True) | ||
# It errors, because no commits yet | ||
assert "Cannot detect revision using 'scm' mode from repository" in t.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters