question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Access input file names in system hooks?

See original GitHub issue

Is there a way to access the input filename for system hooks? I’m trying to run sort --output $file $file on a set of simple Yaml files containing only key-value pairs.

repos:
  - repo: local
    hooks:
      - id: sort-simple-yaml
        name: Sort simple YAML files
        entry: sort --output $file $file
        language: system
        files: .+\.yml

Related: https://github.com/pre-commit/pre-commit/issues/522

I tried sort-simple-yaml but couldn’t get it to sort even when setting files explicitly.

repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v2.3.0
    hooks:
      - id: sort-simple-yaml
        files: ^.*\.yml$ # nothing happens

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
janoshcommented, Jun 20, 2022

Cool, didn’t know about the file-contents-sorter hook. Will use that then.

Just to confirm, there’s no documented way to access the file name in an entry field?

1reaction
asottilecommented, Jun 20, 2022

just tried it, seems to work fine to me?

$ pre-commit run --all-files
file contents sorter.....................................................Failed
- hook id: file-contents-sorter
- exit code: 1
- files were modified by this hook

Sorting test.yml
Read more comments on GitHub >

github_iconTop Results From Across the Web

Access the changed files path in git pre-receive hook
I'm wondering if there is a temporary location where the files are saved in git as soon as they are pushed so that...
Read more >
Git Hooks
We'll cover most of the major hook filenames here. Client-Side Hooks. There are a lot of client-side hooks. This section splits them into...
Read more >
Handling Multiple File Uploads With React Hook Form
In this article, we are going to discuss how to work on multiple file uploads with the React Hook Form.
Read more >
File hooks - GitLab Docs
Inside the file_hooks directory, create a file with a name of your choice, without spaces or special characters. Make the hook file executable...
Read more >
Git Hooks | Atlassian Git Tutorial
If you take a look inside .git/hooks , you'll find the following files: ... Then, it calls git symbolic-ref --short HEAD to get...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found