Skip to content

Bug: Windows - $'\r': command not found #103

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

Closed
Braunson opened this issue Feb 13, 2020 · 8 comments
Closed

Bug: Windows - $'\r': command not found #103

Braunson opened this issue Feb 13, 2020 · 8 comments

Comments

@Braunson
Copy link

Braunson commented Feb 13, 2020

Commit failed - exit code 1 received, with output: '.git/hooks/pre-commit: line 2: $'\r': command not found
committing as 
/usr/bin/env: php: No such file or directory'

When trying to commit via GitHub Desktop on Windows 10..

This is what my composer.json looks like...

"extra": {
    "laravel": {
        "dont-discover": []
    },
    "hooks": {
        "pre-commit": [
            "echo committing as $(git config user.name)",
            "vendor/bin/php-cs-fixer fix --using-cache=no ."
        ],
        "commit-msg": "grep -q '[A-Z]+-[0-9]+.*' $1",
        "pre-push": [
            "vendor/bin/php-cs-fixer fix --dry-run --using-cache=no .",
            "phpunit"
        ],
        "post-merge": "composer update"
    }
},

// ... some lines down

"scripts": {
    "post-install-cmd": "cghooks add --ignore-lock",
    "post-update-cmd": "cghooks update",
} 
@BrainMaestro
Copy link
Owner

Is this windows specific? does it work on linux?

@Braunson
Copy link
Author

Braunson commented Mar 8, 2020

Yeah seems Windows specific. Tested on Linux, no issues. Ran again on Windows and recieved:

Script vendor/bin/cghooks update handling the post-update-cmd event returned with error code 1

"post-update-cmd": "vendor/bin/cghooks update",

Running with composer's verbose flag returns this:

> post-update-cmd: vendor/bin/cghooks update
'vendor' is not recognized as an internal or external command, operable program or batch file.

Interestingly enough, when running vendor/bin/cghooks update directly in PowerShell it runs without issue..

@Braunson Braunson closed this as completed Mar 8, 2020
@Braunson
Copy link
Author

Braunson commented Mar 8, 2020

@BrainMaestro

post-update-cmd: vendor/bin/cghooks update
'vendor' is not recognized as an internal or external command,
operable program or batch file.
Script vendor/bin/cghooks update handling the post-update-cmd event returned with error code 1

        "post-install-cmd": "vendor/bin/cghooks add --ignore-lock",
        "post-update-cmd": "vendor/bin/cghooks update",

Any ideas? Running it directly works, just not within composer's post-install/update-cmd

@Braunson Braunson reopened this Mar 8, 2020
@BrainMaestro
Copy link
Owner

@Braunson looks like some strange behavior with the working directory that the command is run from. can you change the post-install-cmd to pwd or the windows equivalent and see what directory it's run from?

@badmansan
Copy link

I have the same issue on Win 7

"extra": {
	"hooks": {
	  "pre-commit": [
		"vendor/bin/phplint"
	  ]
	}
  }

i try to run vendor/bin/cghooks pre-commit but get

'vendor' is not recognized as an internal or external command,
operable program or batch file.

if change pre-commit section to

"pre-commit": [
		"cd",
		"vendor/bin/phplint"
	  ]

vendor/bin/cghooks pre-commit runs only first command (cd is pwd in win), and it print correct project directory

if change pre-commit section to specific windows syntaxis

"pre-commit": [
		"vendor\\bin\\phplint"
	  ]

vendor/bin/cghooks pre-commit work correctly. But in this case git can't commit:

C:\home\test>git commit
.git/hooks/pre-commit: line 3: vendorbinphplint: command not found

@denitsa-md
Copy link

denitsa-md commented Sep 30, 2020

I am experiencing the same problem on Windows 10 and I found something that could be relevant. I'm trying to set up php-cs-fixer to run pre-commit.

My hooks look like this:

    "hooks": {
      "pre-commit": [
        "php-cs-fixer fix . --config .php_cs.dist --allow-risky=yes"
      ]
    }

(I know this scans the entire code base, but I'm just setting it up and I haven't done the diff-ing yet)

The relevant scripts:

 "scripts": {
    "post-install-cmd": "cghooks add --ignore-lock",
    "post-update-cmd": "cghooks update"
  },

Now the error I get when I try to commit through the Github client is:

Commit failed - exit code 1 received, with output: '.git/hooks/pre-commit: line 2: $'\r': command not found
/usr/bin/env: ‘php’: No such file or directory'

Now, I checked out the hook that gets generated in .git/hooks/pre-commit

It starts with #!/bin/bash.

If I change that to #!/bin/sh I can successfully do my commit.

Then I get the files fixed by php-cs-fixer as newly staged files (not sure this is excatly what I want cause I kind of want to block the commit but have to figure that out).

P.S.

I can see that the change to use bash has been added related to this #8 and this #7

But ironically bash actually breaks it for me.

@BrainMaestro
Copy link
Owner

@denitsa-md I don't have Windows to test this, so I'm not certain how to proceed. I think previous most windows users have bash installed either through cygwin or WSL. Is that the case for you

@BrainMaestro
Copy link
Owner

I will close for inactivity. Feel free to reopen if there is new information

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

4 participants