diff --git a/elements/source-repositories/extra-data.d/98-source-repositories b/elements/source-repositories/extra-data.d/98-source-repositories index 35d46a68e..680422fa1 100755 --- a/elements/source-repositories/extra-data.d/98-source-repositories +++ b/elements/source-repositories/extra-data.d/98-source-repositories @@ -136,16 +136,35 @@ function get_repos_for_element(){ fi echo "Cloning from $REPONAME cache and applying ref $REPOREF" - sudo git clone $CACHE_PATH $REPO_DEST - pushd $REPO_DEST - sudo git fetch $CACHE_PATH $REPOREF - sudo git reset --hard FETCH_HEAD - # Get the sha in use - git_sha=$(git rev-parse FETCH_HEAD) - popd + # If the local dir is already used, see if the pertinent details differ + if [[ -d $REPO_DEST ]]; then + DESIRED="$(sudo git --git-dir=$REPO_DEST/.git config remote.origin.url)" + if [[ "$CACHE_PATH" != "$DESIRED" ]]; then + echo "REPOLOCATIONS don't match ("$CACHE_PATH" != "$DESIRED")" >&2 + exit 1 + else + pushd $REPO_DEST + # When we first clone we create a branch naming what we fetched + # that must match, or we are asking for two different references from the + # same repo, which is an error + if ! git rev-parse fetch_$REPOREF; then + echo "REPOREFS don't match - failed to get sha1 of fetch_$REPOREF" >&2 + exit 1 + fi + popd + fi + else + sudo git clone $CACHE_PATH $REPO_DEST + pushd $REPO_DEST + sudo git fetch $CACHE_PATH $REPOREF:fetch_$REPOREF + sudo git reset --hard FETCH_HEAD + # Get the sha in use + git_sha=$(git rev-parse FETCH_HEAD) + popd - # Write the sha being used into the source-repositories manifest - echo "$REPONAME git $REPOPATH $REPOLOCATION $git_sha" >> $GIT_MANIFEST + # Write the sha being used into the source-repositories manifest + echo "$REPONAME git $REPOPATH $REPOLOCATION $git_sha" >> $GIT_MANIFEST + fi ;; tar) # The top level directory of the tarball mightn't have a fixed name i.e.