Skip to content

Commit

Permalink
Fixes to setup-repo.sh:
Browse files Browse the repository at this point in the history
- Commit hook was missing shebang
- Commit hook wasn't working correctly with spaces in the repository path
- .clang-format is no longer overwritten with a symlink if it exists already
- .clang-format is no longer added to .gitignore if it's already part of the git tree
  • Loading branch information
ksuther committed Aug 28, 2015
1 parent 9c5b6cb commit 00b415b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions setup-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,30 @@ function ensure_hook_is_installed() {
# check if this repo is referenced in the precommit hook already
repo_path=$(git rev-parse --show-toplevel)
if ! grep -q "$repo_path" "$pre_commit_file"; then
echo "#!/usr/bin/env bash" >> $pre_commit_file
echo "current_repo_path=\$(git rev-parse --show-toplevel)" >> $pre_commit_file
echo "repo_to_format=\"$repo_path\"" >> $pre_commit_file
echo 'if [ "$current_repo_path" == "$repo_to_format" ]'" && [ -e $DIR/format-objc-hook ]; then $DIR/format-objc-hook; fi" >> $pre_commit_file
echo 'if [ "$current_repo_path" == "$repo_to_format" ]'" && [ -e \"$DIR\"/format-objc-hook ]; then \"$DIR\"/format-objc-hook; fi" >> $pre_commit_file
fi
}

function ensure_git_ignores_clang_format_file() {
# if .clang-format is already in the git tree then it doesn't need to be added to the ignore file
pushd "$DIR"
git ls-files .clang-format --error-unmatch > /dev/null
in_tree=$?
popd
grep -q ".clang-format" ".gitignore"
if [ $? -gt 0 ]; then
if [ $? -gt 0 -a $in_tree -gt 0 ]; then
echo ".clang-format" >> ".gitignore"
fi
}

function symlink_clang_format() {
$(ln -sf "$DIR/.clang-format" ".clang-format")
# only symlink .clang-format if it doesn't exist already
if [ ! -e "$DIR/.clang-format" ]; then
$(ln -sf "$DIR/.clang-format" ".clang-format")
fi
}


Expand Down

0 comments on commit 00b415b

Please sign in to comment.