1

I am writing a script in node.js to clone a git repository.

 const { exec } = require('child_process');
 exec('git clone <path>.git', (err, stdout, stderr) => {
        if(err){
          return;
        }

        console.log(`stdout: ${stdout}`);
        console.log(`stderr: ${stderr}`);
      });

I need to pass the passphrase key in order to clone using the public key. How to pass it in the single line as an argument for exec('git clone <path>.git'

Passphrase should pass as a param and it should not be saved

Rather than moving in to 2 steps is it possible to do in a single step?

Timir
  • 1,395
  • 8
  • 16
not 0x12
  • 19,360
  • 22
  • 67
  • 133

2 Answers2

1

Looks like git clone will not take a passphrase on the command line. But your node script can read command line arguments. Then you should be able to pass the credentials to the git using node-expect.

Timir
  • 1,395
  • 8
  • 16
  • You're right, it's not being actively maintained. The other alternatives are a) node-expect substitutes from npm, b) expect/shell script wrapper over git, exec'ed from your node script, c) replace the node script altogether by expect/shell script – Timir May 08 '18 at 05:11
1

In order to clone a repository I have used the following library

    var cmd = require('node-cmd');
    cmd.get(
      `
        git clone <repo-name>
      `,
      function(err, data, stderr){
          console.log(data);
        }
      );

And it worked like a charm

not 0x12
  • 19,360
  • 22
  • 67
  • 133