Skip to content

Commit

Permalink
Fix missing no-change message in -ie mode
Browse files Browse the repository at this point in the history
This warning is nice to see,
but only worked in `-i` and `-e` mode, not in `-ie` mode:

    (warning) no changes performed

The Step.message was initialized to None instead of the old value,
causing unedited messages in message-edit mode to compare unequal.

This commit removes the optionality and thereby the possibility
for the problem.
It can also be solved by interpreting None as the old value
or resetting the new value to None if it is indifferent.
  • Loading branch information
anordal committed Jul 28, 2023
1 parent 45ec1c6 commit 015b93b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
4 changes: 2 additions & 2 deletions gitrevise/todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ def parse(instr: str) -> StepKind:
class Step:
kind: StepKind
commit: Commit
message: Optional[bytes]
message: bytes

def __init__(self, kind: StepKind, commit: Commit) -> None:
self.kind = kind
self.commit = commit
self.message = None
self.message = commit.message

@staticmethod
def parse(repo: Repository, instr: str) -> Step:
Expand Down
21 changes: 20 additions & 1 deletion tests/test_interactive.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import TYPE_CHECKING, Optional, Sequence
from typing import TYPE_CHECKING, List, Optional, Sequence

import pytest

Expand Down Expand Up @@ -343,3 +343,22 @@ def test_interactive_reword(repo: Repository) -> None:
assert prev_u.tree().entries[b"file2"] == curr.tree().entries[b"file2"]
assert prev_u.tree().entries[b"file1"] == curr_uu.tree().entries[b"file1"]
assert prev.tree().entries[b"file1"] == curr_u.tree().entries[b"file1"]


@pytest.mark.parametrize("interactive_mode", ["-i", "-ie", "-e"])
def test_no_changes(repo: Repository, interactive_mode: str) -> None:
bash("git commit --allow-empty -m empty")
old = repo.get_commit("HEAD")
assert old.message == b"empty\n"

base = "--root" if interactive_mode != "-e" else "HEAD"

outputs: List[bytes] = []
with editor_main([interactive_mode, base], stdout_stderr_out=outputs) as ed:
with ed.next_file() as f:
f.replace_dedent(f.indata)

normalized_outputs = [text.decode().replace("\r\n", "\n") for text in outputs]
assert normalized_outputs == ["", "(warning) no changes performed\n"]
new = repo.get_commit("HEAD")
assert new.oid == old.oid

0 comments on commit 015b93b

Please sign in to comment.