Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Deprecate default of Git.show(strip_newline_in_stdout=False)#1948

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
SonOfLilit wants to merge3 commits intogitpython-developers:main
base:main
Choose a base branch
Loading
fromSonOfLilit:main
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletionsgit/cmd.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1210,6 +1210,14 @@ def execute(
if self.GIT_PYTHON_TRACE and (self.GIT_PYTHON_TRACE != "full" or as_process):
_logger.info(" ".join(redacted_command))

if strip_newline_in_stdout and command[:2] == ["git", "show"]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

"git" shouldn't be hard-coded, and I am pretty sure there is a variable for this somewhere.

warnings.warn(
"Git.show() has strip_newline_in_stdout=True by default, which probably isn't what you want and will "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
"Git.show() has strip_newline_in_stdout=True by default, which probably isn't what you want andwill "
"Git.show() has strip_newline_in_stdout=True by default, which probably isn't what you want andmay "

"change in a future version. It is recommended to use Git.show(..., strip_newline_in_stdout=False)",
DeprecationWarning,
stacklevel=1,
)

# Allow the user to have the command executed in their working dir.
try:
cwd = self._working_dir or os.getcwd() # type: Union[None, str]
Expand Down
2 changes: 1 addition & 1 deletiontest/test_diff.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -51,7 +51,7 @@ def _assert_diff_format(self, diffs):
@with_rw_directory
def test_diff_with_staged_file(self, rw_dir):
# SET UP INDEX WITH MULTIPLE STAGES
r = Repo.init(rw_dir)
r = Repo.init(rw_dir, initial_branch="master")
fp = osp.join(rw_dir, "hello.txt")
with open(fp, "w") as fs:
fs.write("hello world")
Expand Down
16 changes: 13 additions & 3 deletionstest/test_repo.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1193,7 +1193,7 @@ def test_remote_method(self):
@with_rw_directory
def test_empty_repo(self, rw_dir):
"""Assure we can handle empty repositories"""
r = Repo.init(rw_dir, mkdir=False)
r = Repo.init(rw_dir, mkdir=False, initial_branch="master")
# It's ok not to be able to iterate a commit, as there is none.
self.assertRaises(ValueError, r.iter_commits)
self.assertEqual(r.active_branch.name, "master")
Expand DownExpand Up@@ -1352,7 +1352,7 @@ def test_git_work_tree_env(self, rw_dir):

@with_rw_directory
def test_rebasing(self, rw_dir):
r = Repo.init(rw_dir)
r = Repo.init(rw_dir, initial_branch="master")
fp = osp.join(rw_dir, "hello.txt")
r.git.commit(
"--allow-empty",
Expand All@@ -1377,13 +1377,23 @@ def test_rebasing(self, rw_dir):

@with_rw_directory
def test_do_not_strip_newline_in_stdout(self, rw_dir):
r = self.create_repo_commit_hello_newline(rw_dir)
self.assertEqual(r.git.show("HEAD:hello.txt", strip_newline_in_stdout=False), "hello\n")

def create_repo_commit_hello_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_in_stdout=False), "hello\n")
return r

@with_rw_directory
def test_warn_when_strip_newline_in_stdout(self, rw_dir):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Let's put the additional assertion done intest_do_not_strip_newline_in_stdout here so that it's clearer what's under test: The deprecation warning ifgit show is used andstrip_newline_in_stdout=True. This way,test_do_not_strip_newline_in_stdout can be removed. I'd also hope that the assertion then can be changed to use the default value forstrip_newline_in_stdout, which is probablyTrue, the cause of the confusion in this case.

r = self.create_repo_commit_hello_newline(rw_dir)
with pytest.warns(DeprecationWarning):
self.assertEqual(r.git.show("HEAD:hello.txt", strip_newline_in_stdout=True), "hello")

@pytest.mark.xfail(
sys.platform == "win32",
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp