Skip to content

Commit 015b93b

Browse files
committed
Fix missing no-change message in -ie mode
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.
1 parent 45ec1c6 commit 015b93b

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

gitrevise/todo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ def parse(instr: str) -> StepKind:
4141
class Step:
4242
kind: StepKind
4343
commit: Commit
44-
message: Optional[bytes]
44+
message: bytes
4545

4646
def __init__(self, kind: StepKind, commit: Commit) -> None:
4747
self.kind = kind
4848
self.commit = commit
49-
self.message = None
49+
self.message = commit.message
5050

5151
@staticmethod
5252
def parse(repo: Repository, instr: str) -> Step:

tests/test_interactive.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import TYPE_CHECKING, Optional, Sequence
1+
from typing import TYPE_CHECKING, List, Optional, Sequence
22

33
import pytest
44

@@ -343,3 +343,22 @@ def test_interactive_reword(repo: Repository) -> None:
343343
assert prev_u.tree().entries[b"file2"] == curr.tree().entries[b"file2"]
344344
assert prev_u.tree().entries[b"file1"] == curr_uu.tree().entries[b"file1"]
345345
assert prev.tree().entries[b"file1"] == curr_u.tree().entries[b"file1"]
346+
347+
348+
@pytest.mark.parametrize("interactive_mode", ["-i", "-ie", "-e"])
349+
def test_no_changes(repo: Repository, interactive_mode: str) -> None:
350+
bash("git commit --allow-empty -m empty")
351+
old = repo.get_commit("HEAD")
352+
assert old.message == b"empty\n"
353+
354+
base = "--root" if interactive_mode != "-e" else "HEAD"
355+
356+
outputs: List[bytes] = []
357+
with editor_main([interactive_mode, base], stdout_stderr_out=outputs) as ed:
358+
with ed.next_file() as f:
359+
f.replace_dedent(f.indata)
360+
361+
normalized_outputs = [text.decode().replace("\r\n", "\n") for text in outputs]
362+
assert normalized_outputs == ["", "(warning) no changes performed\n"]
363+
new = repo.get_commit("HEAD")
364+
assert new.oid == old.oid

0 commit comments

Comments
 (0)