javascriptnode.jsbashgitshelljs

Do something based on echo text


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
}

Solution

  • I ended up using this:

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

    This worked perfectly.