File: test_reword.py

package info (click to toggle)
git-revise 0.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 344 kB
  • sloc: python: 2,505; makefile: 16
file content (51 lines) | stat: -rw-r--r-- 1,425 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# pylint: skip-file

import textwrap
from conftest import *


@pytest.mark.parametrize("target", ["HEAD", "HEAD~", "HEAD~~"])
@pytest.mark.parametrize("use_editor", [True, False])
def test_reword(repo, target, use_editor):
    bash(
        """
        echo "hello, world" > file1
        git add file1
        git commit -m "commit 1"
        echo "new line!" >> file1
        git add file1
        git commit -m "commit 2"
        echo "yet another line!" >> file1
        git add file1
        git commit -m "commit 3"
        """
    )

    message = textwrap.dedent(
        """\
        reword test

        another line
        """
    ).encode()

    old = repo.get_commit(target)
    assert old.message != message
    assert old.persisted

    if use_editor:
        with editor_main(["--no-index", "-e", target]) as ed:
            with ed.next_file() as f:
                assert f.startswith(old.message)
                f.replace_dedent(message)
    else:
        main(["--no-index", "-m", "reword test", "-m", "another line", target])

    new = repo.get_commit(target)
    assert old != new, "commit was modified"
    assert old.tree() == new.tree(), "tree is unchanged"
    assert old.parents() == new.parents(), "parents are unchanged"

    assert new.message == message, "message set correctly"
    assert new.persisted, "commit persisted to disk"
    assert new.author == old.author, "author is unchanged"