Today I received a new and irritating demand at work: from now on I must apparently give my Pull Requests on Bitbucket a title that contains the issue number for the task from the project software we use ie. Linear.
It is irritating because that information is already available in the branch name: we started naming our branches with this convention some time ago. But when Bitbucket sets up a Pull Request it constructs its title not from the branch name but from the commit message of the head commit. So, this amounts to yet another GUI copy and paste chore and of course Bitbucket is not stellar with accessibility; I don’t know a site that is. Meaning more mousing and more stress for my RSI prone hands.
Even worse, I already have this chore earlier in my workflow: when pushing the branch for the first time to Bitbucket from my local repository on my development system, via Magit. Magit needs to set the upstream branch to push to, and for a reason unknown to me it doesn’t sensibly default the upstream branch name to the local name. Maybe it is because it only considers already existing remote branches as preferred candidates. So I need to do the copy and paste job at that point, even if only within Emacs.
My irritation morphed into an idea: if I could get the branch name into
the clipboard with a single UI action — ideally a keyboard shortcut —
I would then be able to paste it at both of the places where it is
needed. But there’s a hurdle: Emacs knows the branch name but it runs
on the development system, but to paste into Bitbucket I need the text
in the clipboard on my desktop (a MacBook). So I can’t simply use the
Emacs clipboard-kill-ring-save
function.
The solution is necessarily a hack, consisting of two pieces: one to
save the text into a file on the remote development system, a second one
to retrieve the file contents via ssh
and stuff it into the Mac clipboard.
The Emacs part
(defun imbr ()
"Copy current git branch to clipoard.
Needed for fucked up GUIs."
(interactive)
(let ((br (magit-get-current-branch)))
(with-temp-buffer
(insert br)
(write-file (expand-file-name "~/.magit-branch")))))
The name imbr
is sure not very descriptive, but it is easy to type.
This way I don’t have to invent a new keybinding, M-x imbr
will work.
The Mac part
#! /bin/sh -Cfu
ssh devnode cat /home/itz/.magit-branch | pbcopy
Now I just had to use the Automator app on the Mac to set up a Quick Action for the script; that has the effect of adding a button on the Touch Bar, and more importantly for me, making a keybinding available in the Services part of the Preferences app.
Question
The Bitbucket way of setting Pull Request titles does not seem very natural. I think many people would prefer them to be named after the branch they come from, rather than after the commit. So, how do others cope with this? Have I missed some setting in Bitbucket to change this behavior?