From e4360aea32aad11bf3c54b0dc0a6cabb21b5e687 Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Wed, 6 Apr 2022 23:08:36 +0900 Subject: feat(cmd): add the `strip_newline` flag This commit adds the `strip_newline` flag to the `Git.execute` method. When this flag is set to `True`, it will trim the trailing `\n`. The default value is `True` for backward compatibility. Setting it to `False` is helpful for, e.g., the `git show` output, especially with the binary file, as the missing `\n` may invalidate the file. --- test/test_repo.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test') diff --git a/test/test_repo.py b/test/test_repo.py index 6d617609..14339f57 100644 --- a/test/test_repo.py +++ b/test/test_repo.py @@ -1098,3 +1098,13 @@ class TestRepo(TestBase): except GitCommandError: pass self.assertEqual(r.currently_rebasing_on(), commitSpanish) + + @with_rw_directory + def test_do_not_strip_newline(self, rw_dir): + r = Repo.init(rw_dir) + fp = osp.join(rw_dir, 'hello.txt') + with open(fp, 'w') as fs: + fs.write("hello\n") + r.git.add(Git.polish_url(fp)) + r.git.commit(message="init") + self.assertEqual(r.git.show("HEAD:hello.txt", strip_newline=False), 'hello\n') -- cgit v1.2.1 From 49150e79c6f7a19a0d61a5ea6864b9ac140264ff Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Thu, 7 Apr 2022 10:04:19 +0900 Subject: chore: `s/strip_newline/&_in_stdout` --- test/test_repo.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/test_repo.py b/test/test_repo.py index 14339f57..c5b2680d 100644 --- a/test/test_repo.py +++ b/test/test_repo.py @@ -1100,11 +1100,11 @@ class TestRepo(TestBase): self.assertEqual(r.currently_rebasing_on(), commitSpanish) @with_rw_directory - def test_do_not_strip_newline(self, rw_dir): + def test_do_not_strip_newline_in_stdout(self, rw_dir): r = Repo.init(rw_dir) fp = osp.join(rw_dir, 'hello.txt') with open(fp, 'w') as fs: fs.write("hello\n") r.git.add(Git.polish_url(fp)) r.git.commit(message="init") - self.assertEqual(r.git.show("HEAD:hello.txt", strip_newline=False), 'hello\n') + self.assertEqual(r.git.show("HEAD:hello.txt", strip_newline_in_stdout=False), 'hello\n') -- cgit v1.2.1