Skip to content

Instantly share code, notes, and snippets.

View patrickmch's full-sized avatar

Patrick McHeyser patrickmch

View GitHub Profile
@patrickmch
patrickmch / commit-msg
Last active December 27, 2018 23:09
commit-msg
#!/bin/bash
BRANCH_PATH=$(git symbolic-ref -q HEAD) # Something like refs/heads/my-branch-name
BRANCH_NAME=${BRANCH_PATH##*/} # Get text behind the last / of the branch path
# Make sure we have an issue number in front before doing anything
if [[ $BRANCH_NAME =~ (^[0-9]{4}) ]] ;then
ISSUE_NUMBER=${BASH_REMATCH[1]}
FIRST_LINE=$(head -n1 $1)
# make sure there isn't already a "fixes ISSUE_NUMBER" line in message (ex. if it's an amend)
@patrickmch
patrickmch / prepare-commit-msg
Created December 27, 2018 18:19
prepare-commit-msg
#!/bin/bash
# This adds "fixes #0000" to the third line of the commit message automatically
# if there is an issue number in front of the branch name.
BRANCH_PATH=$(git symbolic-ref -q HEAD) # Something like refs/heads/my-branch-name
BRANCH_NAME=${BRANCH_PATH##*/} # Get text behind the last / of the branch path
# Make sure we have an issue number in front before doing anything
if [[ $BRANCH_NAME =~ (^[0-9]{4}) ]] ;then
ISSUE_NUMBER=${BASH_REMATCH[1]}
FIRST_LINE=$(head -n1 $1)
@patrickmch
patrickmch / pre-commit
Last active December 21, 2018 19:17
pre-commit hook
#!/usr/bin/env python
# adapted from https://dzone.com/articles/why-your-need-git-pre-commit
# store this bad-dad as .git/hooks/pre-commit
import os
import re
import subprocess
import sys
modified = re.compile('^(?:M|A)(\s+)(?P<name>.*)')