Skip to content

Commit

Permalink
Added install script for pre-commit hook and updated readme.md with i…
Browse files Browse the repository at this point in the history
…nstallation instructions
  • Loading branch information
calimarkus committed Feb 15, 2013
1 parent 3dfdb73 commit 14e971b
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 7 deletions.
12 changes: 9 additions & 3 deletions .generateDescription.py
Expand Up @@ -5,12 +5,18 @@
print ">> Updating README.md based on .codesnippet files"

file = open('README.md', 'w')
file.write('# CodeSnippets\n\nThese are my Xcode 4 CodeSnippets. Just clone them into the following path: \n')
file.write('The folder must be empty, to clone the repository directly in it.\n\n')
file.write('# CodeSnippets\n\n')
file.write('These are my Xcode 4 CodeSnippets. \n')
file.write('To use them, clone this repository into the following path:\n\n')
file.write(' cd ~/Library/Developer/Xcode/UserData/CodeSnippets\n')
file.write(' git clone git@github.com:jaydee3/CodeSnippets.git .\n\n')
file.write('(The folder must be empty, to clone the repository directly in it.) \n')
file.write('And you\'re ready to go.\n\n')
file.write('## Snippet Descriptions\n\n(generated with .generateDescription.py)\n\n')
file.write('#### Installing the pre-commit hook \n')
file.write('This README is generated automatically using `.generateDescription.py`. \n')
file.write('To run this script automatically before each commit, install the pre-commit hook like this:\n\n')
file.write(' sh .install-precommit-hook.sh\n\n')
file.write('## Snippet Descriptions\n\n')

listing = os.listdir(".")
for fileName in listing:
Expand Down
50 changes: 50 additions & 0 deletions .install-precommit-hook.sh
@@ -0,0 +1,50 @@
#!/bin/sh
#
# Installs the pre-commit git hook
# which will automatically update the README.md
# and stage it for the current commit right before
# every actual commit
#

hookfile=".pre-commit.hook"
target=".git/hooks/pre-commit"
backupTarget=".git/hooks/pre-commit.backup"

# file existing options
cancel=false
overwrite=false
backup=false

# ask what to do with existing file
if [ -e "$target" ] || [ -h "$target" ]; then
echo "A pre-commit hook already exists!"
echo "[c]ancel, [o]verwrite or [b]ackup"
while true; do
read answer
case $answer in
"c" ) cancel=true; break;;
"o" ) overwrite=true; break;;
"b" ) backup=true; break;;
* ) continue ;;
esac
done

if $overwrite; then
rm $target
fi

if $backup; then
mv $target $backupTarget
echo "Saved old hook as $backupTarget"
fi
fi

# cancel or install
if $cancel; then
echo "Canceled"
else
cp $hookfile $target
echo "Installed hook: $target"
fi


9 changes: 9 additions & 0 deletions .pre-commit.hook
@@ -0,0 +1,9 @@
#!/bin/sh
#
# generate documentation, before commiting
# this will update the readme.md
#

python .generateDescription.py
git add README.md

13 changes: 9 additions & 4 deletions README.md
@@ -1,16 +1,21 @@
# CodeSnippets

These are my Xcode 4 CodeSnippets. Just clone them into the following path:
The folder must be empty, to clone the repository directly in it.
These are my Xcode 4 CodeSnippets.
To use them, clone this repository into the following path:

cd ~/Library/Developer/Xcode/UserData/CodeSnippets
git clone git@github.com:jaydee3/CodeSnippets.git .

(The folder must be empty, to clone the repository directly in it.)
And you're ready to go.

## Snippet Descriptions
#### Installing the pre-commit hook
This README is generated automatically using `.generateDescription.py`.
To run this script automatically before each commit, install the pre-commit hook like this:

sh .install-precommit-hook.sh

(generated with .generateDescription.py)
## Snippet Descriptions

**allocInit.codesnippet** (Initalize an object)
Shortcut: `alloc`
Expand Down

0 comments on commit 14e971b

Please sign in to comment.