From deadcd64a5ca08bf05c57d76080b4db9c724d861 Mon Sep 17 00:00:00 2001 From: Jonhnny Weslley Date: Tue, 9 Nov 2010 12:03:31 -0300 Subject: [PATCH] git-ignore template support. Templates are based in https://github.com/github/gitignore --- .gitmodules | 3 +++ Readme.md | 3 +++ bin/git-ignore | 20 +++++++++++++++++++- etc/gitignore | 1 + 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 .gitmodules create mode 160000 etc/gitignore diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..bfa6d33 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "etc/gitignore"] + path = etc/gitignore + url = git://github.com/github/gitignore.git diff --git a/Readme.md b/Readme.md index f2facca..1ad8c79 100644 --- a/Readme.md +++ b/Readme.md @@ -178,6 +178,9 @@ of commits included in the commitish: *.o *.log + Adding patterns from an existing template: + $ git ignore -t rails + ## git-delete-branch <name> Deletes local and remote branch _name_. diff --git a/bin/git-ignore b/bin/git-ignore index 625a9e6..47f084a 100755 --- a/bin/git-ignore +++ b/bin/git-ignore @@ -1,7 +1,25 @@ #!/bin/sh +template="" +while getopts "t:" opt; do + case "$opt" in + t) template=$OPTARG;shift;shift;; + esac +done + +if [ ! -z "$template" ]; then + gitignoredir="`dirname $0`/../etc/gitignore" + selected_template=$(find $gitignoredir -type f -name *.gitignore | xargs -i basename {} .gitignore | grep -i $template) + count=$(echo $selected_template | wc -w) + case "$count" in + 0) echo "The pattern '$template' does not match any available templates." && exit 1;; + 1) find $gitignoredir -name $selected_template.gitignore -exec cat {} \; >> .gitignore && echo "... added patterns from template '$selected_template'";; + *) echo "Be more specific. $count macthes found:\n$selected_template" && exit 2;; + esac +fi + if test $# -eq 0; then - test -f .gitignore && cat .gitignore + test -z $template && test -f .gitignore && cat .gitignore else for pattern in $@; do echo $pattern >> .gitignore diff --git a/etc/gitignore b/etc/gitignore new file mode 160000 index 0000000..0a41318 --- /dev/null +++ b/etc/gitignore @@ -0,0 +1 @@ +Subproject commit 0a41318dba7094f7f97646280a0096e30b6cd596