Node.js child_process password input for git clone in atom


#1

I am trying to clone a git repository requiring the child_process module of node.js in my atom package:

    var spawn = require('child_process').spawn;
    var gitClone = spawn('git', ['clone', 'ssh://user@gitrepo.com/path/to/reponame'], {cwd: path});

    gitClone.stdout.on('data', (data) => {
		gitClone.stdin.write('password');
		console.log(`stdout: ${data}`);
	});

	gitClone.stderr.on('data', (data) => {
		console.log(`stderr: ${data}`);

	});

	gitClone.on('close', (code) => {
		console.log(`child process exited with code ${code}`);
	});

As it is not possible to use a ssh key, I need to pass the user’s password to the spawned process.

I thought regarding this topic would solve my problem as well, but it seems like there is not a possibility to get into my gitClone.stdout.on('data', function (data) { ... }.
Any console.log() I am trying to perform from in there, will not be displayed on atom’s console.

Here is my output:

    stderr: Cloning into 'reponame'...
    stderr: Permission denied, please try again.
    stderr: Permission denied, please try again.
    stderr: Permission denied (publickey,password).
    stderr: fatal: Could not read from remote repository.
    Please make sure you have the correct access rights and the repository exists.
    child process exited with code 128

I am wondering why I can see only the sdterr-messages. When I run git clone in my bash it first tells me Cloning into 'reponame'..., then it asks for my password.

Is there a way to catch the password prompt in child_process’ spawn()?