Skip to content

Commit

Permalink
add newline at the end of the diff file (#1473)
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksanderWWW authored Sep 26, 2023
1 parent 7404e86 commit 31b13c7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [UNRELEASED] neptune 1.7.1

### Fixes
- Add newline at the end of generated `.patch` while tracking uncommitted changes ([#1473](https://github.com/neptune-ai/neptune-client/pull/1473))

## neptune 1.7.0

### Features
Expand Down
7 changes: 6 additions & 1 deletion src/neptune/internal/utils/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,12 @@ def get_diff(repo: "git.Repo", commit_ref: str) -> Optional[str]:
from git.exc import GitCommandError

try:
return repo.git.diff(commit_ref, index=False)
diff = repo.git.diff(commit_ref, index=False)

# add a newline at the end (required to be a valid `patch` file)
if diff[-1] != "\n":
diff += "\n"
return diff
except GitCommandError:
return
except ImportError:
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/neptune/new/internal/utils/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ def test_get_uncommitted_changes(mock_get_sha, mock_repo):
# then
assert mock_repo.git.diff.call_count == 2
assert mock_get_sha.call_count == 1
assert uncommitted_changes.diff_head == "some_diff"
assert uncommitted_changes.diff_head == "some_diff\n"
assert uncommitted_changes.upstream_sha == "test_sha"
assert uncommitted_changes.diff_upstream == "some_diff"
assert uncommitted_changes.diff_upstream == "some_diff\n"


@patch("git.Repo")
Expand Down

0 comments on commit 31b13c7

Please sign in to comment.