From 8dd97597eaf3f30da8fafbd1e169b79a757c9b94 Mon Sep 17 00:00:00 2001 From: Jon-Paul Sullivan Date: Tue, 18 Nov 2014 17:09:35 +0000 Subject: [PATCH] Allow multiple identical sources The source-repositories element puts source in place in the generated image for later installation. It is possible for two elements to define the same source to later install, and as long as the remote location and reference to be installed is identical, we should not error. Change-Id: Ic7dfb1961486c59d2005b5c1e7587267ea42e999 --- .../extra-data.d/98-source-repositories | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) 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.