Skip to content

Commit

Permalink
scm dirty fail (#12267)
Browse files Browse the repository at this point in the history
  • Loading branch information
czoido authored Oct 7, 2022
1 parent f1f0d86 commit f12a597
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
5 changes: 5 additions & 0 deletions conans/client/cmd/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ def calc_revision(scoped_output, path, manifest, revision_mode):
"'{}'".format(revision_mode, path)
raise ConanException("{}: {}".format(error_msg, exc))

with chdir(path):
if bool(check_output_runner('git status -s').strip()):
raise ConanException("Can't have a dirty repository using revision_mode='scm' and doing"
" 'conan export', please commit the changes and run again.")

revision = rev_detected

scoped_output.info("Using git commit as the recipe revision: %s" % revision)
Expand Down
15 changes: 7 additions & 8 deletions conans/test/functional/revisions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,23 +806,22 @@ def test_upload_no_overwrite_packages(self):

class SCMRevisions(unittest.TestCase):

@pytest.mark.xfail(reason="reconsider this case for Conan 2.0")
def test_auto_revision_even_without_scm_git(self):
"""Even without using the scm feature, the revision is detected from repo.
Also while we continue working in local, the revision doesn't change, so the packages
can be found"""
"""
Can't do conan create/export with uncommited changes if using revision_mode=scm
"""
ref = RecipeReference.loads("lib/1.0@conan/testing")
client = TurboTestClient()
conanfile = GenConanfile().with_revision_mode("scm")
commit = client.init_git_repo(files={"file.txt": "hey"}, origin_url="http://myrepo.git")
commit = client.init_git_repo(files={"file.txt": "hey", "conanfile.py": str(conanfile)},
origin_url="http://myrepo.git")
client.create(ref, conanfile=conanfile)
self.assertEqual(client.recipe_revision(ref), commit)

# Change the conanfile and make another create, the revision should be the same
client.save({"conanfile.py": str(conanfile.with_build_msg("New changes!"))})
client.create(ref, conanfile=conanfile)
self.assertEqual(client.recipe_revision(ref), commit)
self.assertIn("New changes!", client.out)
client.create(ref, conanfile=conanfile, assert_error=True)
self.assertIn("Can't have a dirty repository using revision_mode='scm' and doing", client.out)

def test_auto_revision_without_commits(self):
"""If we have a repo but without commits, it has to fail when the revision_mode=scm"""
Expand Down

0 comments on commit f12a597

Please sign in to comment.