Home > OS >  fatal: 'webrtmt' does not appear to be a git repository could not read from remote
fatal: 'webrtmt' does not appear to be a git repository could not read from remote

Time:08-25

I have the below shell script named as fetchGitRepo.sh:

#!/bin/bash

if [ -z $1 ]; then
        echo "Missing first argument (git repository path)"
        exit 1
fi
arg=$1
CHECKOUT_DIR=$(pwd)/$arg
BASE_DIR=$(pwd)
set -euo pipefail
basename=${1##*/}

if [[ $# -lt 1 ]]; then
    printf '%s: Clone the latest tag on remote.\n' "$basename" >&2
    printf 'Usage: %s [other args] <remote>\n' "$basename" >&2
    exit 1
fi
remote=${*: -1} # Get last argument
echo BASE_DIR: $(pwd)
echo $CHECKOUT_DIR
if [ "$arg" == "webrtmt" ]; then
        echo $arg >> ${arg}.txt
        [email protected]:CUCM/"$arg".git
        # previousWebrtmtReleaseTag=$(git ls-remote --tags $GITREPO |grep "\."|grep -v -|grep -v {| sort -n -t. -k3 -k4)
        previousWebrtmtReleaseTag=$(git ls-remote --tags --exit-code --refs $remote \
  | sed -E 's/^[[:xdigit:]] [[:space:]] refs\/tags\/(. )/\1/g' | tail -n1)
echo "YYYYYYYYYYYY:"$previousWebrtmtReleaseTag
else
        [email protected]:GoldenGate/"$arg".git
       # recentTag=$(git ls-remote --tags $GITREPO |grep "\."|grep -v -|grep -v {| sort -n -t. -k3 -k4)
       recentTag=$(git ls-remote --tags --exit-code --refs $remote \
  | sed -E 's/^[[:xdigit:]] [[:space:]] refs\/tags\/(. )/\1/g' | tail -n1)
        echo "TTTTTTTTTTTTTTTTTTTTTTTTTT:"$recentTag
fi
echo $CHECKOUT_DIR
# Ensure that we can read the git repo location (NFS)
ls -l ${GITREPO} &> /dev/null

# Ensure that CHECKOUT_DIR exists
mkdir -p ${CHECKOUT_DIR}

# Jump into the checkout location so that we can perform the checkout/pull
 cd ${CHECKOUT_DIR}

function repoclone() {
if [ -n "$username" ]; then
        echo "Build through Jenkins job"
        echo $arg
        if [ "$arg" == "webrtmt" ]; then
                previousWebrtmtReleaseTag=$(git ls-remote --tags https://$username:[email protected]/CUCM/"$arg" |grep "\."|grep -v -|grep -v {| sort -n -t. -k3 -k4)
                tagNumber=${previousWebrtmtReleaseTag##*v}
                echo "webrtmt= v$tagNumber" >> "$arg.txt"
                echo "webrtmt= v$tagNumber" >> durlov.txt
                sh ${BASE_DIR}/git-clone-latest-tag.sh https://$username:[email protected]/CUCM/"$arg"
        else
                recentTag=$(git ls-remote --tags https://$username:[email protected]/GoldenGate/"$arg".git |grep "\."|grep -v -|grep -v {| sort -n -t. -k3 -k4)
                tag = ${recentTag##*v}
                echo "$arg= v$tag" >> "$arg.txt"
                sh ${BASE_DIR}/git-clone-latest-tag.sh https://$username:[email protected]/GoldenGate/"$arg".git
        fi
else
        echo $GITREPO
        if  [ "$arg" == "webrtmt" ]; then
         set -x
            echo "webrtmt= $previousWebrtmtReleaseTag" >> ${arg}.txt
            #git clone -b $ta ${GITREPO}
            echo Current working dir: ${BASE_DIR}
            git remote add ${arg} ${GITREPO}
            #sh ${BASE_DIR}/git-clone-latest-tag.sh ${GITREPO}
            # Ensure that we can read the git repo location (NFS)
            git clone ${GITREPO}
            git checkout tags/$previousWebrtmtReleaseTag
        else
        set -x
            echo "$arg= $recentTag" >> ${arg}.txt
            #git clone -b $tag --single-branch --depth 1 ${GITREPO}
            git remote add ${arg} ${GITREPO}
            #sh ${BASE_DIR}/git-clone-latest-tag.sh ${GITREPO}
            git clone ${GITREPO}
 git checkout tags/$recentTag
        fi
fi
}

if [ ! -d ${CHECKOUT_DIR}/.git ]; then
        cd ${CHECKOUT_DIR}
        # Clone the git repository
        echo "Cloning Git repository to ${CHECKOUT_DIR}"
        repoclone
else
        rm -rf $CHECKOUT_DIR
        echo $CHECKOUT_DIR
        echo "Directory deleted ,new one will be created"
        mkdir -p ${CHECKOUT_DIR}
        cd ${CHECKOUT_DIR}
        repoclone
fi

cd $CHECKOUT_DIR
echo "111111111111111111$CHECKOUT_DIR"
if [ "$arg" == "webrtmt" ]; then
 gradle -Pproduction=true build
else
        make all

fi

when I run this file passing webrtmt as the parameter like this ./fetchGitRepo.sh webrtmt, I get the below error:

enter image description here

Please help on how to fix this. Thanks

CodePudding user response:

From the script in the question, when you run ./fetchGitRepo.sh webrtmt, there are some problems.

remote=${*: -1} # Get last argument

Here remote is assigned the value webrtmt. And then it's used in git ls-remote --tags --exit-code --refs $remote. It's okay to use git ls-remote outside of a git repository, but a valid url is needed. Here $remote is webrtmt. It's an unknown remote and it's not a valid url either. So git ls-remote complains and raises the fatal error.

I think it should be git ls-remote --tags --exit-code --refs $GITREPO instead. The pipeline commands retrieve the expected tags.

ls -l ${GITREPO} &> /dev/null

However, then this command is odd. ${GITREPO} is a url in ssh protocol to a remote repository, and we cannot use ls on it.

I'm afraid you don't pass the right parameters to the script, or the script needs modification.

  • Related