Skip to content

Instantly share code, notes, and snippets.

@HokieGeek
Last active November 18, 2016 02:12
Show Gist options
  • Save HokieGeek/a7b8f9783fd7f682f7de2e6ffa493caf to your computer and use it in GitHub Desktop.
Save HokieGeek/a7b8f9783fd7f682f7de2e6ffa493caf to your computer and use it in GitHub Desktop.
#!/bin/bash -e
echo ">>>> HOOK <<<<"
refBareRepo=$(pwd)
refname=$1
oldrev=$2
newrev=$3
# echo "ref: $refname"
# echo "old: $oldrev"
# echo "new: $newrev"
# git ls-tree ${oldrev} | awk '$2 == "commit"'
# refRepo=$(mktemp -d)
refRepo=$(mktemp -u -d)
gitmodulesFile=$(mktemp)
git clone ${refBareRepo} ${refRepo}
pushd ${refRepo} >/dev/null 2>&1
(
unset GIT_DIR
set -x
# git init
# git fetch ${refBareRepo} '+refs/heads/*:refs/remotes/origin/*' #--depth=1
# git ls-tree ${newrev} | awk '$4 ~/\.gitmodules/ { print $3 }'
filesha=$(git ls-tree ${newrev} | awk '$4 ~/\.gitmodules/ { print $3 }')
git cat-file blob ${filesha} > ${gitmodulesFile}
set +x
)
popd >/dev/null 2>&1
rm -rf ${refRepo}
git ls-tree ${newrev} | awk '$2 == "commit" { printf("%s %s\n", $NF, $(NF-1)) }' | \
while read reponame reposha; do
repourl=$(git config --file ${gitmodulesFile} --get-regexp 'submodule.'${reponame}'.url' | awk '{ print $2 }')
# repourl=$(git config --file ${gitmodulesFile} --get-regexp 'submodule.'${reponame}'.url')
# echo "repo: $reponame, sha: $reposha, url: $repourl"
# echo "sha: $reposha"
# echo -n "lsr: "
# set -x
# repoclone=$(mktemp -u -d)
# git clone
git --git-dir ${repourl} rev-parse ${reposha} >/dev/null
# git ls-remote --refs ${repourl} ${reposha}
# set +x
done
#!/bin/bash
here=$(cd ${0%/*}; pwd)
hook=${1:-"${here}/verify-submodule-commits.sh"}
parent=$(mktemp -d)
child=$(mktemp -d)
others=($(mktemp -d) $(mktemp -d) $(mktemp -d))
# trap "${parent} ${child} ${others[@]}" EXIT
## Create the bare repos of parent and child
for r in ${parent} ${child} ${others[@]}; do
cd ${r}
git init --bare
tmp=$(mktemp -d)
cd ${tmp}
git init .
git remote add origin ${r}
git pull origin master
echo $RANDOM > a
git add a && git commit -m '.'
git push origin master
done
cp ${hook} ${parent}/hooks/update || exit 1
## Clone the parent
git clone ${parent} ${parent}.$$ || exit 2
cd ${parent}.$$
## Clone the children
for r in ${child} ${others[@]}; do
git submodule add ${r}
done
touch t.$RANDOM
git add t.*
## Commit these children. This should work fine
git commit -m 'Initial'
echo -n "pwd: "
pwd
git push origin master && echo "SUCCESS!" || echo "FAILED!"
# git remote -v
# cat ${parent}/hooks/update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment