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

Breaking changes in 1.3.9 #479

Closed
arrilot opened this issue May 10, 2023 · 2 comments
Closed

Breaking changes in 1.3.9 #479

arrilot opened this issue May 10, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@arrilot
Copy link

arrilot commented May 10, 2023

🔧 Summary

Lefthook version

1.3.9 - 1.3.12

Steps to reproduce

post-merge
  commands:
    010_composer_i:
      files: "git diff-tree -r --name-only --no-commit-id HEAD@{1} HEAD"
      glob: "composer.lock"
      skip:
        - rebase
        - merge
      run: "echo {files} | composer install"
post-checkout:
  commands:
    010_composer_i:
      files: "git diff-tree -r --name-only --no-commit-id HEAD@{1} HEAD"
      glob: "composer.lock"
      skip:
        - merge
        - rebase
      run: "echo {files} | composer install"

It works great in 1.3.8, but 1.3.9 introduces a breaking change there resulting in an error 128

LEFTHOOK_VERBOSE=1 git checkout -b test-h5
Switched to a new branch 'test-h5'
Lefthook v1.3.12
SYNCING
SERVED HOOKS: pre-commit, post-merge, post-checkout, prepare-commit-msg
RUNNING HOOK: post-checkout
[lefthook] cmd: [sh -c git diff-tree -r --name-only --no-commit-id HEAD@49c5332d4d16feb7837269813a5ee3956b134b36 HEAD]
[lefthook] err: exit status 128
[lefthook] out: fatal: ambiguous argument 'HEAD@49c5332d4d16feb7837269813a5ee3956b134b36': unknown revision or path not in the working tree.
error replacing {files}: exit status 128

Possible Solution

I COULD possibly switch to a new proposed syntax

post-merge:
  commands:
    010_composer_i:
      files: "git diff --name-only {1} {2}"
      glob: "composer.lock"
      skip:
        - merge
        - rebase
      run: "composer install"
post-checkout:
  commands:
    010_composer_i:
      files: "git diff --name-only {1} {2}"
      glob: "composer.lock"
      skip:
        - rebase
        - merge
      run: "composer install"

It works fine for post-checkout, but unfortunately in fails for post-merge

LEFTHOOK_VERBOSE=1 git checkout -b test-h6 #everything is fine
#change composer.lock and commit changes
LEFTHOOK_VERBOSE=1 git checkout test-h5 #everything is fine
LEFTHOOK_VERBOSE=1 git merge test-h6
Updating 49c5332d4..19edb0eda
Fast-forward
 composer.lock | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Lefthook v1.3.12
RUNNING HOOK: post-merge
[lefthook] cmd: [sh -c git diff --name-only 0 {2}]
[lefthook] err: exit status 128
[lefthook] out: fatal: ambiguous argument '0': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:                                           
'git <command> [<revision>...] -- [<file>...]'                                                  
                                                                                                
error replacing {files}: exit status 128
010_composer_i: (skip) error

Am i missing smth?

@arrilot arrilot added the bug Something isn't working label May 10, 2023
@mrexox
Copy link
Member

mrexox commented May 11, 2023

Hey! I remember this change and I'm sorry it broke your configuration. This feature makes sense since we used to have arguments references in run option, so it feels OK to have it in files. I guess that I can add a special check to skip replacement if there's a leading HEAD before the brackets. I'll put this issue on my radar.

I'd like to provide some workarounds in case you want a quick solution:

Use HEAD~1

I think this variant is preferred.

post-checkout:
  commands:
    010_composer_i:
      files: "git diff-tree -r --name-only --no-commit-id HEAD~1 HEAD"
      ...

Use HEAD^1

post-checkout:
  commands:
    010_composer_i:
      files: "git diff-tree -r --name-only --no-commit-id HEAD^1 HEAD"
      ...

@arrilot
Copy link
Author

arrilot commented May 11, 2023

Thank you for your quick response.

I ended with the following configuration and it seems to work fine.

post-merge:
  commands:
    010_composer_i:
      files: "git diff-tree -r --name-only --no-commit-id HEAD^1 HEAD"
      glob: "composer.lock"
      skip:
        - merge
        - rebase
      run: "composer install"
post-checkout:
  commands:
    010_composer_i:
      files: "git diff --name-only {1} {2}"
      glob: "composer.lock"
      skip:
        - rebase
        - merge
      run: "composer install"

Closing it for now

@arrilot arrilot closed this as completed May 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants