scripts/functions: Fix CT_ExtractGit function.

Change CT_ExtractGit so that it clones the repository, instead of just
symlinking it.  After cloning, any given ref is checked out, or if no
ref is given, the HEAD of the repository is checked out.

This makes CT_Extract behave similar for git repositories as it does
for tarballs, so that it for example can be used for passing glibc-ports
as a git repository.

Signed-off-by: "Esben Haabendal" <esben.haabendal@prevas.dk>
[yann.morin.1998@anciens.enib.fr: fix incomplete var rename]
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
This commit is contained in:
Yann E. MORIN" 2011-10-07 15:06:44 +02:00 committed by Esben Haabendal
parent 91e01072fe
commit 0c06bd8cae

View File

@ -787,26 +787,27 @@ CT_Extract() {
CT_Popd CT_Popd
} }
# Create a working git clone # Create a working git clone of a local git repository
# Usage: CT_ExtractGit <basename> [ref] # Usage: CT_ExtractGit <basename> [ref]
# where 'ref' is the reference to use: # where 'ref' is the reference to use:
# the full name of a branch, like "remotes/origin/branch_name" # the full name of a branch, like "remotes/origin/branch_name"
# a date as understandable by git, like "YYYY-MM-DD[ hh[:mm[:ss]]]" # a date as understandable by git, like "YYYY-MM-DD[ hh[:mm[:ss]]]"
# a tag name # a tag name
# If 'ref' is not given, the current repository HEAD will be used
CT_ExtractGit() { CT_ExtractGit() {
local basename="${1}" local basename="${1}"
local ref="${2}" local ref="${2}"
local clone_dir local repo
local ref_type local ref_type
# pushd now to be able to get git revlist in case ref is a date # pushd now to be able to get git revlist in case ref is a date
clone_dir="${CT_TARBALLS_DIR}/${basename}" repo="${CT_TARBALLS_DIR}/${basename}"
CT_Pushd "${clone_dir}" CT_Pushd "${repo}"
# What kind of reference is ${ref} ? # What kind of reference is ${ref} ?
if [ -z "${ref}" ]; then if [ -z "${ref}" ]; then
# Don't update the clone, keep as-is ref_type=head
ref_type=none ref=$(git rev-list -n1 HEAD)
elif git tag |grep -E "^${ref}$" >/dev/null 2>&1; then elif git tag |grep -E "^${ref}$" >/dev/null 2>&1; then
ref_type=tag ref_type=tag
elif git branch -a --no-color |grep -E "^. ${ref}$" >/dev/null 2>&1; then elif git branch -a --no-color |grep -E "^. ${ref}$" >/dev/null 2>&1; then
@ -818,15 +819,17 @@ CT_ExtractGit() {
CT_Abort "Reference '${ref}' is an incorrect git reference: neither tag, branch nor date" CT_Abort "Reference '${ref}' is an incorrect git reference: neither tag, branch nor date"
fi fi
CT_DoExecLog DEBUG rm -f "${CT_SRC_DIR}/${basename}"
CT_DoExecLog ALL ln -sf "${clone_dir}" "${CT_SRC_DIR}/${basename}"
case "${ref_type}" in
none) ;;
*) CT_DoExecLog FILE git checkout "${ref}";;
esac
CT_Popd CT_Popd
CT_DoExecLog FILE rmdir "${basename}"
case "${ref_type}" in
branch) CT_DoExecLog FILE git clone -b "${ref}" "${repo}" "${basename}" ;;
*) CT_DoExecLog FILE git clone "${repo}" "${basename}"
CT_Pushd "${basename}"
CT_DoExecLog FILE git checkout "${ref}"
CT_Popd
;;
esac
} }
# Patches the specified component # Patches the specified component