Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
11 kB
1
Indexable
Never
        if [ -f ${CGR_ROOT_DIR}/.git/modules/${agr}/config ]; then
            # Network transfer related optimizations
            ${GIT} -C "${CGR_ROOT_DIR}/.git/modules/${agr}" config remote.origin.promisor 'true'
            ${GIT} -C "${CGR_ROOT_DIR}/.git/modules/${agr}" config remote.origin.partialclonefilter 'blob:none'
            ${GIT} -C "${CGR_ROOT_DIR}/.git/modules/${agr}" config core.sparsecheckout 'true'
            # Tunings from scalar - https://git-scm.com/docs/scalar
            ${GIT} -C "${CGR_ROOT_DIR}/.git/modules/${agr}" config core.fscache 'true'
            ${GIT} -C "${CGR_ROOT_DIR}/.git/modules/${agr}" config core.multipackindex 'true'
            ${GIT} -C "${CGR_ROOT_DIR}/.git/modules/${agr}" config core.preloadindex 'true'
            ${GIT} -C "${CGR_ROOT_DIR}/.git/modules/${agr}" config core.untrackedcache 'true'
            ${GIT} -C "${CGR_ROOT_DIR}/.git/modules/${agr}" config core.autocrlf 'false'
            ${GIT} -C "${CGR_ROOT_DIR}/.git/modules/${agr}" config core.safecrlf 'false'
            ${GIT} -C "${CGR_ROOT_DIR}/.git/modules/${agr}" config am.keepcr 'true'
            ${GIT} -C "${CGR_ROOT_DIR}/.git/modules/${agr}" config gc.auto '0'
            ${GIT} -C "${CGR_ROOT_DIR}/.git/modules/${agr}" config gui.gcwarning 'false'
            ${GIT} -C "${CGR_ROOT_DIR}/.git/modules/${agr}" config pack.usebitmaps 'false'
            ${GIT} -C "${CGR_ROOT_DIR}/.git/modules/${agr}" config pack.usesparse 'true'
            ${GIT} -C "${CGR_ROOT_DIR}/.git/modules/${agr}" config merge.renames 'true'
            ${GIT} -C "${CGR_ROOT_DIR}/.git/modules/${agr}" config index.threads 'true'
            ${GIT} -C "${CGR_ROOT_DIR}/.git/modules/${agr}" config index.version '4'
            ${GIT} -C "${CGR_ROOT_DIR}/.git/modules/${agr}" config merge.stat 'false'
            ${GIT} -C "${CGR_ROOT_DIR}/.git/modules/${agr}" config receive.autogc 'false'
            ${GIT} -C "${CGR_ROOT_DIR}/.git/modules/${agr}" config feature.manyfiles 'false'
            ${GIT} -C "${CGR_ROOT_DIR}/.git/modules/${agr}" config feature.experimental 'false'
            ${GIT} -C "${CGR_ROOT_DIR}/.git/modules/${agr}" config fetch.unpacklimit '1'
            ${GIT} -C "${CGR_ROOT_DIR}/.git/modules/${agr}" config fetch.writecommitgraph 'false'
            ${GIT} -C "${CGR_ROOT_DIR}/.git/modules/${agr}" config fetch.showforcedupdates 'false'
            ${GIT} -C "${CGR_ROOT_DIR}/.git/modules/${agr}" config status.aheadbehind 'false'
            ${GIT} -C "${CGR_ROOT_DIR}/.git/modules/${agr}" config commitgraph.generationversion '1'
            ${GIT} -C "${CGR_ROOT_DIR}/.git/modules/${agr}" config maintenance.auto 'false'
            ${GIT} -C "${CGR_ROOT_DIR}/.git/modules/${agr}" config maintenance.strategy 'incremental'
            # LFS configuration - https://github.com/git-lfs/git-lfs/tree/main/docs
            ${GIT} -C "${CGR_ROOT_DIR}/.git/modules/${agr}" lfs install --local > /dev/null
            ${GIT} -C "${CGR_ROOT_DIR}/.git/modules/${agr}" config filter.lfs.clean 'git-lfs clean -- %f'
            ${GIT} -C "${CGR_ROOT_DIR}/.git/modules/${agr}" config filter.lfs.smudge 'git-lfs smudge -- %f'
            ${GIT} -C "${CGR_ROOT_DIR}/.git/modules/${agr}" config filter.lfs.process 'git-lfs filter-process'
            ${GIT} -C "${CGR_ROOT_DIR}/.git/modules/${agr}" config filter.lfs.required 'true'

        else
            # If this AGR's config file is not yet present in .git/modules,
            # it means that the submodule hasn't been initialized not even once in this local clone
            # so we can craft the config options before the first fetch and make usage of "git submodules absorbgitdirs"
            local agr_url=$( ${GIT} config -f "${CGR_ROOT_DIR}/.gitmodules" submodule.${agr}.url )
            local agr_path=$( ${GIT} config -f "${CGR_ROOT_DIR}/.gitmodules" submodule.${agr}.path )
            local default_branch=$( ${GIT} ls-remote --symref ${agr_url} HEAD | \
                                    grep -oiPe 'refs/heads/(\S+)' | cut -d'/' -f 3 )
            vprint 3 "AGR URL: ${agr_url}"
            vprint 3 "AGR PATH: ${agr_path}"
            vprint 3 "AGR Default branch: ${default_branch}"
            vprint 3 "AGR config path: ${CGR_ROOT_DIR}/${agr_path}"

            # Initialize an inner git repo in the location of where that submodule shoube be.
            ${GIT} -c "init.defaultBranch=${default_branch}" init -q "${CGR_ROOT_DIR}/${agr_path}"
            # Add the remote as per defined in the .gitmodules config file.
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" remote add origin ${agr_url}
            # Network transfer related optimizations
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config remote.origin.promisor 'true'
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config remote.origin.partialclonefilter 'blob:none'
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config core.sparsecheckout 'true'
            # Setting up tracking to origin
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config branch.${default_branch}.remote 'origin'
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config branch.${default_branch}.merge "refs/heads/${default_branch}"
            # Tunings from scalar - https://git-scm.com/docs/scalar
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config core.fscache 'true'
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config core.multipackindex 'true'
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config core.preloadindex 'true'
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config core.untrackedcache 'true'
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config core.autocrlf 'false'
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config core.safecrlf 'false'
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config am.keepcr 'true'
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config gc.auto '0'
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config gui.gcwarning 'false'
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config pack.usebitmaps 'false'
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config pack.usesparse 'true'
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config merge.renames 'true'
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config index.threads 'true'
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config index.version '4'
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config merge.stat 'false'
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config receive.autogc 'false'
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config feature.manyfiles 'false'
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config feature.experimental 'false'
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config fetch.unpacklimit '1'
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config fetch.writecommitgraph 'false'
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config fetch.showforcedupdates 'false'
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config advice.fetchShowForcedUpdates 'false'
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config advice.detachedHead 'false'
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config status.aheadbehind 'false'
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config commitgraph.generationversion '1'
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config maintenance.auto 'false'
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config maintenance.strategy 'incremental'
            # LFS configuration - https://github.com/git-lfs/git-lfs/tree/main/docs
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" lfs install --local > /dev/null
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config filter.lfs.clean 'git-lfs clean -- %f'
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config filter.lfs.smudge 'git-lfs smudge -- %f'
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config filter.lfs.process 'git-lfs filter-process'
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" config filter.lfs.required 'true'

            # --> TODO: Scope redux entry-point before 1st fetch
            #if [[ ${#scope_redux[@]} gt 0 ]]; then
                # entries would have the valid formats of : assembly, BB or ASML CC:
                # -s as_rh_common (1st order folder after the CGR root)
                # -s BB-061-0002A (2nd order folder after the CGR root)
                # -s KD (3rd order folder after after the CGR root)
                # sparse_rules=$(parse_requested_scope_items) # (function with gh api calls)
                # ${GIT} -C "${CGR_ROOT_DIR}/{$agr_path}" sparse-checkout init --cone
                # ${GIT} -C "${CGR_ROOT_DIR}/{$agr_path}" sparse-checkout add ${sparse_rules}
            #fi

            # Fetch to the index area (this is not a checkout!)
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" fetch origin ${default_branch} --quiet --prune
            # Setup the initial branch (created locally) to track the same one fetched from origin
            # (For some odd reason git branch --set-upstream-to didn't work in this case)
            local origin_head=$( ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" rev-parse origin/${default_branch} )
            echo ${origin_head} > "${CGR_ROOT_DIR}/${agr_path}/.git/refs/heads/${default_branch}"
            echo "ref: refs/remotes/origin/${default_branch}" > "${CGR_ROOT_DIR}/${agr_path}/.git/refs/remotes/origin/HEAD"
            # Added decoration for better handling diffs and
            # better human readable configuration file (without the needs to check gitlinks directly).
            local agr_foundation_commit=$( ${GIT} config -f "${CGR_ROOT_DIR}/.gitmodules" submodule.${agr}.revision )

            # If there a no decorated information in the .gitmodules file that shows the foundation commit
            # revert by fetching the foundation commit according to what is described in the gitlink value
            # for this AGR, in the parent project (CGR).
            # TODO: Confirm if this should be based on ${agr} or ${agr_path}.
            if [[ -z ${agr_foundation_commit} ]];then
                agr_foundation_commit=$( ${GIT} -C "${CGR_ROOT_DIR}" ls-files \
                                         --stage | grep '^160000' | grep ${agr} | cut -d' ' -f 2 )
            fi

            vprint 3 "AGR foundation commit to checkout: ${agr_foundation_commit}"
            ${GIT} -C "${CGR_ROOT_DIR}/${agr_path}" checkout --quiet ${agr_foundation_commit}

            [[ $? -ne 0 ]] && vprint 0 "[setup] Unable to checkout AGR ${agr} at required " 1 && \
                              vprint 0 "commit '${agr_foundation_commit}' in target location: ${agr_path}" && exit 1
        fi