angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

git: not found

Open mackelito opened this issue 8 years ago • 3 comments

Sorry if this is the wrong place to post this (docker rookie here) but I'm trying to get the git last commit hash using this script

const revision = new Observable<string>(s => {
  exec('git rev-parse --short HEAD',
    function (error: Error, stdout: Buffer, stderr: Buffer) {
      if (error !== null) {
        console.log('git error: ' + error + stderr);
      }
      s.next(stdout.toString().trim());
      s.complete();
    });
});

works fine locally but when using this docker we get

git error: Error: Command failed: git rev-parse --short HEAD
/bin/sh: git: not found
/bin/sh: git: not found

Any hint on how I can move forward?

mackelito avatar Sep 26 '18 22:09 mackelito

I think your git command is not in /bin/sh. You can locate it with:

$ which git
/usr/bin/git

So you have two options:

  • Add /usr/bin/ to your $PATH
  • Change your code: exec('/usr/bin/git rev-parse --short HEAD'...

Hope this can be helpful.

Regards, Alex

alejandroSuch avatar Sep 27 '18 07:09 alejandroSuch

Hmm.. perhaps the docker image needs to have "apk add git" for this to work?

mackelito avatar Sep 27 '18 07:09 mackelito

Of course! if it's a docker image, you should install git

alejandroSuch avatar Oct 09 '18 10:10 alejandroSuch