I tried to clone the git repository by passing the username, password. That was successful.
But what my intention is that I want to know whether the git clone command executed or not. If not, I would like to handle such kind of errors in shell script itself.
My working shell script:
cd ..
git clone https://username:[email protected]/username/repositoryname.git
cd repositoryname
git checkout branchname1
cd ..
mv repositoryname newfoldername
git clone https://username:[email protected]/username/respositoryname.git
cd repositoryname
git checkout branchname2
cd ..
mv repositoryname newfoldername
How do I test, in the script, whether these steps were successful?
You successfully cloned a Git repository into a specific folder on your server. In this case, you cloned the master branch from your Git remote repository. You can check the current branch cloned by running the “git branch” command.
Cloning an entire repo is standard operating procedure using Git. Each clone usually includes everything in a repository. That means when you clone, you get not only the files, but every revision of every file ever committed, plus the history of each commit.
Use the git status command, to check the current state of the repository.
The return value is stored in $?. 0 indicates success, others indicates error.
some_command
if [ $? -eq 0 ]; then
echo OK
else
echo FAIL
fi
I haven't tried it with git, but I hope this works.
if some_command
then
echo "Successful"
fi
if ! git clone http://example.com/repo.git
then
echo "Failed"
else
echo "Successful"
fi
See How to detect if a git clone failed in a bash script.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With