Allow source-repositories ref to be "*"
Passing a source-repositories ref of "*" should signal fetching all heads similar to when a non-cached ref is requested. Reuse the same fallback logic, but skip unnecessary checks since "*" is not a real refname. Also expand the fallback to update tags, and to --purge local refs that no longer exist on the remote for additional safety. Change-Id: I4562c9689a8d235ebe09b2f7178aa5890dbc85f1
This commit is contained in:
parent
6bf4631cfa
commit
f82400b432
@ -9,7 +9,8 @@ from git and pbr from a tarball would be
|
|||||||
*File : elements/custom-element/source-repository-ironic*
|
*File : elements/custom-element/source-repository-ironic*
|
||||||
|
|
||||||
#<name> <type> <destination> <location> [<ref>]
|
#<name> <type> <destination> <location> [<ref>]
|
||||||
# <ref> defaults to master if not specified
|
# <ref> defaults to master if not specified.
|
||||||
|
# A value of "*" prunes and fetches all heads and tags.
|
||||||
ironic git /usr/local/ironic git://git.openstack.org/openstack/ironic.git
|
ironic git /usr/local/ironic git://git.openstack.org/openstack/ironic.git
|
||||||
|
|
||||||
*File : elements/custom-element/source-repository-pbr*
|
*File : elements/custom-element/source-repository-pbr*
|
||||||
|
@ -118,12 +118,14 @@ function get_repos_for_element(){
|
|||||||
mv ${CACHE_PATH}{.tmp,}
|
mv ${CACHE_PATH}{.tmp,}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ "$REPOREF" != "*" ] ; then
|
||||||
HAS_REF=$(git --git-dir=$CACHE_PATH/.git name-rev $REPOREF 2>/dev/null || true)
|
HAS_REF=$(git --git-dir=$CACHE_PATH/.git name-rev $REPOREF 2>/dev/null || true)
|
||||||
|
fi
|
||||||
if [ -z "$DIB_OFFLINE" -o -z "$HAS_REF" ] ; then
|
if [ -z "$DIB_OFFLINE" -o -z "$HAS_REF" ] ; then
|
||||||
echo "Updating cache of $REPOLOCATION in $CACHE_PATH with ref $REPOREF"
|
echo "Updating cache of $REPOLOCATION in $CACHE_PATH with ref $REPOREF"
|
||||||
# Copy named refs (which might be outside the usual heads
|
# Copy named refs (which might be outside the usual heads
|
||||||
# pattern) - e.g. gerrit
|
# pattern) - e.g. gerrit
|
||||||
if ! git --git-dir=$CACHE_PATH/.git fetch --update-head-ok $REPOLOCATION \
|
if [ "$REPOREF" == "*" ] || ! git --git-dir=$CACHE_PATH/.git fetch --update-head-ok $REPOLOCATION \
|
||||||
+${REPOREF}:${REPOREF} ; then
|
+${REPOREF}:${REPOREF} ; then
|
||||||
# Copy all heads from the remote repository - this permits
|
# Copy all heads from the remote repository - this permits
|
||||||
# using a SHA1 object reference so long as the object
|
# using a SHA1 object reference so long as the object
|
||||||
@ -131,12 +133,14 @@ function get_repos_for_element(){
|
|||||||
# not permit arbitrary sha fetching from remote servers.
|
# not permit arbitrary sha fetching from remote servers.
|
||||||
# This is a separate fetch to the prior one as the prior
|
# This is a separate fetch to the prior one as the prior
|
||||||
# one will fail when REPOREF is a SHA1.
|
# one will fail when REPOREF is a SHA1.
|
||||||
git --git-dir=$CACHE_PATH/.git fetch --update-head-ok $REPOLOCATION \
|
git --git-dir=$CACHE_PATH/.git fetch --prune --update-head-ok $REPOLOCATION \
|
||||||
+refs/heads/*:refs/heads/*
|
+refs/heads/*:refs/heads/* +refs/tags/*:refs/tags/*
|
||||||
fi
|
fi
|
||||||
# Ensure that we have a reference to the revision.
|
# Ensure that we have a reference to the revision.
|
||||||
|
if [ "$REPOREF" != "*" ] ; then
|
||||||
git --git-dir=$CACHE_PATH/.git rev-parse -q --verify $REPOREF^{commit}
|
git --git-dir=$CACHE_PATH/.git rev-parse -q --verify $REPOREF^{commit}
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Cloning from $REPONAME cache and applying ref $REPOREF"
|
echo "Cloning from $REPONAME cache and applying ref $REPOREF"
|
||||||
# If the local dir is already used, see if the pertinent details differ
|
# If the local dir is already used, see if the pertinent details differ
|
||||||
@ -145,7 +149,7 @@ function get_repos_for_element(){
|
|||||||
if [[ "$CACHE_PATH" != "$DESIRED" ]]; then
|
if [[ "$CACHE_PATH" != "$DESIRED" ]]; then
|
||||||
echo "REPOLOCATIONS don't match ("$CACHE_PATH" != "$DESIRED")" >&2
|
echo "REPOLOCATIONS don't match ("$CACHE_PATH" != "$DESIRED")" >&2
|
||||||
exit 1
|
exit 1
|
||||||
else
|
elif [[ "$REPOREF" != "*" ]]; then
|
||||||
pushd $REPO_DEST
|
pushd $REPO_DEST
|
||||||
# When we first clone we create a branch naming what we fetched
|
# 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
|
# that must match, or we are asking for two different references from the
|
||||||
@ -159,10 +163,16 @@ function get_repos_for_element(){
|
|||||||
else
|
else
|
||||||
sudo git clone $CACHE_PATH $REPO_DEST
|
sudo git clone $CACHE_PATH $REPO_DEST
|
||||||
pushd $REPO_DEST
|
pushd $REPO_DEST
|
||||||
|
if [[ "$REPOREF" == "*" ]]; then
|
||||||
|
sudo git fetch --prune --update-head-ok $CACHE_PATH \
|
||||||
|
+refs/heads/*:refs/heads/* +refs/tags/*:refs/tags/*
|
||||||
|
git_sha=$(git rev-parse HEAD)
|
||||||
|
else
|
||||||
sudo git fetch $CACHE_PATH $REPOREF:fetch_$REPOREF
|
sudo git fetch $CACHE_PATH $REPOREF:fetch_$REPOREF
|
||||||
sudo git reset --hard FETCH_HEAD
|
sudo git reset --hard FETCH_HEAD
|
||||||
# Get the sha in use
|
# Get the sha in use
|
||||||
git_sha=$(git rev-parse FETCH_HEAD)
|
git_sha=$(git rev-parse FETCH_HEAD)
|
||||||
|
fi
|
||||||
popd
|
popd
|
||||||
|
|
||||||
# Write the sha being used into the source-repositories manifest
|
# Write the sha being used into the source-repositories manifest
|
||||||
|
Loading…
Reference in New Issue
Block a user