Skip to content

Error "Not a git repository" when trying to execute git command inside of bash script #364

@dcurletti

Description

@dcurletti

I have a bash script:

#ts-precommit.sh

SRC_PATTERN=".*\.(ts|tsx)$"
if git diff --cached --name-only | grep --quiet -E "$SRC_PATTERN"

That I am running like so:

"husky": {
    "hooks": {
      "pre-commit": "sh ./ts-precommit.sh"
    }
  }

And I get the following output:

Not a git repository
To compare two paths outside a working tree:
usage: git diff [--no-index] <path> <path>

Any reasons why I wouldn't be able to call git from the script?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions