From ee26afe65e8f9ebf11d7236fd3ee16a47f9b4fc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n=20Valles?= Date: Mon, 23 Mar 2020 10:22:51 -0600 Subject: [PATCH] git: quote filenames @ remind_to_track (#3315) Fix #3303 --- dvc/scm/git/__init__.py | 5 ++++- tests/unit/scm/test_scm.py | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/dvc/scm/git/__init__.py b/dvc/scm/git/__init__.py index 8f05ad029..e70d6f7b0 100644 --- a/dvc/scm/git/__init__.py +++ b/dvc/scm/git/__init__.py @@ -3,6 +3,7 @@ import logging import os import yaml +import shlex from funcy import cached_property from pathspec.patterns import GitWildMatchPattern @@ -321,11 +322,13 @@ class Git(Base): if not self.files_to_track: return + files = " ".join(shlex.quote(path) for path in self.files_to_track) + logger.info( "\n" "To track the changes with git, run:\n" "\n" - "\tgit add {files}".format(files=" ".join(self.files_to_track)) + "\tgit add {files}".format(files=files) ) def track_file(self, path): diff --git a/tests/unit/scm/test_scm.py b/tests/unit/scm/test_scm.py index 513653139..4fb590fc5 100644 --- a/tests/unit/scm/test_scm.py +++ b/tests/unit/scm/test_scm.py @@ -37,3 +37,9 @@ class TestScmContext(TestCase): self.assertEqual(0, self.scm_mock.reset_ignores.call_count) self.assertEqual(0, self.scm_mock.remind_to_track.call_count) + + +def test_remind_to_track(scm, caplog): + scm.files_to_track = ["fname with spaces.txt", "тест", "foo"] + scm.remind_to_track() + assert "git add 'fname with spaces.txt' 'тест' foo" in caplog.text