X-Git-Url: http://gitweb.hugovil.com/?a=blobdiff_plain;f=scripts%2Fgit-project-clone.sh;fp=scripts%2Fgit-project-clone.sh;h=44d0ebab9d499cbdf4bebe6c3e8770b05692b06c;hb=17221ee06c14d4e39dd45e9c5b779b0f915f2f4e;hp=49a40b63fa544eee0585dc494397d2546278df53;hpb=fa37c01979686fe0a32001b8f2687b248c7eb16a;p=hvutilities.git diff --git a/scripts/git-project-clone.sh b/scripts/git-project-clone.sh index 49a40b6..44d0eba 100755 --- a/scripts/git-project-clone.sh +++ b/scripts/git-project-clone.sh @@ -2,8 +2,7 @@ SCRIPT="`readlink -e $0`" SCRIPTPATH=$(dirname ${SCRIPT}) - -SUBREPOS_LIST=.gitsubrepos +source ${SCRIPTPATH}/hv-git-functions.sh # Uncomment to have verbose debug output ##debug=1 @@ -25,11 +24,7 @@ if [ ${#} -ne 2 ]; then exit 1 fi -if [ ! -f ${SUBREPOS_LIST} ]; then - echo "Missing file for list of subrepos: ${SUBREPOS_LIST}" - print_usage - exit 1 -fi +hv_git_validate_subrepos_list branch_from=${1} branch_new=${2} @@ -37,8 +32,6 @@ rc=0 clone_repo() { - local valid="0" - if [ ${#} -ne 1 ]; then echo "Missing repository name" exit 1 @@ -71,89 +64,33 @@ clone_repo() popd 1> /dev/null } -update_repo() -{ - local valid="0" - - if [ ${#} -ne 1 ]; then - echo "Missing repository name" - exit 1 - fi - - local r=${1} - - echo -n "Repo ${r}: " - - pushd "${r}" 1> /dev/null - b=${branch_from} - - exists=$(git show-ref refs/heads/${b}) - if [ -n "$exists" ]; then - vco -q ${b} 1> /dev/null - - if [ ${?} -ne 0 ]; then - rc=1 - echo "${b} (error)" - else - echo "${b}" - fi - else - echo "${b} (not found)" - rc=1 - fi - - popd 1> /dev/null -} - # First, try to update all subrepos to BRANCH_FROM -update_repo ./ - -# Read list of repositories from file named .gitsubrepos -while IFS=$'\n' read r ; do - [[ "${r}" =~ \#.* ]] && continue # Skip comment lines - [ -z ${r} ] && continue # Skip enmpty lines - +for r in ./ $(hv_git_get_subrepos_list); do # Make sure directory exists if [ ! -d "${r}" ]; then echo "Missing repos ${r}, skipping" continue fi - # Update only git repos - if [ ! -d "${r}/.git" ]; then - echo "Not a GIT repository" + hv_git_checkout ${r} ${branch_from} + if [ ${?} -ne 0 ]; then + echo "Error switching to ${branch_from} in repos ${r}" exit 1 fi +done - update_repo ${r} -done < ${SUBREPOS_LIST} - -if [ ${rc} -ne 0 ]; then - echo "Error switching to branch" - exit 1 -fi - -clone_repo ./ - -# Read list of repositories from file named .gitsubrepos -while IFS=$'\n' read r ; do - [[ "${r}" =~ \#.* ]] && continue # Skip comment lines - [ -z ${r} ] && continue # Skip enmpty lines +# Then clone repo +for r in ./ $(hv_git_get_subrepos_list); do # Make sure directory exists if [ ! -d "${r}" ]; then echo "Missing repos ${r}, skipping" continue fi - # Update only git repos - if [ ! -d "${r}/.git" ]; then - echo "Not a GIT repository" - exit 1 - fi - clone_repo ${r} -done < ${SUBREPOS_LIST} + rc=${?} +done exit ${rc}