Skip to content

Commit

Permalink
Merge pull request #1933 from cardoeng/main
Browse files Browse the repository at this point in the history
fix: fix incoherent beginning whitespace
  • Loading branch information
Byron authored Jun 18, 2024
2 parents 4d07031 + 97fad9c commit 4c21e51
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion git/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ def _handle_diff_line(lines_bytes: bytes, repo: "Repo", index: DiffIndex["Diff"]
change_type: Lit_change_type = cast(Lit_change_type, _change_type[0])
score_str = "".join(_change_type[1:])
score = int(score_str) if score_str.isdigit() else None
path = path.strip()
path = path.strip("\n")
a_path = path.encode(defenc)
b_path = path.encode(defenc)
deleted_file = False
Expand Down
19 changes: 19 additions & 0 deletions test/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,3 +529,22 @@ def test_diff_patch_with_external_engine(self, rw_dir):
self.assertEqual(len(index_against_head), 1)
index_against_working_tree = repo.index.diff(None, create_patch=True)
self.assertEqual(len(index_against_working_tree), 1)

@with_rw_directory
def test_beginning_space(self, rw_dir):
# Create a file beginning by a whitespace
repo = Repo.init(rw_dir)
file = osp.join(rw_dir, " file.txt")
with open(file, "w") as f:
f.write("hello world")
repo.git.add(Git.polish_url(file))
repo.index.commit("first commit")

# Diff the commit with an empty tree
# and check the paths
diff_index = repo.head.commit.diff(NULL_TREE)
d = diff_index[0]
a_path = d.a_path
b_path = d.b_path
self.assertEqual(a_path, " file.txt")
self.assertEqual(b_path, " file.txt")

0 comments on commit 4c21e51

Please sign in to comment.