Skip to content

Instantly share code, notes, and snippets.

View dabrady's full-sized avatar
🛠️

Daniel Brady dabrady

🛠️
View GitHub Profile
@dabrady
dabrady / post-merge
Created February 21, 2020 21:59
A post-merge Git hook for Ruby on Rails projects which installs dependencies and runs database migrations as needed
# Determine if the project dependencies have changed and install them if needed.
# (See below for an explanation of the `git` command being used here.)
NEW_GEMS=$(git diff-tree --name-only --no-commit-id --diff-filter=M ORIG_HEAD HEAD Gemfile Gemfile.lock)
[ -z "$NEW_GEMS" ] || (echo "Gemfile changed: installing updated dependences..." && bundle install)
# Get a list of new migration files that have been added since you last pulled.
#
# Check out `git help diff-tree` for full details, but the TL;DR is:
# `diff-tree`: show what is different between two project trees (as opposed to
# `diff`, which is more useful for diffing individual commits)
@dabrady
dabrady / jira_function.sh
Created February 21, 2020 21:50
A pre-commit Git hook for adding info about the currently tracked JIRA ticket
# An example approach to managing the JIRA ticket you are currently working on.
# This function simply manipulates an environment variable that can be read by other processes.
cj () {
local jira_config=$HOME/.jira
[[ -z "$jira_config" ]] || touch $jira_config # ensure it exists
. $jira_config # refresh the JIRA variable in the current session
local jira="$1"
# If no ticket specified, print the one currently being tracked.
[[ -z "$jira" ]] && echo "Now tracking $JIRA_CURRENT." && return 0