How can I view the pull request URL for the current branch?
The URL you've listed here is for a pull request that already exists - the "View pull request" text is the giveaway there. Existing pull requests have an ID in the URL, which you'll need to specify; if you don't know the ID, then you'll need to get the URL from the GUI (https://bitbucket.org/owner/repo/pull-requests/
is probably the easiest place to find it).
If there isn't already a pull request for your branch, then the "Create pull requests" link that the hook generates is https://bitbucket.org/owner/repo/pull-requests/new?source=branchname&t=1
.
Bash version:
#!/bin/bash
org="myOrg"
branch=$(git rev-parse --abbrev-ref HEAD)
repo_dir=$(git rev-parse --show-toplevel)
repo=$(basename ${repo_dir})
url="https://bitbucket.org/${org}/${repo}/pull-requests/new?source=${branch}&t=1"
echo $url
This pull request URL is not a git feature but a message generated by a hook script on the BitBucket server.
On a BitBucket server, you can disable it globally with: How do I disable the remote create pull request message when pushing changes?. On the BitBucket cloud you cannot disable it.
One soultion to obtain this message would be to simulate a git pull
with the --dry-run
option, such as :
git pull --dry-run
but if this is not enough to trigger the hook, probably that the only way is to go through the BitBucket web interface.
I was able to generate the URL using a batch file like this:
@echo off
setlocal
for /f "tokens=*" %%a in (
'git rev-parse --abbrev-ref HEAD'
) do (
set branch=%%a
set url=https://bitbucket.org/my-company/repo/pull-requests/new?source=%%a^^^&t=1
)
echo %url%
endlocal
It simply grabs the current git branch and puts in a string, then echoes the string.