trace-decision: find the commit inside a squash-merged pull request that changed a line

Open
#62 0 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
25/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
git, github, shell
Domain
tooling

Research direction

Read the trace-decision collector change in #56 and the decision in #54, then review the manual git fetch and git blame steps in this issue. The proposal is explicitly deferred until a real squash merge demonstrates the problem or a user finds the manual steps too slow; done would require mapping questioned lines from the squash commit to the pull request head and identifying the relevant commit.

Written by the indexing model from the issue text.

Description

type/feature
Problem to solve

After a squash merge, git blame finds only the squash commit. The commits inside the pull request are not in the Git history. GitHub keeps them in refs/pull/<number>/head, also after the head branch is deleted (tested in https://github.com/c-w-z/commit-decision-record/issues/49#issuecomment-7298506022).

The trace-decision collector finds the pull request of a squash commit and prints the messages of all its commits (#56). It does not tell which of those commits changed the lines of the question. #54 allows a reason for a choice inside a change to be in a commit of the pull request. In a pull request with many commits, each with its own Why, the reader must then read all messages and judge which one is about the lines.

With a merge commit, the commits inside the pull request stay in Git, and git blame already finds the commit that changed the lines.

Proposal

Do not build this now. This repository has no squash-merged pull request yet, so no case shows that the messages of all commits are not enough (C1 in #54).

Build it when one of these occurs:

  • trace-decision gives a wrong reason, or cannot choose a reason, because a squash-merged pull request has many commits with different reasons.
  • A user asks for the commit inside a squash-merged pull request that changed a line, and the manual steps below are too slow.

Possible design: fetch refs/pull/<number>/head, map the lines of the question from the squash commit to the head of the pull request, and run git blame there. The mapping is needed because GitHub applies the changes of the pull request onto the base branch at the merge, and the head of the pull request can be on an older base. Not tested: how often the line numbers differ.

Manual steps until then:

git fetch origin pull/<number>/head
git blame -L <start>,<end> FETCH_HEAD -- <file>

The line numbers in FETCH_HEAD can differ from the line numbers in the current file.

Version

c304b28

More information
  • Decision: #54
  • Collector change: #56
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.