[Feature Request] Create Merge/Pull Request from branch context menu
p-fischer opened this issue · 3 comments
It would be a great workflow improvement if merge/pull requests could be initiated by right-clicking on a branch, clicking on the context menu option "Create Merge Request on origin", which will re-direct to the brower.
While the integration with e.g. GitHub and GitLab would be ideal, I saw in #250 concern was expressed about these integrations.
As a fallback I suggest to add support for custom actions on branch level, so users can replicate the "Create Merge Request" context menu option themselves.
I successfully tested this on Ubuntu 24.10.
Awesome! Thank you very much!
I successfully tested this on Ubuntu 24.10. Awesome! Thank you very much!
@p-fischer Can you share an example of how to setup the custom action to create a pull request in github (for example)?
I setup a custom action so I can right-click on a branch name in the left column, select "Custom Action" and click on my custom action "Create Merge Request", which will open (in my case) GitLab in a website with the correct branches selected.
Building this for GitHub should work in the equivalent way.
Steps to create the custom action:
- Open repository in SourceGit
- Open repository settings (That's the settings icon left of the fetch icon. Don't confuse the repository settings with the global settings. A dialog with title "Repository Configure" will open.)
- Click on tab "CUSTOM ACTION"
- Click on + icon on the bottom left
- Pick name for the custom action (e.g. "Create Pull Request" or "Create Merge Request")
- Select scope "Branch" (At least if you want the website to be opened with preselected branches)
- Skip input controls
- (Outside of SourceGit) Create a script (see below about the script content)
- Make script executable (using
chmod +x FILENAMEon Linux) - (Back to SourceGit dialog) Link script in "Executable File"
- For Arguments set
${BRANCH} - Check wait for action exit
regarding 8:
Create a script file. Under Linux I chose the path ~/.config/SourceGit/scripts/push_and_create_merge_request_from_branch.sh
My script looks like this:
#!/bin/bash
current_branch=$1 # the branch you clicked on
target_branch=main # the branch you want to merge into
remote=origin
gitlab_repo=https://[Enter project URL here]
# push the current_branch
git push ${remote} ${current_branch}:${current_branch}
# open GitLab website to create merge request
xdg-open ${gitlab_repo}/merge_requests/new?merge_request[source_branch]=${current_branch}&merge_request[target_branch]=${target_branch}
Some notes on the script
- Pushing the current branch is optional. I personally added it for convenience.
xdg-openis a Linux specific command to open a URL using the default browser. If you're on Windows or MacOS you need to change it.- The script, especially the last line is specific to GitLab and how the URL for creating a merge request looks like. For GitHub start creating a new pull request in the web, copy the URL and replace the concrete branch names with the variables
source_branchandcurrent_branch. You could extract the repository URL into a variable like I did but you don't need to. This might be nice if you want to re-use the script. - Your target/default branch might have a different name than
main. If so change it.
... OR as an alternative for GitHub for the script you could install GitHub CLI and use the PR create command