Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

"glab mr for" returns 400 - ref is empty #736

Closed
eriknaslund opened this issue May 21, 2021 · 9 comments · Fixed by #900
Closed

"glab mr for" returns 400 - ref is empty #736

eriknaslund opened this issue May 21, 2021 · 9 comments · Fixed by #900
Labels
bug Something isn't working stale

Comments

@eriknaslund
Copy link

eriknaslund commented May 21, 2021

Description
The glab mr for <issue_id> command always returns a "ref is empty" for me. All other commands seem to work well as far as I can see.

Expected Behavior vs Actual Behavior
When issuing glab mr for <issue_id> I always get the following error message back:
"POST https://gitlab.com/api/v4/projects/repo/repository/branches: 400 {error: ref is empty}"

I would expect a merge request to be created.

Steps to Reproduce

So my first attempt started out like this, simply trying to create an MR for an issue.

$ glab issue create -t test -d description
- Creating issue in <repo>
#124 test (less than a minute ago)
 https://gitlab.com/<repo>/-/issues/124
 
$ glab issue view 124
open • opened by vterik less than a minute ago
test #124

  description
  
$ glab mr for 124
POST https://gitlab.com/api/v4/projects/<repo>/repository/branches: 400 {error: ref is empty}
POST https://gitlab.com/api/v4/projects/<repo>/repository/branches: 400 {error: ref is empty}

I can kinda see why that doesn't work, because I haven't created a branch yet. However it would be great to have better docs and error messaging here, or the ability to have glab create the branch for me. That's would closely mirror the behavior of the web UI.

However, I gave it a go and added the branch...

$ git checkout -b 124-test
...

# Did a minor change to a file.

$ git commit -m "124: Changing some text just to try glab."
...

$ git push --set-upstream origin 124-test
...

$ glab mr for 124
POST https://gitlab.com/api/v4/projects/<repo>/repository/branches: 400 {error: ref is empty}
POST https://gitlab.com/api/v4/projects/<repo>/repository/branches: 400 {error: ref is empty}
...

I was surprised by the fact that I still got the same error even though the branch now exists.
It's very likely that I'm just using it wrong, but I thought I'd post the issue just in case it's really a bug, or in case some one else does the same usage mistake as I did.

Your Environment
glab version 1.17.0 (2021-05-14)
OS: Manjaro 21.0.4

@eriknaslund eriknaslund added the bug Something isn't working label May 21, 2021
@idcmardelplata
Copy link

i have the same problem.

@profclems
Copy link
Owner

profclems commented Jun 7, 2021

Hi @Ekik and @idcmardelplata, I can't seem to reproduce this issue. I may need a little bit of information to be able to resolve this.
I tested against a repo on GitLab.com and gnome's self hosted instance and everything seems to work perfectly for me.

Are you using a self hosted GitLab instance? If yes, what version?

@eriknaslund
Copy link
Author

eriknaslund commented Jun 8, 2021

@profclems I too am using gitlab.com, so no difference there.

One thing I'm doing a bit differently than some others is that I use Gitlab Groups to Organize my projects.

This means my Git URLs look like this: [email protected]:GROUP_NAME/REPO_NAME.git.
Without groups they would look like [email protected]:USER_NAME/REPO_NAME.git instead.

It might be a bit far fetched, but I'm mentioning it anyways since I actually had issues with other projects / products before that didn't account for the usage of groups.

@zemzale
Copy link
Collaborator

zemzale commented Jun 15, 2021

I can't reproduce this too. Tried this with self-hosted and gitlab.com, for personal and group projects and it worked every time.

Are you still having this issue? Maybe there was an issue with the API itself (which also is far fetched, but since 2 people can't reproduce it 🤷‍♂️)

@eriknaslund
Copy link
Author

I'm still able to reproduce it, and here's some more info I managed to dig up.

Based on the fact that glab is POSTing to that particular URL leads me to believe it's trying to create a new branch for me.
See the docs here: https://docs.gitlab.com/ee/api/branches.html#create-repository-branch

# This does not work and gives a 404 because the "/" in the project ID isn't correctly URL encoded.
# I don't think this is what happens with glab, because there we're seeing a 400 BAD REQUEST.
curl --header "Authorization: Bearer SECRET" -X POST "https://gitlab.com/api/v4/projects/virtual-tourist/vt-guide/repository/branches?branch=newbranch&ref=master"

# Using any of these requests works fine.
# In the first case I've properly url-encoded the project ID, and in the second case I'm using the numeric one.
curl --header "Authorization: Bearer SECRET" -X POST "https://gitlab.com/api/v4/projects/virtual-tourist%2Fvt-guide/repository/branches?branch=newbranch&ref=master"
curl --header "Authorization: Bearer SECRET" -X POST "https://gitlab.com/api/v4/projects/17291191/repository/branches?branch=newbranch&ref=master"

# This does NOT work because I've removed the "&ref=master" from the end of the URL.
# This results in a response of `{"error":"ref is missing, ref is empty"}`, which is exactly the response I'm getting with glab as well.
curl --header "Authorization: Bearer SECRET" -X POST "https://gitlab.com/api/v4/projects/17291191/repository/branches?branch=newbranch"

Could it be the case that glab for some reason is failing to append &ref=<whatever> to the URL?
I can't see it in the command output, but I guess that could just be glab not showing the full URL including the query string.
Based on the GitLab docs it seems like the query string is where ref is supposed to go.

@clemsbot
Copy link
Collaborator

This issue has been automatically marked as stale because it has not had recent activity. We haven't had the time to address it yet, but we want to keep it open. This message is just a reminder for us to help triage issues.

@clemsbot clemsbot added the stale label Jul 16, 2021
@profclems
Copy link
Owner

@Ekik @idcmardelplata do you still have this issue with the current GitLab version?

@profclems profclems removed the stale label Jul 24, 2021
@eriknaslund
Copy link
Author

@profclems I'm afraid so.
Exact same behavior for me with "glab version 1.18.1-40-g0fb95ea (2021-07-27)".

@clemsbot
Copy link
Collaborator

This issue has been automatically marked as stale because it has not had recent activity. We haven't had the time to address it yet, but we want to keep it open. This message is just a reminder for us to help triage issues.

@clemsbot clemsbot added the stale label Aug 26, 2021
@profclems profclems linked a pull request Nov 4, 2021 that will close this issue
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working stale
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants