diff --git a/vendorsetup.sh b/vendorsetup.sh index c0b8e22000ac5972f7503095f8abfd46b92db4b4..b9a9c6b880ff677eb52f447d6ba00a8e4c8ff60a 100644 --- a/vendorsetup.sh +++ b/vendorsetup.sh @@ -1,4 +1,4 @@ -# Copyright (c) 2012-2014, The Linux Foundation. All rights reserved. +# Copyright (c) 2012-2015, The Linux Foundation. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are @@ -56,15 +56,45 @@ __tree_md5sum() ) | openssl dgst -md5 } + +__abandon_branch() +{ + local branch=$1 + local FORCE="$2" + + if [[ -n "$(git branch --list b2g_autogen_ephemeral_branch)" ]]; then + if [[ "$FORCE" != "yes" && $(whoami) != "lnxbuild" ]]; then + if [[ -n $(git status --porcelain) ]]; then + echo + echo "ERROR: Uncommitted changes found in $branch/" + echo " You may force overwriting these changes" + echo " with |source build/envsetup.sh force|" + echo + return 1 + fi + fi + local currentRev=$(${REPO} info -l . | sed -ne 's/^Current revision: \(\w*\)$/\1/p') + git reset --hard $currentRev + git clean -dfx + ${REPO} abandon b2g_autogen_ephemeral_branch . + fi +} + + __abandon_tree() { + local FORCE="$1" rm -f out/lastpatch.md5sum if [[ -d .repo ]]; then - if [[ -f out/lastpatch.projects ]] ; then - ${REPO} abandon b2g_autogen_ephemeral_branch $(cat out/lastpatch.projects) || true - else - ${REPO} abandon b2g_autogen_ephemeral_branch || true - fi + if [[ -f out/lastpatch.projects ]]; then + local projects=$(cat out/lastpatch.projects) + else + local projects=$(repo forall -c 'echo $REPO_PATH') + fi + + for p in $projects; do + cd $p ; __abandon_branch $p "$FORCE" ; cd $OLDPWD + done fi } @@ -95,7 +125,12 @@ __patch_tree() LASTMD5SUM=$(cat out/lastpatch.md5sum) MD5SUM=$(__tree_md5sum ${B2G_PATCH_DIRS}) fi - if [[ "$LASTMD5SUM" != "$MD5SUM" || $1 == "force" ]]; then + FORCE= + if [[ $1 == "force" ]]; then + FORCE=yes + fi + + if [[ "$LASTMD5SUM" != "$MD5SUM" || "yes" == "$FORCE" ]]; then branch() { [[ -d $1 ]] || return 1 @@ -105,17 +140,12 @@ __patch_tree() echo echo [entering $1] if [[ -d .git ]]; then - # Try repo first, but if the project is not repo managed then - # use a raw git branch instead. - ${REPO} start b2g_autogen_ephemeral_branch . || - ( git checkout master && \ - ( git branch -D b2g_autogen_ephemeral_branch || true ) && \ - git branch b2g_autogen_ephemeral_branch && \ - git checkout b2g_autogen_ephemeral_branch \ - ) if [[ -d .git/rebase-apply ]]; then git am --abort fi + + __abandon_branch $1 "$FORCE" + ${REPO} start b2g_autogen_ephemeral_branch . else read -p "Project $1 is not managed by git. Modify anyway? [y/N] " if [[ ${REPLY} != "y" ]]; then @@ -183,7 +213,7 @@ __patch_tree() # Only abandon if there are any patches that need to be applied. if [[ ${#PRJ_LIST[@]} -gt 0 ]] ; then - __abandon_tree + __abandon_tree "$FORCE" rm -f out/lastpatch.projects fi @@ -196,16 +226,19 @@ __patch_tree() ( set -e if branch ${PRJ} ; then - if [[ $1 != "force" && $(whoami) != "lnxbuild" ]]; then + if [[ "$FORCE" != "yes" && $(whoami) != "lnxbuild" ]]; then if [[ -n $(git status --porcelain) ]]; then - echo "ERROR: You have uncommited changes in ${PRJ}" - echo "You may force overwriting these changes" - echo "with |source build/envsetup.sh force|" + echo + echo "ERROR: Uncommitted changes found in ${PRJ}/" + echo " You may force overwriting these changes" + echo " with |source build/envsetup.sh force|" + echo exit 1 fi fi # Ensure the project is clean before applying patches to it - git reset --hard HEAD > /dev/null + local currentRev=$(${REPO} info -l . | sed -ne 's/^Current revision: \(\w*\)$/\1/p') + git reset --hard $currentRev git clean -dfx declare -a PATCHNAME @@ -250,6 +283,7 @@ __patch_tree() ERR=$? if [[ ${ERR} -ne 0 ]]; then + echo ERROR: B2G PATCHES FAILED TO APPLY lunch() { echo ERROR: B2G PATCHES FAILED TO APPLY; return 1; } choosecombo() { lunch; } fi