0

Let's say you have the following setup in gitlab:

  1. Gitlab Group Developments, of which there is a Subgroup Subgroup, which in turn contains Template project X which provides a general structure for all projects of the group Developments. The subgroup is simply used as that's needed to make use of gitlab's project templates.
  2. You then create a Project Y in the group Developments from the Template project X.
  3. You then create a Project Z in the group Developments, also from the Template project X.

During development, you then notice a bug in Project Y in a file that is also present in the Template project X. What I thus want to do now is:

  • Fix the bug in Project Y, let's say within Commit 123.
  • git add remote to add the Template project X as an additional remote your local Project Y (thus now having origin and template-project-x when calling git remote -v).
  • Create a new branch fix from starting point template-project-x with --no-track while in Project Y.
  • Add the Commit 123 into the fix branch (e.g. using git format-patch and git am).
  • Push the fix branch to the template-project-x remote with the -u flag.

Until that, everything works perfectly, and I have the patch of the concerned commit within the newly created fix branch in my gitlab Template project X showing up.

The last missing piece in this workflow is: How can I create a merge request of the pushed template-project-x/fix > template-project-x/main ?

When I, after the sequence of actions described above, run the following command while still in Project Y:

glab mr create --repo <GIT-URL-TEMPLATE-PROJECT-X> --assignee <assignee-name> --draft --remove-source-branch --reviewer <reviewer-name> --source-branch fix --target-branch main

I get:

Creating draft merge request for fix into main in template-project-x

Failed to create merge request. Created recovery file: /Users/.../mr.json
Run the command again with the '--recover' option to retry.
          
   ERROR  
          
  Post https://gitlab.com/api/v4/projects/.../merge_requests: 422 {message: [Source project is not a fork of the target project]}.     

Does this mean that I cannot create a merge request using glab for a project A while in project B ?

I have found similar questions in the gitlab community, but without a real answer.

3
  • This sounds like an overkill for what a plain git cherry-pick should be able to handle (if the contents of the commits involved are similar enough). Commented Nov 26 at 14:43
  • git format-patch provides much more details about the commit vs git cherry-pick, that's the reason why I chose git format-patch. And as long as it can be automated with a single shell script and executes fast, it's not an overkill to me ? Anyways the main issue is the creation of the merge request across projects, not the copy-paste operation of the commit, as the question says. Commented Nov 26 at 15:18
  • I might be wrong about this but I think that cherry-pick beats format-patch/am because it has context about the relationship between the ancestor of the commit you are cherry-picking and where you want to apply it. To give an example, differences in line numbers, in my experience, can break a patch, whereas cherry-pick will easily handle that case. Commented Nov 26 at 21:46

1 Answer 1

0

Turns out glab cannot create merge requests across projects, while the git command can do this with:

git push \ 
-o merge_request.create \
-o merge_request.target=main \
-o merge_request.draft \
-o merge_request.target_project=project-template-x \
-u project-template-x

I just read about alternative ways to create merge requests in gitlab, and trying this through the git CLI with the push options somehow does the magic.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.