ci: warn when a PR moves text and its body names no old place

Open
#19 5 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
45/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
git, github-actions, shell
Domain
ci-cd, testing, tooling

Research direction

Start with the commit rules in CONTRIBUTING.md and the existing no-merge-commits check, then read tools/trace-decision/ for the repository’s script and test pattern. Prototype checks must inspect each PR commit from base to head, with tests that build a small repository and verify rename scores and moved-line detection across Linux, macOS, and Windows. Done means the check catches the specified mixed commits, warns for moved lines across files, and passes on the Git version used by CI.

Written by the indexing model from the issue text.

Description

type/ci
Problem to solve

Commits in CONTRIBUTING.md says: "Moves and rewrites go in different commits." Then git log --follow and git log -L can follow the text, and a reader sees what the rewrite changed. No check enforces this rule. A review must find a mixed commit, and a PR branch then needs a rewrite. #4 had such a commit, and a review found it.

When to write in docs/doc-rules.md says that a rule that a tool can check goes to the tool.

Proposal

A CI job checks each commit of a PR (base..head), like no-merge-commits. It has two levels:

  1. A rename with a change. git log --name-status -M gives a rename a similarity score. R100 is a pure move. A score below 100 means that the commit also changed the content. The job fails on it.
  2. A moved block with other changes. git diff --color-moved marks moved lines with their own colors. A commit with moved lines and other changed lines mixes a move and a rewrite. Proposal: the job fails when both are in the same file, and only warns when they are in different files.

The check goes into a script in tools/, with tests that build a small repo, like tools/trace-decision/.

More information

I tried both levels in a temporary repo with Git for Windows:

Commit Result
Rename only R100 doc.md moved.md
Rename and one changed line R086 moved.md moved2.md
Move a section in the file Only moved lines
Move a section and change one line Moved lines, 1 removed line, 2 added lines

For level 2, the prototype set fixed colors for color.diff.oldMoved, color.diff.newMoved, color.diff.old and color.diff.new, and counted the color codes in the output of git show --color=always --color-moved=plain.

The history of this repo has no rename with a score below 100.

Limits and choices for the maintainer:

  • Git marks a block as moved only when it is long enough, about 20 letters or digits. A short moved line counts as removed and added.
  • A section move often comes with link fixes in other files that point to the section. By the letter of the rule, these are rewrites. Level 2 only warns across files for this reason. The maintainer decides if the rule allows these fixes.
  • Level 2 reads colors from the Git output. The tests must show that this works on Linux, macOS and Windows, and with the Git version of CI.
  • A delete and an add below the rename threshold of Git (50%) are not paired as a rename. Level 1 does not see them, and git log --follow does not follow them either.
Dominant language
Shell
Stars
1
Forks
0
Avg merge
6h 59m
Merged PRs (30d)
26

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from c-w-z/commit-decision-record

All issues in c-w-z/commit-decision-record

Similar issues

More Shell/Bash issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.