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

Running Lint-staged from within a sub directory #65

Merged
merged 4 commits into from Oct 7, 2016
Merged

Running Lint-staged from within a sub directory #65

merged 4 commits into from Oct 7, 2016

Conversation

TheWolfNL
Copy link
Contributor

@TheWolfNL TheWolfNL commented Oct 7, 2016

I've added the possibility to set the git-root which if set will be used to resolve the filepaths accordingly

this should fix: #41

… properly when the working directory is a subdirectory of the git root
Tweak readme a bit
Move some information
Copy link
Collaborator

@okonet okonet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! I'll need to add tests for this part as well ASAP though.

// If current working directory is not the git root -> resolve file paths accordingly
if (sgf.cwd !== process.cwd()) {
var relpath = path.relative(process.cwd(), sgf.cwd) + '/'
for (var i in fileList) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work on Windows I guess. Let's remove / and just use path.resolve that accepts Array<string>.

if (sgf.cwd !== process.cwd()) {
var relpath = path.relative(process.cwd(), sgf.cwd) + '/'
for (var i in fileList) {
fileList[i] = path.resolve(relpath + fileList[i])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this should become

path.resolve(relpath, fileList[i])

@okonet
Copy link
Collaborator

okonet commented Oct 7, 2016

Awesome! Thank you! I'll ask @ai to test with his setup.

@okonet okonet merged commit 364b3da into lint-staged:master Oct 7, 2016
@ai
Copy link
Contributor

ai commented Oct 7, 2016

Wow! Great work. I will try it in Wednesday (moving to next city :( )

@ai
Copy link
Contributor

ai commented Oct 12, 2016

It doesn’t work :(. I tested lint-staged from master:

➤ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    modified:   blocks/intro-notices/intro-notices.js

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   package.json


➤ git commit -m 'Test'

> amplifr@ precommit /home/ai/Dev/amplifr/front
> lint-staged

Error: fatal: Not a git repository: '.git'

    at ChildProcess.<anonymous> (/home/ai/Dev/amplifr/front/node_modules/staged-git-files/index.js:85:19)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:877:16)
    at Socket.<anonymous> (internal/child_process.js:334:11)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at Pipe._handle.close [as _onclose] (net.js:493:12)
/home/ai/Dev/amplifr/front/node_modules/lint-staged/src/index.js:27
    const filePaths = results.map(file => file.filename)
                             ^

TypeError: Cannot read property 'map' of undefined
    at /home/ai/Dev/amplifr/front/node_modules/lint-staged/src/index.js:27:30
    at /home/ai/Dev/amplifr/front/node_modules/staged-git-files/index.js:13:13
    at /home/ai/Dev/amplifr/front/node_modules/staged-git-files/index.js:38:13
    at ChildProcess.<anonymous> (/home/ai/Dev/amplifr/front/node_modules/staged-git-files/index.js:88:9)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:877:16)
    at Socket.<anonymous> (internal/child_process.js:334:11)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)

@ai
Copy link
Contributor

ai commented Oct 12, 2016

Ouh, I forgot about "git-root": "../", :) Everything works right now. Waiting for release!

@okonet
Copy link
Collaborator

okonet commented Oct 13, 2016

I've renamed the option to gitDir for consistency with git and coding standard.

@okonet
Copy link
Collaborator

okonet commented Oct 13, 2016

Released as 3.1.0: https://github.com/okonet/lint-staged/releases/tag/3.1.0

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

Successfully merging this pull request may close these issues.

Work in subdirectory
3 participants