-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getLocalRef can return the wrong ref when there are multiple branches with a similar name #90
Comments
Hello, Thanks for reporting the issue. |
git show-ref will return all branches where end segment matches the input. This cause issues when there are both 'someBranch' and 'somePrefix/someBranch' branches. This fix ensures the correct ref is returned by explicitly matching segments after common parts (e.g. refs/heads).
Fix #90 getLocalRef() returns wrong ref
The fix turns out to be pretty simple. I change the code so it explicitly matches what follows after Please verify if it works for you now and reopen the issue if there is still some issue. |
This is great, @dorny. Just ran the action with v2.10.2 and this corrected the behavior I was seeing with v2.10.1. Thanks! |
So this worked well for me using a short name, but it does break when I use a fully qualified ref. I think that the filter logic here breaks down when I think that this can be fixed by modifying |
git show-ref will return all branches where end segment matches the input. This cause issues when there are both 'someBranch' and 'somePrefix/someBranch' branches. This fix ensures the correct ref is returned by explicitly matching segments after common parts (e.g. refs/heads).
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, sayanother/my_branch
,getLocalRef
will returnanother/my_branch
instead ofmy_branch
as it shows up first in the list of matching refs pulled bygetLocalRef
:Prefixing with this format
{some_prefix}/{branch_name}
causes some trouble withshow-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:

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 thereremoteRef.length > 1
ingetLocalRef
?The text was updated successfully, but these errors were encountered: