From 015b93bfad1e12324fadecd9d238c559d6995aea Mon Sep 17 00:00:00 2001 From: Andreas Nordal Date: Fri, 23 Jun 2023 22:10:01 +0200 Subject: [PATCH] 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. --- gitrevise/todo.py | 4 ++-- tests/test_interactive.py | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/gitrevise/todo.py b/gitrevise/todo.py index 08b312c..d56a8c6 100644 --- a/gitrevise/todo.py +++ b/gitrevise/todo.py @@ -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: diff --git a/tests/test_interactive.py b/tests/test_interactive.py index 94915e3..e92afc1 100644 --- a/tests/test_interactive.py +++ b/tests/test_interactive.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, Sequence +from typing import TYPE_CHECKING, List, Optional, Sequence import pytest @@ -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