Do something based on echo text

74 Views Asked by At

I am using shelljs to git clone in my node app. I want to only do something once the clone is successful. So wanted to so something like this:

shell.exec(`git clone https://myrepo.git; echo "cloned"`);

This returns cloned once my repo is cloned on Google Cloud functions. How do I do something like this:

if echo === 'cloned' {
   //do something
} else {
      //do something else
}
2

There are 2 best solutions below

0
On BEST ANSWER

I ended up using this:

if (shell.exec(`git clone https://myrepo.git`).code === 0) {
    //do something
} else {
   //do something else
}

This worked perfectly.

0
On

use && instead of ; like this:

shell.exec(`git clone https://myrepo.git && echo "cloned"`);

&& means echo "cloned" won't be executed until git clone https://myrepo.git finish successfully.