From debcffa4176390083e5e112c7d3c34358522baae Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Sat, 3 Dec 2011 01:47:20 +0800 Subject: [PATCH] Added functions to quickly add git ignore rules to either .gitignore or .git/info/exclude --- lib/git/tools.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/git/tools.sh b/lib/git/tools.sh index 35d96a6..767b988 100644 --- a/lib/git/tools.sh +++ b/lib/git/tools.sh @@ -40,3 +40,16 @@ git_set_default_remote() { git config branch.$branch.remote $remote git config branch.$branch.merge refs/heads/$branch } + +# Add one git ignore rule, global by default +# Usage: git_ignore [rule] [ignore_file=.gitignore] +git_ignore() { + if [ -n "$2" ]; then local f="$2"; else local f=".gitignore"; fi + if [ -n "$1" ] && [ -e $f ] && ! grep -q "$1" $f; then echo "$1" >> $f; fi +} + +# Add one git ignore rule, just for your machine +# Usage: git_exclude [rule] +git_exclude() { + git_ignore "$1" ".git/info/exclude" +}