Skip to content

Commit

Permalink
Merge pull request #6 from git-hook/initialize-submodules-before-invo…
Browse files Browse the repository at this point in the history
…king-target-post-clone-hook

Initialize submodules before invoking target post clone hook
  • Loading branch information
EricCrosson authored Jun 29, 2017
2 parents ca1ad39 + ca72595 commit b0659a6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
6 changes: 3 additions & 3 deletions bin/clone
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
readonly template=$(mktemp -d /tmp/post-clone.XXXXX)

teardown() {
rm -rf ${template}
rm -rf "${template}"
}
trap teardown EXIT

init() {
cd ${template}
cd "${template}"
git init
git remote add origin https://github.com/git-hook/post-clone.git
git fetch origin
Expand All @@ -22,7 +22,7 @@ init() {
}

main() {
git clone --template=${template} "$@"
git clone --template="${template}" "$@"
}

init &>/dev/null
Expand Down
17 changes: 11 additions & 6 deletions hooks/post-checkout
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,32 @@
# This hook can be used to save metadata about where a git repository
# is cloned locally. The intent is to use this information in other
# scripts that operate on the cloned git repository.

# path to the newly cloned repo on disk

readonly repo=$(git rev-parse --show-toplevel)

main() {
rm -rf -- ${repo}/.git/hooks
rm -rf -- "${repo}/.git/hooks"
initializeSubmodules
installClonedReposHooks
invokeClonedReposPostCloneHook
}

initializeSubmodules() {
git submodule update --init --recursive
}

installClonedReposHooks() {
cd ${repo}/.git
cd "${repo}/.git"
rm -rf hooks
ln -sf ../hooks
cd - >/dev/null
}

invokeClonedReposPostCloneHook() {
local -r post_clone_hook=${repo}/.git/hooks/post-clone
test ! -e ${post_clone_hook} && return
chmod u+x ${post_clone_hook}
local -r post_clone_hook="${repo}/.git/hooks/post-clone"
test ! -e "${post_clone_hook}" && return
chmod u+x "${post_clone_hook}"
${post_clone_hook}
}

Expand Down

0 comments on commit b0659a6

Please sign in to comment.