Skip to content

getLocalRef can return the wrong ref when there are multiple branches with a similar name #90

@raidenhasegawa

Description

@raidenhasegawa

Behavior and Cause

When you have an action triggered by a push to a certain branch, say my_branch, and another similarly named branch exists, say another/my_branch, getLocalRef will return another/my_branch instead of my_branch as it shows up first in the list of matching refs pulled by getLocalRef:

const output = (await exec('git', ['show-ref', shortName], {ignoreReturnCode: true})).stdout 
const refs = output.split(/\r?\n/g) 
                   .map(l =>; l.match(/refs\/.*$/)?.[0] ?? '')
                   .filter(l =>; l !== '')

Prefixing with this format{some_prefix}/{branch_name} causes some trouble with show-ref as they show up as refs for {branch_name}. Annoyingly, some bots will autogenerate branches with this pattern, e.g., changeset actions has a bot that does such a thing (see example below).

Example

This was caused by the changeset bot:
image

Comment

I'm not sure what the right solution is here, I'd be happy to work together to figure it out but I'm not an expert in actions or git in general. It does appear to be an undesirable behavior that can get by you rather silently. I think you can solve this in some cases by explicitly passing the ref in the inputs but does it make sense to fail if say there remoteRef.length > 1 in getLocalRef?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions