more info in commit list

This commit is contained in:
Vaclav Tvrdik
2026-09-24 16:23:27 +02:00
parent fda13684d2
commit 120676e952
4 changed files with 109 additions and 6 deletions

View File

@@ -196,3 +196,43 @@ def test_commit_message_counts_one_file(monkeypatch):
commands.ACTIONS["commit"](sublime.View(), window, staged_state(True, False))
window.input[2]("one")
assert refreshed == ["committed 1 file"]
def commit(subject, files=1, insertions=1, deletions=0, short="abc1234"):
return git.Commit("a" * 40, short, "Ann", "2 days ago", subject, files, insertions, deletions)
def test_commit_items_show_totals_before_the_hash():
plural, single, merge = commands.commit_items(
[
commit("fix the parser", 23, 210, 0, "fda1368"),
commit("tweak", 1, 1, 2, "d45a250"),
commit("merge branch 'side'", None, None, None, "beef123"),
]
)
assert plural.annotation == "23 files changed -0 +210 fda1368"
assert single.annotation == "1 file changed -2 +1 d45a250"
# no diffstat for a merge, so the row falls back to the hash alone
assert merge.annotation == "beef123"
assert plural.trigger == "fix the parser" and plural.details == "Ann · 2 days ago"
def test_long_subject_is_clipped_to_clear_the_annotation():
long_subject = "a subject that runs on and on " * 6
item = commands.commit_items([commit(long_subject, 3, 9, 4)])[0]
assert item.trigger.endswith("..") and item.trigger[:-2] == long_subject[: len(item.trigger) - 2]
# the clipped subject plus the annotation fit the row, leaving the totals and hash readable
assert len(item.trigger) + len(item.annotation) <= commands.COMMIT_ROW_WIDTH
# a subject that already fits is left alone
assert commands.commit_items([commit("short one")])[0].trigger == "short one"
def test_commit_items_keep_a_readable_subject_when_the_annotation_is_huge():
# an annotation long enough to eat the whole row: the subject still keeps its floor
item = commands.commit_items([commit("x" * 200, 999999, 999999, 999999, "a" * 90)])[0]
assert len(item.trigger) == commands.MIN_SUBJECT_WIDTH and item.trigger.endswith("..")
def test_commit_items_fall_back_for_an_empty_subject():
assert commands.commit_items([commit("")])[0].trigger == "(no subject)"

View File

@@ -109,6 +109,37 @@ def test_commits(repo):
assert info.sha == commits[0].sha
def test_recent_commits_carry_shortstat_totals(repo):
write(repo, "new.py", "one\ntwo\n")
sh(repo, "add", "-A")
sh(repo, "commit", "-q", "-m", "added a file")
write(repo, "a.py", "x\n") # 6 lines become 1
write(repo, "b.txt", "y\n") # 1 line becomes 1
sh(repo, "commit", "-q", "-am", "changed two files")
newest, added, initial = git.recent_commits(repo, 3)
assert (newest.files, newest.insertions, newest.deletions) == (2, 2, 7)
# a pure addition: git omits the deletions clause entirely, which reads as zero, not unknown
assert (added.files, added.insertions, added.deletions) == (1, 2, 0)
assert initial.subject == "initial" and initial.files == 3
def test_commits_without_a_diffstat_report_no_totals(repo):
sh(repo, "commit", "-q", "--allow-empty", "-m", "empty")
sh(repo, "checkout", "-q", "-b", "side")
write(repo, "s.py", "s\n")
sh(repo, "add", "-A")
sh(repo, "commit", "-q", "-m", "on the side")
sh(repo, "checkout", "-q", "main")
sh(repo, "merge", "-q", "--no-ff", "side", "-m", "merge side")
totals = {c.subject: (c.files, c.insertions, c.deletions) for c in git.recent_commits(repo, 5)}
# git log prints no diffstat for either, so the totals stay unknown rather than a false zero
assert totals["merge side"] == (None, None, None)
assert totals["empty"] == (None, None, None)
assert totals["on the side"] == (1, 1, 0)
def test_no_head_repo(tmp_path):
repo = str(tmp_path)
sh(repo, "init", "-q")