From 5b99028acf67d5883f1d836e85bec911cbf8fb98 Mon Sep 17 00:00:00 2001 From: Tim Miller Date: Fri, 8 Mar 2013 08:15:58 -0800 Subject: [PATCH] Correctly translate all branches/tags/shas: The code which raises an error if two elements try to install different versions of the same git repo currently works correctly for SHAs, or if a branch is specified first, followed by a SHA. However it fails if two branches are specified, because the shallow clone does not fetch all branch heads. This change correctly handles any combination of SHAs/branch-heads/tags. Change-Id: I501e94150ddeb41b79588816576a5d7a06fa92aa --- elements/os-svc-install/bin/os-svc-install | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/elements/os-svc-install/bin/os-svc-install b/elements/os-svc-install/bin/os-svc-install index c6d5e186..ebcb011a 100755 --- a/elements/os-svc-install/bin/os-svc-install +++ b/elements/os-svc-install/bin/os-svc-install @@ -15,14 +15,24 @@ function install-os-service() { chown -R $user:$user /etc/$user local svc_root=/opt/stack/$user + local git_dir="--git-dir $svc_root/.git" + if [ ! -e $svc_root ]; then git clone --depth=1 -b $branch $repo $svc_root - [ -e $svc_root/tools/pip-requires ] && $pip_install -r $svc_root/tools/pip-requires + + [ -e $svc_root/tools/pip-requires ] && pip install -r $svc_root/tools/pip-requires $pip_install $svc_root else - expected_rev=$(git --git-dir $svc_root/.git rev-parse $branch) - actual_rev=$(git --git-dir $svc_root/.git show | head -1 | awk '{print $2}') - if [ "$expected_rev" -ne "$actual_rev" ]; then + if ! git $git_dir remote -v | grep $repo; then + echo "ERROR: $svc_root exists and did not come from $repo" + exit 1 + fi + + # raise an error unless existing repo is at expected git-rev + actual_rev=$(git $git_dir show | head -1 | awk '{print $2}') + git $git_dir checkout $branch + expected_rev=$(git $git_dir show | head -1 | awk '{print $2}') + if [ "$expected_rev" != "$actual_rev" ]; then echo "ERROR: $repo exists and is not on rev $branch" exit 1 fi