0

how can I change this message when I execute this git command in a GitLab repository:

git push --set-upstream origin test-branch

The origin message:

Total 0 (delta 0), reused 0 (delta 0), pack-reused 0

remote:
remote: To create a merge request for test-branch, visit:
remote: https://example.org/customer/name/project/-/merge_requests/new?merge_request[source_branch]=test-branch
remote:  
 
To git.example.org/customer/name/project.git
* [new branch]        test-branch -> test-branch
branch 'test-branch' set up to track 'origin/test-branch'.

The message I want to achieve:

Total 0 (delta 0), reused 0 (delta 0), pack-reused 0

remote:
remote: To create a merge request for test-branch, visit:
remote: https://example.org/customer/name/project/-/merge_requests/new?merge_request[source_branch]=test-branch 
remote:
remote: To create a merge request for test-branch with target branch 'staging', visit:
remote: https://example.org/customer/name/project/-/merge_requests/new?merge_request[source_branch]=test-branch&merge_request%5Btarget_branch%5D=staging
remote: 
remote: To create a merge request for test-branch with target branch 'main', visit:
remote: https://example.org/customer/name/project/-/merge_requests/new?merge_request[source_branch]=test-branch&merge_request%5Btarget_branch%5D=main
remote: 

To git.example.org/customer/name/project.git
* [new branch]        test-branch -> test-branch
branch 'test-branch' set up to track 'origin/test-branch'.

Thanks in advance!

HEYDANNY
  • 144
  • 10
  • 2
    What is it that you want to change? This is not a "message"; it's just Git replying to what you said. What don't you like about Git's reply? It is simply informing you of the situation and giving you some helpful advice. Part of the response is coming from Git, part of it is coming from GitHub, and they are both telling you useful things. – matt Jun 13 '23 at 15:40
  • Also you are not "pushing upstream branch" here; you are just pushing the branch, plain and simple. – matt Jun 13 '23 at 15:42
  • 1
    Indeed they are useful. I would like to extend the message so it offers two more links. I would like to add the URL parameter "target_branch" to preselect "staging" and "main". – HEYDANNY Jun 13 '23 at 20:39
  • Can you add those details into the question, maybe with an example output you'd like? I'm not sure, at first glance, how this would be done. I'm suspicious this is generated server-side and we might not have much control over it, but I'll defer to someone who actually knows what generates this. Even a better name would for this message would improve the question. – ojchase Jun 13 '23 at 21:56
  • I edited the question title and description to add more details and an example, I would like to achieve. – HEYDANNY Jun 14 '23 at 07:46

1 Answers1

1

Per How to add message with link to new pull request page after pushing branch to GitHub?, this messaging is coming from GitLab via the post-receive Git hook, as documented here. This is a server-side hook, so you need to modify files on the GitLab server itself.

My direct expertise ends about here, and I'd have to make educated guesses with you. You want to either modify the actual hook used in GitLab or convince it to additionally call another. I would personally be nervous about losing whatever else the existing hook is doing.

The simplest path that I would try first is to check your server repository for a /hooks directory and see if it has an existing post-receive file you can modify. The questioner in How can I add hooks to gitlab? might have managed this successfully.

Another option is that it appears that GitLab supports custom hooks. This is documented here, although an older version seems more readable, if possibly dated. This looks more involved, but possibly more correct.

Adding the git-post-receive tag to the question might attract better answers.

See also Understanding Git Hook - post-receive hook and How to setup Gitlab with post-receive hook? (serverfault)

ojchase
  • 1,041
  • 1
  • 10
  • 22