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

stage_fixed (or equivalent) for changed files not originally staged #806

Open
isturdy opened this issue Aug 14, 2024 · 4 comments
Open

stage_fixed (or equivalent) for changed files not originally staged #806

isturdy opened this issue Aug 14, 2024 · 4 comments
Labels
feature request A new lefthook feature description

Comments

@isturdy
Copy link

isturdy commented Aug 14, 2024

⚡ Summary

IIUC, currently stage_fixed only affects the files originally in the glob. I'm trying to use lefthook for code/documentation generation, and so some steps create/modify files not part of the original staged set/glob results.

Value

Allows using pre-commit for generated files (e.g. documentation)

Behavior and configuration changes

For a silly example, consider a hook that duplicates files:

pre-commit:
  commands:
    clone:
      stage_fixed: true
      glob: "*.txt"
      run: cp {staged_files} backup

I initially expected that this would commit both the manually-created file and its backup, but instead it commits the original file and creates the backup but does not stage/commit it. I would like to see a variant of stage_fixed that also adds any files not originally staged for the commit that change during the command.

@isturdy isturdy added the feature request A new lefthook feature description label Aug 14, 2024
@isturdy
Copy link
Author

isturdy commented Aug 15, 2024

Update: I had thought of using git add within the command but found it unreliable; apparently that stemmed from running it inside docker, and moving it outside fixed that. (On the other hand, I've also found that stage_fixed doesn't seem to work reliably for files changed by something running in Docker.)

@mrexox
Copy link
Member

mrexox commented Aug 16, 2024

I suggest you to use git add in your command, like this:

pre-commit:
  commands:
    clone:
      glob: "*.txt"
      run: cp {staged_files} backup && git add backup/*

Staging everything in lefthook is hard to control and you may surprise to commit something you didn't want to. So, explicitly adding files with && git add ... is an options. What issues did you meet when using it?

@isturdy
Copy link
Author

isturdy commented Aug 21, 2024

Running git add from a script running in Docker consistently errored saying that .git/index.lock already exists, despite no other git processes running.

@mrexox
Copy link
Member

mrexox commented Aug 22, 2024

Could you provide some example of Dockerfile and lefthook.yml, so I could try reproducing this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A new lefthook feature description
Projects
None yet
Development

No branches or pull requests

2 participants