Test to determine if clone git command is executed

I tried to clone the git repository by passing username, password. It was a success.

But my intention is that I want to know if the clone git command is executed or not. If not, I would like to handle such errors in the shell script itself.

My working shell script:

cd .. git clone https://username: password@bitbucket.org /username/repositoryname.git cd repositoryname git checkout branchname1 cd .. mv repositoryname newfoldername git clone https://username: password@bitbucket.org /username/respositoryname.git cd repositoryname git checkout branchname2 cd .. mv repositoryname newfoldername 

How to check in a script if these steps were successful?

+6
source share
3 answers

The return value is stored in $ ?. 0 indicates success, others indicate an error.

 some_command if [ $? -eq 0 ]; then echo OK else echo FAIL fi 

I have not tried it with git, but hope this works.

+7
source
 if some_command then echo "Successful" fi 

Example

 if ! git clone http://example.com/repo.git then echo "Failed" else echo "Successful" fi 

See How to determine if a git clone has completed in a bash script .

+2
source

This should work (just put your script in the place indicated by "--- your script here ---" below):

 #!/bin/bash # call your script with set -e to stop on the first error bash <<EOF set -e --- your script here --- EOF # test status: I don't want this part to stop on the first error, # and that why use the HERE document above to wrap a sub-shell for "set -e" if [ $? -eq 0 ]; then echo success else echo fail fi 

Alternatively, the HERE document may be replaced by:

 ( set -e --- your script here --- ) 
0
source

Source: https://habr.com/ru/post/977806/


All Articles