From 9be0d632d836d596b121eca03ece49b4f2e7fc8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Fri, 21 Feb 2014 17:10:09 +0100 Subject: [PATCH 4/4] Pass branches and tags as symbolic refs. Now, the checkout phase is fully aware of what we were checking out, and even 'git branch' shows correct value after the checkout. --- eclass/git-r3.eclass | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/eclass/git-r3.eclass b/eclass/git-r3.eclass index fd3610d..a50890d 100644 --- a/eclass/git-r3.eclass +++ b/eclass/git-r3.eclass @@ -322,7 +322,7 @@ git-r3_fetch() { # try to fetch from the remote local r success for r in "${repos[@]}"; do - einfo "Fetching ${remote_ref} from ${r} ..." + einfo "Fetching ${r} ..." local fetch_command=( git fetch --prune "${r}" @@ -335,7 +335,20 @@ git-r3_fetch() { set -- "${fetch_command[@]}" echo "${@}" >&2 if "${@}"; then - set -- git update-ref "${local_ref}" "${remote_ref}" + # now let's see what the user wants from us + local full_remote_ref=$( + git rev-parse --verify --symbolic-full-name "${remote_ref}" + ) + + if [[ ${full_remote_ref} ]]; then + # when we are given a ref, create a symbolic ref + # so that we preserve the actual argument + set -- git symbolic-ref "${local_ref}" "${full_remote_ref}" + else + # otherwise, we were likely given a commit id + set -- git update-ref --no-deref "${local_ref}" "${remote_ref}" + fi + echo "${@}" >&2 if ! "${@}"; then die "Referencing ${remote_ref} failed (wrong ref?)." @@ -422,6 +435,9 @@ git-r3_checkout() { die "Logic error: no local clone of ${repos[0]}. git-r3_fetch not used?" fi fi + local remote_ref=$( + git symbolic-ref --quiet refs/git-r3/"${local_id}"/__main__ + ) local new_commit_id=$( git rev-parse --verify refs/git-r3/"${local_id}"/__main__ ) @@ -434,9 +450,14 @@ git-r3_checkout() { local -x GIT_DIR=${out_dir}/.git local -x GIT_WORK_TREE=${out_dir} - set -- git checkout --quiet "${new_commit_id}" + set -- git checkout --quiet + if [[ ${remote_ref} ]]; then + set -- "${@}" "${remote_ref#refs/heads/}" + else + set -- "${@}" "${new_commit_id}" + fi echo "${@}" >&2 - "${@}" || die "git checkout ${new_commit_id} failed" + "${@}" || die "git checkout ${remote_ref:-${new_commit_id}} failed" } git-r3_sub_checkout @@ -463,7 +484,7 @@ git-r3_checkout() { echo " at the commit: ${new_commit_id}" fi fi - git update-ref refs/git-r3/"${local_id}"/{__old__,__main__} || die + git update-ref --no-deref refs/git-r3/"${local_id}"/{__old__,__main__} || die # recursively checkout submodules if [[ -f ${out_dir}/.gitmodules ]]; then -- 1.9.0