GithubHelp home page GithubHelp logo

Comments (12)

bagley2014 avatar bagley2014 commented on June 1, 2024

I just verified I've got no issue using lint-staged on the repo when connected to nas-server via ssh.

from lint-staged.

iiroj avatar iiroj commented on June 1, 2024

Hey,

so the expected path is M:\Misc\temp repro\.git but lint-staged finds M:\nas-server\nas\Misc\temp repro\.git?

If you don't mind adding some console.log or similar debugging for yourself, I believe the error happens somewhere around here:

/**
* Resolve path to the .git directory, with special handling for
* submodules and worktrees
*/
const resolveGitConfigDir = async (gitDir) => {
// Get the real path in case it's a symlink
const defaultDir = normalizePath(await fs.realpath(path.join(gitDir, '.git')))
const stats = await fs.lstat(defaultDir)
// If .git is a directory, use it
if (stats.isDirectory()) return defaultDir
// Otherwise .git is a file containing path to real location
const file = (await readFile(defaultDir)).toString()
return path.resolve(gitDir, file.replace(/^gitdir: /, '')).trim()
}

Maybe it's line 24 where it essentially resolves the config path from "git dir"; could it be a relative path and gets messed up?

return path.resolve(gitDir, file.replace(/^gitdir: /, '')).trim()

from lint-staged.

bagley2014 avatar bagley2014 commented on June 1, 2024

Thanks for pointing me to the relevant function. I went ahead and added some logging to try to see what was happening.

new logs
M:\Misc\temp repro>npx lint-staged -d true 
  lint-staged:bin Running `[email protected]` on Node.js v18.16.0 (win32) +0ms
  lint-staged:bin Options parsed from command-line: {
  allowEmpty: false,
  concurrent: true,
  configPath: undefined,
  cwd: undefined,
  debug: true,
  diff: undefined,
  diffFilter: undefined,
  maxArgLength: undefined,
  quiet: false,
  relative: false,
  shell: false,
  stash: true,
  verbose: false
} +1ms
  lint-staged:validateOptions Validating options... +0ms
  lint-staged:validateOptions Validated options! +0ms
  lint-staged Unset GIT_LITERAL_PATHSPECS (was `undefined`) +0ms
  lint-staged:runAll Running all linter scripts... +0ms
  lint-staged:runAll Using working directory `M:\Misc\temp repro` +0ms
  lint-staged:resolveGitRepo Resolving git repo from `M:\Misc\temp repro` +0ms
  lint-staged:resolveGitRepo Unset GIT_DIR (was `undefined`) +0ms
  lint-staged:resolveGitRepo Unset GIT_WORK_TREE (was `undefined`) +1ms
  lint-staged:execGit Running git command [ 'rev-parse', '--show-prefix' ] +0ms
  lint-staged:resolveGitRepo resolveGitConfigDir | gitDir: `M:/Misc/temp repro` +134ms
  lint-staged:resolveGitRepo resolveGitConfigDir | defaultDir: `/nas-server/nas/Misc/temp repro/.git` +2ms
  lint-staged:resolveGitRepo Failed to resolve git repo with error: [Error: ENOENT: no such file or directory, lstat 'M:\nas-server\nas\Misc\temp repro\.git'] {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'lstat',
  path: 'M:\\nas-server\\nas\\Misc\\temp repro\\.git'
} +2ms
✖ Current directory is not a git directory!

It looks like the exception is thrown by the lstat call on line 19. The path being passed in is /nas-server/nas/Misc/temp repro/.git which seems to be interpreted by lstat as a path on the M drive.

After messing around in the node repl, I learned that fs.realpath takes the path I'd expect to see (M:\Misc\temp repro\.git) and transforms it into another path that works: \\nas-server\nas\Misc\temp repro\.git

Then normalizePath takes that path and transforms it to /nas-server/nas/Misc/temp repro/.git which doesn't work. I confirmed that removing the normalizePath call on line 18 prevents the crash I was experiencing. However, the result of resolveGitConfigDir is still being passed through normalizePath and resolving to something that doesn't work so it crashes later on.

from lint-staged.

iiroj avatar iiroj commented on June 1, 2024

Hey, the normalizePath is implemented in this repo along with an unit test file that seemingly already handles this (test/unit/normalizePath.spec.js). Maybe there's some bug in the implementation or its usage.

Would M:/nas-server/nas/Misc/temp repro/.git be a working path?

['C:\\user\\docs\\Letter.txt', 'C:/user/docs/Letter.txt'],

from lint-staged.

bagley2014 avatar bagley2014 commented on June 1, 2024

Would M:/nas-server/nas/Misc/temp repro/.git be a working path?

That's the path that doesn't work since there's no nas-server folder on M:. The correct path is M:/Misc/temp repro/.git (but \\nas-server\nas\Misc\temp repro\.git is the equivalent UNC path).

It doesn't seem like the tests are setup to handle a "standard" UNC path. Perhaps one with the \\?\ or \\.\ syntax (although I just learned those exist) is tested fine, but the relevant test for the path I get from fs.realpath would have to look something like ['\\\\Server01\\user\\docs\\Letter.txt', '//Server01/user/docs/Letter.txt'].

from lint-staged.

iiroj avatar iiroj commented on June 1, 2024

Just to be sure, what is the literal content of the .git file in the repo? I assume it's roughly:

gitdir: M:/Misc/temp repro/.git

from lint-staged.

bagley2014 avatar bagley2014 commented on June 1, 2024

The root of the repo is M:/Misc/temp repro and M:/Misc/temp repro/.git is not a file, it's a folder. Are you asking about a file in that folder?

from lint-staged.

iiroj avatar iiroj commented on June 1, 2024

Hmm, maybe I was misunderstanding this issue. I assume your git repo directory was a symlink and that's where the path was going wrong. Since that's not the case, can you clarify how the nas-server relates to the git repo?

Do you mean \\nas-server\nas\Misc\temp repro\ is a path in the Nas server, that you have remapped as a drive letter mount to M:/Misc/temp repro? Sorry, not that familiar with Windows.

from lint-staged.

iiroj avatar iiroj commented on June 1, 2024

We can try to make the realPath call conditional based on stats.isSymbolicLink(); maybe that will help.

from lint-staged.

iiroj avatar iiroj commented on June 1, 2024

I have no idea if the linked PR actually does anything, can you try it out? Based on what you said:

After messing around in the node repl, I learned that fs.realpath takes the path I'd expect to see (M:\Misc\temp repro.git) and transforms it into another path that works: \nas-server\nas\Misc\temp repro.git

I hope this means the git dir will be resolved to M:\Misc\temp repro\.git and then normalized as M:/Misc/temp repro/.git, which hopefully works.

from lint-staged.

bagley2014 avatar bagley2014 commented on June 1, 2024

Yeah, no symlinks involved.

nas-server is another machine on my local network and \nas\Misc\temp repro is a directory on that machine. I mapped \\nas-server\nas to M: on the machine I'm developing on, so M:/Misc/temp repro is equivalent to \\nas-server\nas\Misc\temp repro.

I tried the change in that PR and it worked! The directory resolves as expected and the staged file gets linted as expected. Thanks for all the help!

from lint-staged.

iiroj avatar iiroj commented on June 1, 2024

Thanks for debugging, I'll put it into the next release.

from lint-staged.

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.