Skip to content

Commit

Permalink
git-ignore template support. Templates are based in https://github.co…
Browse files Browse the repository at this point in the history
…m/github/gitignore

Signed-off-by: Tj Holowaychuk <tj@vision-media.ca>
  • Loading branch information
jweslley authored and tj committed May 19, 2011
1 parent 38d8a22 commit a5392d5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitmodules
@@ -0,0 +1,3 @@
[submodule "etc/gitignore"]
path = etc/gitignore
url = git://github.com/github/gitignore.git
3 changes: 3 additions & 0 deletions Readme.md
Expand Up @@ -221,6 +221,9 @@ of commits included in the commitish:
*.o
*.log

Adding patterns from an existing template:
$ git ignore -t rails

## git-delete-branch &lt;name&gt;

Deletes local and remote branch _name_.
Expand Down
20 changes: 19 additions & 1 deletion 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
Expand Down
1 change: 1 addition & 0 deletions etc/gitignore
Submodule gitignore added at 0a4131

0 comments on commit a5392d5

Please sign in to comment.