Giter VIP home page Giter VIP logo

Comments (7)

neverendingqs avatar neverendingqs commented on June 29, 2024 1

This is the full error after changing the line endings:

> git commit -m "test"
/cygdrive/c/Program Files/nodejs/node
pre-commit:
pre-commit: Received an error while parsing or locating the `package.json` file:
pre-commit:
pre-commit:   Cannot find module '\cygdrive\c\path\to\package.json'
pre-commit:
pre-commit: Skipping the pre-commit hook.
pre-commit:

It looks like it's failing on

"$BINARY" "$("$BINARY" -e "console.log(require.resolve('pre-commit'))")"
.

I am using Cygwin Git with a Windows Node installation. This makes sense to me, since Windows Node probably doesn't understand a non-Windows path.

Using "C:\Program Files\Git\bin\git" commit -m "test" works for me, and surprisingly, with pre-commit containing either line ending. Looks like Windows Git with Windows Node installation works out-of-the-box.

Hopefully this helps!

from pre-commit.

dajaj avatar dajaj commented on June 29, 2024

Same problem with babun on Windows 7, I got this when I try to commit :

: No such file or directory     .git/hooks/pre-commit: line 2: ./node_modules/pre-commit/hook
: integer expression expected   .git/hooks/pre-commit: line 4: [: 127
: numeric argument required     .git/hooks/pre-commit: line 5: exit: 0

Hope we'll find a solution

from pre-commit.

codepunkt avatar codepunkt commented on June 29, 2024

Same here on Windows 10 in WSL Bash

from pre-commit.

hbowden avatar hbowden commented on June 29, 2024

Same on Windows 7

from pre-commit.

neverendingqs avatar neverendingqs commented on June 29, 2024

If you open up .git/hooks/pre-commit, you can see that the code is written in bash:

#!/bin/bash
./node_modules/pre-commit/hook
RESULT=$?
[ $RESULT -ne 0 ] && exit 1
exit 0

Interestingly enough, I get the same message in Cygwin, but I don't in Git bash's mingw64.

In any case, the problem is probably something something doesn't understand bash.

Cygwin:

$ uname -r
2.10.0(0.325/5/3)

$ git --version
git version 2.16.2

Git bash:

$ git --version
git version 2.5.0.windows.1

from pre-commit.

neverendingqs avatar neverendingqs commented on June 29, 2024

EDIT: this is a red herring. See next comment for details.

Update: looks like .git/hooks/pre-commit was not happy about the line ending. It had \r\n (Windows). Switching to \n got me further.

EDIT: looks like it purposely chooses Windows line ending (

pre-commit/install.js

Lines 104 to 108 in f25888f

var precommitContent = '#!/usr/bin/env bash' + os.EOL
+ hookRelativeUnixPath + os.EOL
+ 'RESULT=$?' + os.EOL
+ '[ $RESULT -ne 0 ] && exit 1' + os.EOL
+ 'exit 0' + os.EOL;
). Maybe it shouldn't(?).

I suspect the problems I am encountering are specific to Cygwin, so if you're not using Cygwin, give the above a shot.

from pre-commit.

rofrol avatar rofrol commented on June 29, 2024

In node_modules/pre-commit/index.js change line

this.json = require(path.join(this.root, 'package.json'));

to

this.json = require(path.join(this.root, 'package.json').replace(/\\([a-zA-Z])\\/, '$1:\\'));

This will change \c\Users\rofrol\project1\package.json to c:\Users\rofrol\project1\package.json.

from pre-commit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.