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

Command not found on run #253

Closed
tomkys144 opened this issue Jan 11, 2022 · 10 comments
Closed

Command not found on run #253

tomkys144 opened this issue Jan 11, 2022 · 10 comments

Comments

@tomkys144
Copy link

Hi,
when running pre-commit hook (either by git commit or by lefthook run) I get "command not found" error although in command line and in shell scripts everything works just fine...

config:

pre-commit:
  piped: true
  commands:
    1_lint_code:
      glob: '*.dart'
      run: dart fix --apply lib && git add .
    2_format_code:
      glob: '*.dart'
      run: flutter format {staged_files} && git add {staged_files}

Shell output:

Lefthook v0.7.7
RUNNING HOOKS GROUP: pre-commit

  EXECUTE > 1_lint_code
 sh: line 1: dart: command not found


 2_format_code (SKIP BY BROKEN PIPE)

SUMMARY: (done in 0.01 seconds)
🥊  1_lint_code

And in none-pipe mode:

Lefthook v0.7.7
RUNNING HOOKS GROUP: pre-commit

  EXECUTE > 1_lint_code
 sh: line 1: dart: command not found


  EXECUTE > 2_format_code
 sh: line 1: flutter: command not found


SUMMARY: (done in 0.02 seconds)
🥊  1_lint_code
🥊  2_format_code
@mrexox
Copy link
Member

mrexox commented Aug 11, 2022

Hey! Do you edit your PATH env in .bashrc or something? Or maybe you have an alias? How are dart and flutter installed on your system?

@art-solopov
Copy link

I'm having a similar problem. I've aliased docker-compose to docker compose but it still doesn't work. Does lefthook not respect aliases?

@mrexox
Copy link
Member

mrexox commented Aug 31, 2022

@art-solopov, did you write an alias in .bashrc or .zshrc? Lefthook uses sh as a shell, this might be a reason.

@qasim90
Copy link

qasim90 commented Sep 12, 2022

@mrexox I can print PATH contents from sh with echo $PATH and it outputs all paths correctly but still Lefthook gives this error sh: flutter command not found when trying to commit. What is the solution?

@mrexox
Copy link
Member

mrexox commented Nov 1, 2022

@qasim90 , could you provide more context?

  • Where does flutter locate?
  • What is your lefthook.yml?
  • What is your lefthook version?

Maybe you have a public project, so I could reproduce the issue?

@mrexox
Copy link
Member

mrexox commented Dec 12, 2022

I guess that the issue is related to some $PATH env var tweaks. Try setting rc for newest version of lefthook and feel free to open a new issue/discussion if it doesn't help. I am closing this issue.

@mrexox mrexox closed this as completed Dec 12, 2022
@nerder
Copy link

nerder commented Jun 16, 2023

The problem with this is that probably most people define their .lefthookrc they do something like that.

PATH="$PATH:$USER/flutter/bin"

this will not work with the " in the RC files, without the double quotes instead it will work. This is probably an issue with lefthook and how is running commands in a sub-shell.

cc @mrexox

@mrexox
Copy link
Member

mrexox commented Jun 19, 2023

@nerder , can you please provide your lefthook.yml and .lefthookrc file? It will help me better understand the issue.

@nerder
Copy link

nerder commented Jun 25, 2023

lefthook.yml

rc: ~/.lefthookrc

pre-push:
  parallel: true
  commands:
    linter:
      run: flutter analyze
    tests:
      interactive: true
      run: flutter test --coverage

pre-commit:
  parallel: true
  commands:
    check-secrets:
      interactive: true
      run: bash -c '${TALISMAN_HOME}/talisman_hook_script pre-commit'
    pretty:
      glob: '*.dart'
      exclude: '.*freezed\.dart|.*g\.dart|.*mocks\.dart'
      run: dart format -l 100 {staged_files} && git add {staged_files}

.lefthook.rc

PATH="$PATH:$USER/flutter/bin"

This wasn't working while running on the latest Ubuntu and latest version of lefthook, removing double-quotes fixes it

@mrexox
Copy link
Member

mrexox commented Jun 26, 2023

@nerder, thank you for the example. Have your tried doing something like echo $PATH in one of the run options? How does the result change with double quotes and without them?

# lefthook.yml
...
pre-commit:
  parallel: true
  commands:
    pretty:
      glob: '*.dart'
      exclude: '.*freezed\.dart|.*g\.dart|.*mocks\.dart'
      # print $PATH -- how does this differ with and without quotes?
      run: |
        echo $PATH 
        dart format -l 100 {staged_files} && git add {staged_files}

Also, do you have paths like $USER/flutter/bin? Shouldn't it be $HOME/flutter/bin?

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

No branches or pull requests

5 participants