Fall back to origin/<branch> when local branch does not exist
This commit is contained in:
parent
8a09c702df
commit
21709f8eaf
@ -29,19 +29,29 @@ esac
|
||||
CURRENT_BRANCH="$(git -C "${SCRIPT_DIR}" branch --show-current 2>/dev/null || echo '')"
|
||||
|
||||
if [[ "${CURRENT_BRANCH}" != "${PRODUCT_BRANCH}" ]]; then
|
||||
# Resolve the git ref: prefer local branch, fall back to remote tracking branch
|
||||
if git -C "${SCRIPT_DIR}" rev-parse --verify "${PRODUCT_BRANCH}" &>/dev/null; then
|
||||
GIT_REF="${PRODUCT_BRANCH}"
|
||||
elif git -C "${SCRIPT_DIR}" rev-parse --verify "origin/${PRODUCT_BRANCH}" &>/dev/null; then
|
||||
GIT_REF="origin/${PRODUCT_BRANCH}"
|
||||
else
|
||||
echo "ERROR: branch '${PRODUCT_BRANCH}' not found locally or as origin/${PRODUCT_BRANCH}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Extract files/ from the correct branch into a temporary directory
|
||||
echo "==> Current branch is '${CURRENT_BRANCH}'; extracting ${PRODUCT} build files from '${PRODUCT_BRANCH}'"
|
||||
echo "==> Current branch is '${CURRENT_BRANCH}'; extracting ${PRODUCT} build files from '${GIT_REF}'"
|
||||
BUILD_FILES_DIR="$(mktemp -d)"
|
||||
trap 'rm -rf "${BUILD_FILES_DIR}"' EXIT
|
||||
|
||||
git -C "${SCRIPT_DIR}" show \
|
||||
"${PRODUCT_BRANCH}:files/add-${PRODUCT}-support.sh" \
|
||||
"${GIT_REF}:files/add-${PRODUCT}-support.sh" \
|
||||
> "${BUILD_FILES_DIR}/add-${PRODUCT}-support.sh"
|
||||
|
||||
while IFS= read -r patch; do
|
||||
git -C "${SCRIPT_DIR}" show "${PRODUCT_BRANCH}:files/${patch}" \
|
||||
git -C "${SCRIPT_DIR}" show "${GIT_REF}:files/${patch}" \
|
||||
> "${BUILD_FILES_DIR}/${patch}"
|
||||
done < <(git -C "${SCRIPT_DIR}" ls-tree --name-only "${PRODUCT_BRANCH}:files/" \
|
||||
done < <(git -C "${SCRIPT_DIR}" ls-tree --name-only "${GIT_REF}:files/" \
|
||||
| grep '\.patch$')
|
||||
else
|
||||
BUILD_FILES_DIR="${SCRIPT_DIR}/files"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user