Skip to content

Instantly share code, notes, and snippets.

@hgenru
Last active November 9, 2016 13:14
Show Gist options
  • Save hgenru/303d9197b3cb0387148e1f1e3628d406 to your computer and use it in GitHub Desktop.
Save hgenru/303d9197b3cb0387148e1f1e3628d406 to your computer and use it in GitHub Desktop.
Add task number to all commit in task branch
#!/bin/sh
ticket_number_rx='/\d{2,5}' # if you pass ticket number like prefix/123-foo-bar
# ticket_number_rx='\d{2,5}$' # if you pass ticket number like prefix/foo-bar-123
ticket_number=$(git symbolic-ref HEAD | grep -oE -m 1 $ticket_number_rx | grep -oE "\d+")
if [ -n "$ticket_number" ]; then
ticket="#$ticket_number"
if ! head -n 1 $1 | grep -qw $ticket; then
ticket_template="(refs $ticket)"
sed -ie "1 s/$/ $ticket_template/" $1
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment