Getting the name of source branch when merging

I’m encountring again a problem and a challange regarding the sourcebranch name in the pipeline when merging.
according to some other posts on the forum it seems inpossible.

the most usefull one was this:

I have tried:
but both return me ‘main’.

I need the name because i’m doing som thing behind the scenes where I use amend.
Currently everything is working in a standard commit or branch pipeline, but it doesn’t work when I do a merge.

What I actually need is all the commits from the source branch (preferably the commit id’s)

I’m trying to do that with git log --no-merges sourcebranchname ^main

If there is an alternative like getting the commits and writing them to a file, i’m all ears.
besides that is there another option? I could use the same git log command on the main branch but i think that would be very difficult.

For MR commits you can get the name from $CI_COMMIT_MESSAGE which is usually in format Merge branch 'source_branch' into 'main' ...

howly sh*t I didn’t tought of that. currently I am working with the commit id since the commit of the merge gives me the same information, however that it does depend on the project settings.