Action does not push branches: Invalid branch name
Thanks for creating this action. For some of the repos I mirrored I get an error like this:
remote: GitLab: You cannot create a branch with an invalid name.
! [remote rejected] upstream/HEAD -> HEAD (pre-receive hook declined)
The error is quite inconsistent and it sometimes works on one of the consecutive runs of the pipeline. I looked into it and pushed refs individually. As far as I understand it, it sometimes has a symbolic ref upstream that it wants to push and this is the reason it fails.
I was able to fix the problem by recreating the functionality checking for non-symbolic refs:
# Push only non-symbolic branches
- |
if git for-each-ref refs/remotes/upstream| grep -q .; then
branch_refs=$(git for-each-ref --format='%(refname) %(objecttype)' refs/remotes/upstream | grep ' commit$' | cut -d' ' -f1)
else
branch_refs=" "
fi
# Push only non-symbolic tags
- |
if git for-each-ref refs/tags | grep -q .; then
tag_refs=$(git for-each-ref --format='%(refname) %(objecttype)' refs/tags | grep ' tag$' | cut -d' ' -f1)
else
tag_refs=""
echo "No tags found"
fi
- |
for ref in $branch_refs $tag_refs; do
if [[ "$ref" == refs/remotes/upstream/* ]]; then
shortname=${ref#refs/remotes/upstream/}
target_ref="refs/heads/$shortname"
echo "Pushing branch $ref -> $target_ref"
elif [[ "$ref" == refs/tags/* ]]; then
shortname=${ref#refs/tags/}
target_ref="refs/tags/$shortname"
echo "Pushing tag $ref -> $target_ref"
else
echo "Skipping unknown ref $ref"
continue
fi
if git push origin "$ref:$target_ref" --force; then
echo "✅ Success: $short name"
else
echo "❌ Failed: $shortname"
failed=1
fi
echo "--------------------------"
done
if [ "$failed" -ne 0 ]; then
echo "One or more pushes failed."
exit 1
fi
Has anyone else seen this error or has any other idea on how to fix this?
Edited by Julian Rösner