diff options
| author | Hiroki Tokunaga <tokusan441@gmail.com> | 2022-04-06 23:08:36 +0900 |
|---|---|---|
| committer | Hiroki Tokunaga <tokusan441@gmail.com> | 2022-04-06 23:08:36 +0900 |
| commit | e4360aea32aad11bf3c54b0dc0a6cabb21b5e687 (patch) | |
| tree | 5d8092a2fbfeef22e70953ed70753ff4bb603435 /test | |
| parent | 0b33576f8e7add5671f8927dff228e7f92eec076 (diff) | |
| download | gitpython-e4360aea32aad11bf3c54b0dc0a6cabb21b5e687.tar.gz | |
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.
Diffstat (limited to 'test')
| -rw-r--r-- | test/test_repo.py | 10 |
1 files changed, 10 insertions, 0 deletions
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') |
