From 09d97746e23f01abece155867768b7018e9f5af5 Mon Sep 17 00:00:00 2001 From: Solviana Date: Wed, 13 Dec 2023 18:34:51 +0100 Subject: [PATCH] Fix dirty repo handling (conan-io#15261) --- conan/tools/scm/git.py | 2 +- conans/test/functional/tools/scm/test_git.py | 26 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/conan/tools/scm/git.py b/conan/tools/scm/git.py index 5f7e3fbe774..f80ca588285 100644 --- a/conan/tools/scm/git.py +++ b/conan/tools/scm/git.py @@ -103,7 +103,7 @@ def is_dirty(self): :return: True, if the current folder is dirty. Otherwise, False. """ - status = self.run(f"status . -s").strip() + status = self.run("status . --short --no-branch --untracked-files").strip() return bool(status) def get_url_and_commit(self, remote="origin"): diff --git a/conans/test/functional/tools/scm/test_git.py b/conans/test/functional/tools/scm/test_git.py index 73ed31cfd85..632cc5ccc23 100644 --- a/conans/test/functional/tools/scm/test_git.py +++ b/conans/test/functional/tools/scm/test_git.py @@ -179,6 +179,32 @@ def test_capture_remote_pushed_commit(self): assert "pkg/0.1: SCM COMMIT: {}".format(new_commit) in c.out assert "pkg/0.1: SCM URL: {}".format(url) in c.out + def test_capture_commit_modified_config(self): + """ + A clean repo with the status.branch git config set to on + Expected to not raise an error an return the commit and url + """ + folder = temp_folder() + url, commit = create_local_git_repo(files={"conanfile.py": self.conanfile}, folder=folder) + c = TestClient() + with c.chdir(folder): + c.run_command("git config --local status.branch true") + c.run("export .") + assert "pkg/0.1: SCM COMMIT: {}".format(commit) in c.out + assert "pkg/0.1: SCM URL: {}".format(url) in c.out + + def test_capture_commit_modified_config_untracked(self): + """ + A dirty repo with the showUntrackedFiles git config set to off. + Expected to throw an exception + """ + folder = temp_folder() + url, commit = create_local_git_repo(files={"conanfile.py": self.conanfile}, folder=folder) + c = TestClient() + with c.chdir(folder): + c.save(files={"some_header.h": "now the repo is dirty"}) + c.run_command("git config --local status.showUntrackedFiles no") + c.run("export .", assert_error=True) @pytest.mark.tool("git") class TestGitBasicClone: