Skip to content

Instantly share code, notes, and snippets.

@garymacindoe
Created April 5, 2018 15:19
Show Gist options
  • Save garymacindoe/1e9b24757aa16a9c99f79f73d7a027d0 to your computer and use it in GitHub Desktop.
Save garymacindoe/1e9b24757aa16a9c99f79f73d7a027d0 to your computer and use it in GitHub Desktop.
Checkout a team's projects in SVN
#!/bin/bash
REPO_BASE="https://svn.repo/department/team"
LOCAL_BASE="${HOME}/svn"
backoff() {
local count iteration timeout output ret
timeout=1
count=5
iteration=0
output="$(${@} 2>&1)"
ret=$?
while [[ $ret -ne 0 && $iteration -lt $count ]]
do
sleep ${timeout}
timeout=$((timeout * 2))
iteration=$((iteration + 1))
output="$(${@} 2>&1)"
ret=$?
done
if [ -n "${output}" ]
then
echo "${output}"
fi
return $ret
}
is_stdlayout() {
output=$(backoff svn ls "${1}")
if [[ $? -ne 0 ]]
then
return 2
elif [[ $(grep "^\(branches\|tags\|trunk\)/\?$" <<< "${output}" | wc -l) -gt 0 ]]
then
return 0
else
return 1
fi
}
repo_list=$(backoff svn ls "${REPO_BASE}")
if [ $? -ne 0 ]
then
echo "Unable to list ${REPO_BASE}"
exit 1
fi
while read repo;
do
SVNFLAGS="--quiet --ignore-externals"
REMOTE_REPO="${REPO_BASE}/${repo%%/}"
LOCAL_REPO="${LOCAL_BASE}/${repo%%/}"
if [[ -d "${LOCAL_REPO}" ]]
then
continue
fi
echo "${REMOTE_REPO} -> ${LOCAL_REPO}"
if is_stdlayout "${REMOTE_REPO}"
then
REMOTE_REPO="${REMOTE_REPO}/trunk"
fi
backoff svn checkout ${SVNFLAGS} "${REMOTE_REPO}" "${LOCAL_REPO}"
if [ $? -ne 0 ]
then
echo "${REMOTE_REPO}" >> failed.txt
echo "Failed to checkout ${REMOTE_REPO}"
echo -n "${output}"
fi
done <<< "${repo_list}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment