Cause cros_workon to die rather than clobber local_manifest

cros_workon would clobber local edits to local_manifest in many cases
This is a quick fix to prevent it. The proper solution is to actually parse
local_manifest as an XML doc and modify the DOM. Not play tricks with grep.

BUG=chromium-os:6272
TEST=Ran cros_workon against missing local_manifest, auto-generated local_manifest, local_manifest with indented tags. local_manifest with multi-line tags and local_manifest with <remote tags.

Review URL: http://codereview.chromium.org/3227006

Change-Id: I008c11a43ac21336575445273453373645f96398
This commit is contained in:
Jon Kliegman 2010-09-01 09:39:44 -04:00
parent b801bec71a
commit 3ecded4794

View File

@ -148,6 +148,25 @@ regen_manifest_and_sync() {
find_repo_dir
local_manifest="${REPODIR}/local_manifest.xml"
# ensure we don't clobber existing manifest entries
if [ -f "${local_manifest}" ]; then
grep -q -i "<remote" "${local_manifest}"
if [ $? -ne 1 ]; then
die "Your local manifest will be clobbered running cros_workon. You can not have any <remote> tags at all."
fi
sed -ne '/^[[:space:]]\+[^[:space:]]/q1' "${local_manifest}"
if [ $? -ne 0 ]; then
die "Your local manifest will be clobbered running cros_workon. You can not have any tags that span multiple lines or are indented."
fi
egrep -q "^[^<]" "${local_manifest}"
if [ $? -ne 1 ]; then
die "Your local manifest will be clobbered running cros_workon. You can not have any tags that span multiple lines"
fi
grep -v "<project" "${local_manifest}" | grep -q -i "<project"
if [ $? -eq 0 ]; then
die "Your local manifest has mixed case tags for project. You can not have mixed case tags"
fi
fi
# preserve old manifest entries
[ -f "${local_manifest}" ] && \
MANIFEST_ENTRIES_OLD=$(cat "${local_manifest}" | grep "^<project")