Find MR for given commit
Description
It's fairly difficult to find a branch and associated MR for a given commit. If one of the StackOverflow git-fu snippets is unable to locate the branch, my approach is usually to filter MRs by the author of the commit and looks for around that date or search for keywords based on the commit message which is very tedious and not fool-proof(MR could be authored by someone else).
The following are a few scenarios where things fell short. Really curious what people are currently doing to accomplish the same thing
Trying to use the commit page:
- Notice how commit
6b762b9af7dcb09cbd4c5a3eee1164e31255a7a3
is in MR: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/9140/commits which is using branch27963-tooltips-jobs
- Visit the commit https://gitlab.com/gitlab-org/gitlab-ce/commit/6b762b9af7dcb09cbd4c5a3eee1164e31255a7a3
- Expand the branch/tag list
- Notice how the branch the commit was introduced in is not listed,
27963-tooltips-jobs
Note: The branch is listed until the MR is merged. Only branches that still have open MRs are listed. I assume because the branch is deleted when the MR is merged.
Trying this copy-pasta inspired by http://stackoverflow.com/a/17819027/796832 works for 6b762b9af7dcb09cbd4c5a3eee1164e31255a7a3
and 2895937c48871b35f6a54684dc27d1de4ad3a1ad
in https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/9140/commits
git config --add remote.origin.fetch +refs/merge-requests/*/head:refs/remotes/origin/merge-requests/*
git fetch origin
git describe --all --contains 6b762b9af7dcb09cbd4c5a3eee1164e31255a7a3
# -> remotes/origin/27963-tooltips-jobs~1
git describe --all --contains 2895937c48871b35f6a54684dc27d1de4ad3a1ad
remotes/origin/merge-requests/9140~1
But unfortunately this doesn't seem to work for everything
git config --add remote.origin.fetch +refs/merge-requests/*/head:refs/remotes/origin/merge-requests/*
git fetch origin
git describe --all --contains 78874519db2ca2f18a2fbca5fe070292e521d0c1
# -> tags/v8.17.0.pre~55^2~2 d
Even though the ref is available in the local repository confirmed by:
git show-ref | grep merge-requests/8480
# -> 061bb6eb6ed0ca6be3c571b3fcfd14a6f9729205 refs/remotes/origin/merge-requests/8480
Proposal
The best solution is to link directly to the MRs associated with the commit directly on the commit page.
A step in that direction is to keep the branch that introduced the commit listed but also sort by oldest to newest so it's easy to tell which is directly associated. Could add a slashed branch icon to show it is not available.