From 48517c71092b39cfe867924fa923404ab529971a Mon Sep 17 00:00:00 2001 From: maitrey Date: Tue, 14 Jan 2025 14:09:50 +0100 Subject: [PATCH 1/2] Updated to use maxsplit=1 --- conan/tools/scm/git.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conan/tools/scm/git.py b/conan/tools/scm/git.py index f3578e2c9ff..525bb5f5cd4 100644 --- a/conan/tools/scm/git.py +++ b/conan/tools/scm/git.py @@ -137,7 +137,7 @@ def is_dirty(self, repository=False): return bool(status) # Parse the status output, line by line, and match it with "_excluded" lines = [line.strip() for line in status.splitlines()] - lines = [line.split()[1] for line in lines if line] + lines = [line.split(maxsplit=1)[1] for line in lines if line] lines = [line for line in lines if not any(fnmatch.fnmatch(line, p) for p in self._excluded)] self._conanfile.output.debug(f"Filtered git status: {lines}") return bool(lines) From 3176230ea2918b1352a245d85d0416fc4054a539 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abril=20Rinc=C3=B3n=20Blanco?= Date: Tue, 14 Jan 2025 15:08:11 +0100 Subject: [PATCH 2/2] Add tests, unquote paths with spaces --- conan/tools/scm/git.py | 4 +++- test/functional/tools/scm/test_git.py | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/conan/tools/scm/git.py b/conan/tools/scm/git.py index 525bb5f5cd4..ee259655bf5 100644 --- a/conan/tools/scm/git.py +++ b/conan/tools/scm/git.py @@ -137,7 +137,9 @@ def is_dirty(self, repository=False): return bool(status) # Parse the status output, line by line, and match it with "_excluded" lines = [line.strip() for line in status.splitlines()] - lines = [line.split(maxsplit=1)[1] for line in lines if line] + # line is of the form STATUS PATH, get the path by splitting + # (Taking into account that STATUS is one word, PATH might be many) + lines = [line.split(maxsplit=1)[1].strip('"') for line in lines if line] lines = [line for line in lines if not any(fnmatch.fnmatch(line, p) for p in self._excluded)] self._conanfile.output.debug(f"Filtered git status: {lines}") return bool(lines) diff --git a/test/functional/tools/scm/test_git.py b/test/functional/tools/scm/test_git.py index 7c8df169731..d4211ec6835 100644 --- a/test/functional/tools/scm/test_git.py +++ b/test/functional/tools/scm/test_git.py @@ -26,7 +26,7 @@ class Pkg(ConanFile): version = "0.1" def export(self): - git = Git(self, self.recipe_folder, excluded=["myfile.txt", "mynew.txt"]) + git = Git(self, self.recipe_folder, excluded=["myfile.txt", "mynew.txt", "file with spaces.txt"]) commit = git.get_commit() repo_commit = git.get_commit(repository=True) url = git.get_remote_url() @@ -127,7 +127,8 @@ def test_git_excluded(self): c.run("export . -vvv") assert "pkg/0.1: DIRTY: False" in c.out c.save({"myfile.txt": "changed", - "mynew.txt": "new"}) + "mynew.txt": "new", + "file with spaces.txt": "hello"}) c.run("export .") assert "pkg/0.1: DIRTY: False" in c.out c.save({"other.txt": "new"})