Skip to content

Lefthook does not stash untracked files #833

Open
@j-chmielewski

Description

🔧 Summary

This may be me misunderstanding lefthook's philosophy, but after reading through those issues and PRs:

I was convinced that lefthook stashes the changes before running pre-commit hooks. It seems to me however that this does not include untracked files. This means that if I add new files to the project without staging them, then they will be a part of hook's evaluation unless I explicitly specify the files for the linting / formatting tool with {staged_files} placeholder.

This is an issue for me since in our projects we often prepare npm scripts, like:

    "lint": "pnpm lint:prettier && pnpm lint:eslint && astro check && tsc",
    "lint:eslint": "eslint --max-warnings=0 src",
    "lint:prettier": "prettier 'src/**/*.{js,jsx,ts,tsx,astro,scss,css,json,mdx,md}' --check",
    "fix": "pnpm fix:prettier && pnpm fix:eslint",
    "fix:eslint": "eslint --fix src",
    "fix:prettier": "prettier 'src/**/*.{js,jsx,ts,tsx,astro,scss,css,json,mdx,md}' --write",

Those are pretty elaborate and I'd like to avoid rewriting and duplicating them in lefthook config file. Ideally lefthook would just run the scripts and the scripts would only see staged files. This is achievable by simply stashing all the changes - including new, untracked files, like git stash -a does.

I suspect that this may be in conflict with the {all_files} placeholder. If that's the case then is there an elegant way to achieve what I'm trying to do?

Lefthook version

1.7.18

Steps to reproduce

https://github.com/j-chmielewski/lefthook-unstaged-file

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions