Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add newline at the end of the diff file #1473

Merged
merged 3 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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