0

I build VS Code extension I have wrapper in a class like this

public exec(cmd: string): string {
    try {
        return execSync(cmd, { cwd: this.workspaceRoot }).toString();
    }
    catch (e) {
        return '' + e;
    }
}

If in the code I run

let tags = this.exec('git tag --sort=-v:refname')

I do get a list of tags. Actually, all other commands run also correctly like git status, git config and other. But as soon as I run this.

let res = this.exec(`git push origin ${name}`); 

It hangs forever. If I pass wrong tag it stops with error, but if I put correct tag, it suspends. I try to console.log('git push origin ${name}') and then copy result and run that command in a terminal, it runs correctly.

What can be the reason of a such behavior?

Sergey Romanov
  • 2,949
  • 4
  • 23
  • 38
  • 1
    you sure it is not waiting for user input? – mmomtchev Jan 23 '22 at 10:00
  • Yes. If I log that command and run it in the terminal it does not require any user input. – Sergey Romanov Jan 24 '22 at 06:15
  • 1
    Try running `strace git push...` to see the last syscall on which it blocks – mmomtchev Jan 24 '22 at 09:11
  • It does not hang when I run this commang in terminal. `strace` also works. close(1) = 0 exit_group(0) = ? +++ exited with 0 +++ – Sergey Romanov Jan 24 '22 at 09:20
  • 1
    I mean exec it from Node.js and try to retrieve the output – mmomtchev Jan 24 '22 at 09:27
  • Run in terminal `node` and then. `exec('git push origin 1.11.2', (e,so,se)=>{console.log(e,so)});` in prints returned object immediately then after some time `null`. And I do not have `>` on the next line like it is finished execution and ready for next node input. – Sergey Romanov Jan 24 '22 at 11:38
  • 1
    I meant exec it from Node with `strace` – mmomtchev Jan 24 '22 at 11:40
  • same thing, hangs. – Sergey Romanov Jan 24 '22 at 11:41
  • 1
    If you just want to execute git-specific commands, you may consider using a library like [this](https://www.npmjs.com/package/simple-git) one. – Empiire Jan 28 '22 at 09:48
  • @mmomtchev thank you, it was indeed authentication. Somehow VS Code have me authorized in Github, I logged in with that account. So it uses it to run Git commands. But my extension do not use VS Code Git classes, so they do not know auth. I had to authenticate PC with GH CLI for HTTPS and for SSH to add key and it works not both ways. – Sergey Romanov Jan 28 '22 at 15:34

0 Answers0