From 8ea8174d9bdb83b73c9c2f57dd86dfd9f831fef7 Mon Sep 17 00:00:00 2001 From: maitrey Date: Tue, 14 Jan 2025 16:30:03 +0100 Subject: [PATCH] Updated to use maxsplit=1 (#17571) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Updated to use maxsplit=1 * Add tests, unquote paths with spaces --------- Co-authored-by: Abril Rincón Blanco --- 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 f3578e2c9ff..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()[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"})