Skip to content

Instantly share code, notes, and snippets.

@nocash
Created February 6, 2019 20:34
Show Gist options
  • Save nocash/a9508a82f1748c1c16079418fdd4ae1d to your computer and use it in GitHub Desktop.
Save nocash/a9508a82f1748c1c16079418fdd4ae1d to your computer and use it in GitHub Desktop.
#!/bin/bash -e
ack_args=$@
git_ref=$( git which-master )
pattern='TODO|NOTE|XXX|placehold\.it|TK|tbd|console\.log'
function committed_files {
git diff ${git_ref}..HEAD --diff-filter=ACMX -G"$pattern" --name-only
}
function uncommitted_files {
git ls-files -mo --exclude-standard
}
( committed_files ; uncommitted_files ) \
| sort -u \
| xargs ack --with-filename $ack_args "$pattern"
#!/bin/bash
# Outputs "origin/master" if origin/master is a valid branch and ahead of
# master, otherwise outputs "master" if master if a valid branch, otherwise
# outputs nothing.
if git show-ref --verify --quiet refs/remotes/origin/master; then
commits_ahead=$( git rev-list master..origin/master | wc -l )
if [ "$commits_ahead" -gt 0 ]; then
echo 'origin/master'
exit 0
fi
fi
if git show-ref --verify --quiet refs/heads/master; then
echo 'master'
exit 0
fi
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment