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

Script error on Git Bash (Windows) #68

Closed
ybiquitous opened this issue Feb 19, 2016 · 13 comments · Fixed by #72
Closed

Script error on Git Bash (Windows) #68

ybiquitous opened this issue Feb 19, 2016 · 13 comments · Fixed by #72

Comments

@ybiquitous
Copy link
Collaborator

I encountered the following script error on Git Bash (Windows 7).

Environment:

  • Windows 7 Professional SP1 64bit
  • Git for Windows 2.7.1
  • pre-git 3.3.0
  • Node.js 4.3.0
  • npm 3.7.2

Reproduction:
Open Git Bash and run the following commands on terminal.

mkdir foo
cd foo
npm init -y
git init
echo 'node_modules' >> .gitignore
echo 'npm-debug.log' >> .gitignore
npm install --save-dev pre-git
git add .
npm run commit

alert

package.json.txt

npm-debug.log.txt

@ybiquitous
Copy link
Collaborator Author

Perhaps I think this error relates to #63.

@bahmutov
Copy link
Owner

Probably it is more related to #33

@bahmutov
Copy link
Owner

bahmutov commented Mar 6, 2016

tried on Windows v3.4.1, seems to work, reopen if not fixed

@ybiquitous
Copy link
Collaborator Author

@bahmutov
When I tried pre-git@3.4.1, Windows JScript error did not occur.
But a following error occured on npm run commit.

C:\Users\koba\git\foo\node_modules\.bin\pre-commit:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
          ^^^^^^^

SyntaxError: missing ) after argument list
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:134:18)
    at node.js:962:3

This is the installed node_modules/.bin/pre-commit:

#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")

case `uname` in
    *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac

if [ -x "$basedir/node" ]; then
  "$basedir/node"  "$basedir/../pre-git/bin/pre-commit.js" "$@"
  ret=$?
else 
  node  "$basedir/../pre-git/bin/pre-commit.js" "$@"
  ret=$?
fi
exit $ret

This is the installed .git/hooks/pre-commit:

#!/bin/sh

/usr/bin/env node --harmony ./node_modules/.bin/pre-commit "$@"

@ybiquitous
Copy link
Collaborator Author

@bahmutov

tried on Windows v3.4.1, seems to work, reopen if not fixed

Sorry, I have no right to reopen this issue.

@bahmutov bahmutov reopened this Mar 7, 2016
@bahmutov
Copy link
Owner

bahmutov commented Mar 7, 2016

Ok, I have reopened the issue @ybiquitous but the solution on Windows is up to you (pull requests are very welcome) - basically I don't have an access to Windows machine for development, and no use for supporting Windows, but if you can do this, it would be great and helpful to many people I think

@ybiquitous
Copy link
Collaborator Author

I will try it. It may take a little time...

@ybiquitous
Copy link
Collaborator Author

First, I tried modifying bin/pre-commit.js as follows:

- #!/usr/bin/env node
+ #!/usr/bin/env node --harmorny

This worked on Windows, but not on Linux.

If using env in shebang, to pass cli options such as --harmony would not work. Reason:

So I wrote wrapper shell script such as bin/pre-commit for bin/pre-commit.js.
This wrapper script worked well on both Windows and Linux.

Please give me a review.

bahmutov added a commit that referenced this issue Mar 14, 2016
fix(bin): added --harmony option wrapper scripts(cross-platform), fixes #68
@bahmutov bahmutov reopened this Mar 14, 2016
@bahmutov
Copy link
Owner

Had a problem running on Mac OSX

installed
/private/tmp/test-pre-git
└── pre-git@3.5.2 

tried to commit a file

$ g done "git"
readlink: illegal option -- e
usage: readlink [-n] [file ...]
module.js:340
    throw err;
    ^

Error: Cannot find module '/private/tmp/test-pre-git/.js'

@bahmutov
Copy link
Owner

Hi,
I was thinking maybe you could just fork it and publish under your own name on NPM, like pre-git-win? I will add a banner directing Windows users to your repo, this might be simpler than trying to fix every env.

@ybiquitous
Copy link
Collaborator Author

@bahmutov
Copy link
Owner

Sure, try it

Sent from my iPhone

On Mar 15, 2016, at 00:04, ybiquitous notifications@github.com wrote:

Umm...

Can we borrow code snippets (alternative readlink -e) in following web sites?

https://www.google.com/search?q=cross+platform+readlink
http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac
https://gist.github.com/nicerobot/2691519
https://github.com/olov/node-harmony-wrapper

You are receiving this because you modified the open/close state.
Reply to this email directly or view it on GitHub:
#68 (comment)

@ybiquitous
Copy link
Collaborator Author

Thanks, I will try it.

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

Successfully merging a pull request may close this issue.

2 participants