scripts/functions: Fix CT_ExtractGit function.
authorEsben Haabendal <esben.haabendal@prevas.dk>
Fri Oct 07 15:06:44 2011 +0200 (2011-10-07)
changeset 27217b64746b0ab3
parent 2720 60503af6d9a9
child 2722 ca0322db584f
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>
scripts/functions
     1.1 --- a/scripts/functions	Thu Oct 13 19:16:04 2011 +0200
     1.2 +++ b/scripts/functions	Fri Oct 07 15:06:44 2011 +0200
     1.3 @@ -787,26 +787,27 @@
     1.4      CT_Popd
     1.5  }
     1.6  
     1.7 -# Create a working git clone
     1.8 +# Create a working git clone of a local git repository
     1.9  # Usage: CT_ExtractGit <basename> [ref]
    1.10  # where 'ref' is the reference to use:
    1.11  #   the full name of a branch, like "remotes/origin/branch_name"
    1.12  #   a date as understandable by git, like "YYYY-MM-DD[ hh[:mm[:ss]]]"
    1.13  #   a tag name
    1.14 +# If 'ref' is not given, the current repository HEAD will be used
    1.15  CT_ExtractGit() {
    1.16      local basename="${1}"
    1.17      local ref="${2}"
    1.18 -    local clone_dir
    1.19 +    local repo
    1.20      local ref_type
    1.21  
    1.22      # pushd now to be able to get git revlist in case ref is a date
    1.23 -    clone_dir="${CT_TARBALLS_DIR}/${basename}"
    1.24 -    CT_Pushd "${clone_dir}"
    1.25 +    repo="${CT_TARBALLS_DIR}/${basename}"
    1.26 +    CT_Pushd "${repo}"
    1.27  
    1.28      # What kind of reference is ${ref} ?
    1.29      if [ -z "${ref}" ]; then
    1.30 -        # Don't update the clone, keep as-is
    1.31 -        ref_type=none
    1.32 +        ref_type=head
    1.33 +        ref=$(git rev-list -n1 HEAD)
    1.34      elif git tag |grep -E "^${ref}$" >/dev/null 2>&1; then
    1.35          ref_type=tag
    1.36      elif git branch -a --no-color |grep -E "^. ${ref}$" >/dev/null 2>&1; then
    1.37 @@ -818,15 +819,17 @@
    1.38          CT_Abort "Reference '${ref}' is an incorrect git reference: neither tag, branch nor date"
    1.39      fi
    1.40  
    1.41 -    CT_DoExecLog DEBUG rm -f "${CT_SRC_DIR}/${basename}"
    1.42 -    CT_DoExecLog ALL ln -sf "${clone_dir}" "${CT_SRC_DIR}/${basename}"
    1.43 +    CT_Popd
    1.44  
    1.45 +    CT_DoExecLog FILE rmdir "${basename}"
    1.46      case "${ref_type}" in
    1.47 -        none)   ;;
    1.48 -        *)      CT_DoExecLog FILE git checkout "${ref}";;
    1.49 +        branch) CT_DoExecLog FILE git clone -b "${ref}" "${repo}" "${basename}" ;;
    1.50 +        *)      CT_DoExecLog FILE git clone "${repo}" "${basename}"
    1.51 +                CT_Pushd "${basename}"
    1.52 +                CT_DoExecLog FILE git checkout "${ref}"
    1.53 +                CT_Popd
    1.54 +                ;;
    1.55      esac
    1.56 -
    1.57 -    CT_Popd
    1.58  }
    1.59  
    1.60  # Patches the specified component