Skip to content

Commit a943fa3

Browse files
committed
deprecation warning for Git.show() w/o string_newline=False
1 parent 855befa commit a943fa3

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Diff for: git/cmd.py

+7
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,13 @@ def execute(
12101210
if self.GIT_PYTHON_TRACE and (self.GIT_PYTHON_TRACE != "full" or as_process):
12111211
_logger.info(" ".join(redacted_command))
12121212

1213+
if strip_newline_in_stdout and command[:2] == ["git", "show"]:
1214+
warnings.warn(
1215+
"Git.show() has strip_newline_in_stdout=True by default, which probably isn't what you want and will "
1216+
"change in a future version. It is recommended to use Git.show(..., strip_newline_in_stdout=False)",
1217+
DeprecationWarning
1218+
)
1219+
12131220
# Allow the user to have the command executed in their working dir.
12141221
try:
12151222
cwd = self._working_dir or os.getcwd() # type: Union[None, str]

Diff for: test/test_repo.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -1377,13 +1377,23 @@ def test_rebasing(self, rw_dir):
13771377

13781378
@with_rw_directory
13791379
def test_do_not_strip_newline_in_stdout(self, rw_dir):
1380+
r = self.create_repo_commit_hello_newline(rw_dir)
1381+
self.assertEqual(r.git.show("HEAD:hello.txt", strip_newline_in_stdout=False), "hello\n")
1382+
1383+
def create_repo_commit_hello_newline(self, rw_dir):
13801384
r = Repo.init(rw_dir)
13811385
fp = osp.join(rw_dir, "hello.txt")
13821386
with open(fp, "w") as fs:
13831387
fs.write("hello\n")
13841388
r.git.add(Git.polish_url(fp))
13851389
r.git.commit(message="init")
1386-
self.assertEqual(r.git.show("HEAD:hello.txt", strip_newline_in_stdout=False), "hello\n")
1390+
return r
1391+
1392+
@with_rw_directory
1393+
def test_warn_when_strip_newline_in_stdout(self, rw_dir):
1394+
r = self.create_repo_commit_hello_newline(rw_dir)
1395+
with pytest.warns(DeprecationWarning):
1396+
self.assertEqual(r.git.show("HEAD:hello.txt", strip_newline_in_stdout=True), "hello")
13871397

13881398
@pytest.mark.xfail(
13891399
sys.platform == "win32",

0 commit comments

Comments
 (0)