Skip to content

Instantly share code, notes, and snippets.

@james2doyle
Last active December 30, 2024 04:38
Show Gist options
  • Save james2doyle/51244a549c1c1f1d16bf7f4b89be71b0 to your computer and use it in GitHub Desktop.
Save james2doyle/51244a549c1c1f1d16bf7f4b89be71b0 to your computer and use it in GitHub Desktop.
Create a bitbucket URL to compare 2 commits
# Based on: https://gist.github.com/danlherman/8a32fa05c2cf6018ed10
# creates a URL to compare 2 commits
# takes 2 commit hashes (future past), or 1 hash and it will compare to the current commit
function bb-compare
set repo_name (git remote show origin | grep "Fetch URL:" | awk -F: '{print $3}')
switch (count $argv);
case 1
set commit_one (git log --pretty=format:"%h" | head -n 1)
set commit_two $argv[1]
echo "Comparing latest commit ($commit_one) and $commit_two"
case 2;
set commit_one $argv[1]
set commit_two $argv[2]
echo "Comparing $commit_one and $commit_two"
end
set start_url "https://bitbucket.org/$repo_name/branches/compare/$commit_one..$commit_two#diff"
echo $start_url
end
@timblaktu
Copy link

This doesn't work for me on Bitbucket Server 6.2.0. I believe this facility only works for branch name references.

@james2doyle
Copy link
Author

@timblaktu I think this will only work with cloud bitbucket since the URL only supports normal bitbucket URLs and not company ones

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment