Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --pre-commit mode #78

Closed
zimbatm opened this issue Feb 27, 2021 · 7 comments
Closed

Add --pre-commit mode #78

zimbatm opened this issue Feb 27, 2021 · 7 comments
Labels
enhancement New feature or request
Milestone

Comments

@zimbatm
Copy link
Member

zimbatm commented Feb 27, 2021

Some developers like to invoke the formatters just before committing the code.

When invoked, it should only format the code that has been staged for the commit and not touch the rest.

This can be done like this: https://stackoverflow.com/a/26911078
And also probably check for unresolved merge commits before and abort if that's the case.

@zimbatm zimbatm added this to the Release 0.2 milestone Feb 27, 2021
@zimbatm zimbatm added the enhancement New feature or request label Mar 5, 2021
@zimbatm zimbatm assigned Rizary and unassigned Rizary Apr 10, 2021
@zimbatm zimbatm modified the milestones: Release 0.2, Release 0.3 Apr 10, 2021
@ocharles
Copy link

I've ended up using pre-commit with this:

repos:
  - repo: local
    hooks:
      - id: treefmt
        name: treefmt
        entry: treefmt
        language: system
        always_run: true

Seems to work well!

@zimbatm
Copy link
Member Author

zimbatm commented May 11, 2022

What behaviour does it have if the commit is not fully formatted? Is it updating the commit with the fixed code, or aborting with an error?

@ocharles
Copy link

It formats the code, and then because files have changed pre-commit aborts the commit.

@loicreynier
Copy link
Contributor

A .pre-commit-hooks.yaml file could also be added to this repository such as

- id: treefmt
  name: treefmt
  description: Format code with treefmt
  entry: treefmt
  language: rust
  minimum_pre_commit_version: 1.18.1

so that pre-commit could download and install (with Cargo and from crates) treefmt with

repos:
  - repo: https://github.com/numtide/treefmt
    rev: master
    hooks:
      - id: treefmt

zimbatm added a commit that referenced this issue May 12, 2022
This is working towards #78 . In the end that script would be shipped
with the treefmt binary, but for now let's just test it out.
@zimbatm
Copy link
Member Author

zimbatm commented May 12, 2022

The pre-commit framework is a bit heavy for my taste so I wrote a bash script to replace it (see #166). I think both approaches are valid, depending on if you use nix to pull the dependencies or not. If you don't then it's nice to have all the machinery that's provided by the pre-commit python code.

zimbatm added a commit that referenced this issue May 12, 2022
This is working towards #78 . In the end that script would be shipped
with the treefmt binary, but for now let's just test it out.
brianmcgee pushed a commit to brianmcgee/treefmt that referenced this issue Dec 9, 2022
This is working towards numtide#78 . In the end that script would be shipped
with the treefmt binary, but for now let's just test it out.
@nikolay
Copy link

nikolay commented Oct 7, 2023

@zimbatm We do use it though, and I've personally been waiting for Lefthook to take over, but it hasn't happened yet, and pre-commit is the king still. Adding a simple YAML file here in the repo would solve elegantly the problem for those of us having to use pre-commit for the time being.

@brianmcgee
Copy link
Member

This is now being tracked here #311

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants