Skip to content

Commit

Permalink
Updated to use maxsplit=1 (#17571)
Browse files Browse the repository at this point in the history
* Updated to use maxsplit=1

* Add tests, unquote paths with spaces

---------

Co-authored-by: Abril Rincón Blanco <[email protected]>
  • Loading branch information
maitrey and AbrilRBS authored Jan 14, 2025
1 parent 1ed9195 commit 8ea8174
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion conan/tools/scm/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions test/functional/tools/scm/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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"})
Expand Down

0 comments on commit 8ea8174

Please sign in to comment.