Developer tools dump stack traces, exit codes, and jargon. Figuring out *what to do next* often means searching the same Stack Overflow answers again.
| 1 | """Git rule tests.""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | import pytest |
| 6 | |
| 7 | from why_failed.matcher import analyze |
| 8 | |
| 9 | CASES = [ |
| 10 | ("fatal: not a git repository", "git.not_repository"), |
| 11 | ("nothing to commit, working tree clean", "git.nothing_to_commit"), |
| 12 | ("Automatic merge failed; fix conflicts and then commit", "git.merge_conflict"), |
| 13 | ("! [rejected] non-fast-forward", "git.non_fast_forward"), |
| 14 | ("fatal: Authentication failed for 'https://github.com/x/y.git'", "git.authentication_failed"), |
| 15 | ("remote: Repository not found.\nfatal: repository 'https://github.com/x/y.git' not found", "git.remote_not_found"), |
| 16 | ("You are in 'detached HEAD' state.", "git.detached_head"), |
| 17 | ("Please commit your changes or stash them before you switch branches.", "git.uncommitted_changes"), |
| 18 | ("error: failed to push some refs to 'origin'", "git.failed_to_push"), |
| 19 | ("fatal: A branch named 'feature' already exists.", "git.branch_already_exists"), |
| 20 | ("Your branch and 'origin/main' have diverged", "git.diverged_branches"), |
| 21 | ] |
| 22 | |
| 23 | |
| 24 | @pytest.mark.parametrize("text,rule_id", CASES) |
| 25 | def test_git_rules(text: str, rule_id: str) -> None: |
| 26 | result = analyze(text) |
| 27 | assert result.match is not None |
| 28 | assert result.match.rule_id == rule_id |