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

lint-staged is unable to operate if committing a git submodule #1348

Open
trusktr opened this issue Oct 31, 2023 · 3 comments
Open

lint-staged is unable to operate if committing a git submodule #1348

trusktr opened this issue Oct 31, 2023 · 3 comments

Comments

@trusktr
Copy link

trusktr commented Oct 31, 2023

Description

Steps to reproduce

I have this state, where both packages/cli and apps/docs are git submodules:

❯ git status                                                                                                                                                                    ✹ ✚
On branch develop
Your branch is up to date with 'origin/develop'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   packages/cli

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
  (commit or discard the untracked or modified content in submodules)
        modified:   apps/docs (modified content)

Then when I run npm lint-staged, it fails on the stash step. See log below:

Debug Logs

expand to view
❯ npx lint-staged --debug                                                                                                                                                       ✹ ✚
  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
} +0ms
  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 `/Users/trusktr/src/lume+lume+develop` +0ms
  lint-staged:resolveGitRepo Resolving git repo from `/Users/trusktr/src/lume+lume+develop` +0ms
  lint-staged:resolveGitRepo Unset GIT_DIR (was `undefined`) +0ms
  lint-staged:resolveGitRepo Unset GIT_WORK_TREE (was `undefined`) +0ms
  lint-staged:execGit Running git command [ 'rev-parse', '--show-prefix' ] +0ms
  lint-staged:resolveGitRepo Resolved git directory to be `/Users/trusktr/src/lume+lume+develop` +33ms
  lint-staged:resolveGitRepo Resolved git config directory to be `/Users/trusktr/src/lume+lume+develop/.git` +0ms
  lint-staged:execGit Running git command [ 'log', '-1' ] +33ms
  lint-staged:execGit Running git command [ 'diff', '--name-only', '-z', '--diff-filter=ACMR', '--staged' ] +29ms
  lint-staged:runAll Loaded list of staged files in git:
  lint-staged:runAll [ '/Users/trusktr/src/lume+lume+develop/packages/cli' ] +89ms
  lint-staged:searchConfigs Searching for configuration files... +0ms
  lint-staged:execGit Running git command [ 'ls-files', '-z', '--full-name' ] +28ms
  lint-staged:execGit Running git command [ 'ls-files', '-z', '--full-name', '--others', '--exclude-standard' ] +30ms
  lint-staged:searchConfigs Found possible config files: [
  '/Users/trusktr/src/lume+lume+develop/examples/react-typescript/package.json',
  '/Users/trusktr/src/lume+lume+develop/examples/react/package.json',
  '/Users/trusktr/src/lume+lume+develop/.lintstagedrc.js',
  '/Users/trusktr/src/lume+lume+develop/package.json'
] +57ms
  lint-staged:loadConfig Loading configuration from `/Users/trusktr/src/lume+lume+develop/examples/react-typescript/package.json`... +0ms
  lint-staged:loadConfig Loading configuration from `/Users/trusktr/src/lume+lume+develop/examples/react/package.json`... +0ms
  lint-staged:loadConfig Loading configuration from `/Users/trusktr/src/lume+lume+develop/.lintstagedrc.js`... +1ms
  lint-staged:loadConfig Loading configuration from `/Users/trusktr/src/lume+lume+develop/package.json`... +0ms
  lint-staged:loadConfig Successfully loaded config from `/Users/trusktr/src/lume+lume+develop/package.json`:
  lint-staged:loadConfig null +0ms
  lint-staged:loadConfig Successfully loaded config from `/Users/trusktr/src/lume+lume+develop/examples/react-typescript/package.json`:
  lint-staged:loadConfig null +0ms
  lint-staged:loadConfig Successfully loaded config from `/Users/trusktr/src/lume+lume+develop/examples/react/package.json`:
  lint-staged:loadConfig null +0ms
  lint-staged:loadConfig Successfully loaded config from `/Users/trusktr/src/lume+lume+develop/.lintstagedrc.js`:
  lint-staged:loadConfig {
  lint-staged:loadConfig   './src/**/*': [Function: ./src/**/*],
  lint-staged:loadConfig   './packages/**/*': [Function: ./packages/**/*]
  lint-staged:loadConfig } +1ms
  lint-staged:validateConfig Validating config from `/Users/trusktr/src/lume+lume+develop/.lintstagedrc.js`... +0ms
  lint-staged:validateConfig Validated config from `/Users/trusktr/src/lume+lume+develop/.lintstagedrc.js`: +0ms
  lint-staged:validateConfig {
  lint-staged:validateConfig   './src/**/*': [Function: ./src/**/*],
  lint-staged:validateConfig   './packages/**/*': [Function: ./packages/**/*]
  lint-staged:validateConfig } +0ms
  lint-staged:searchConfigs Found 1 config files +2ms
  lint-staged:groupFilesByConfig Grouping 1 files by 1 configurations +0ms
  lint-staged:chunkFiles Resolved an argument string length of 49 characters from 1 files +0ms
  lint-staged:chunkFiles Creating 1 chunks for maxArgLength of 131072 +0ms
  lint-staged:generateTasks Generating linter tasks +0ms
  lint-staged:generateTasks Generated task: 
  lint-staged:generateTasks {
  lint-staged:generateTasks   pattern: './src/**/*',
  lint-staged:generateTasks   commands: [Function: ./src/**/*],
  lint-staged:generateTasks   fileList: []
  lint-staged:generateTasks } +1ms
  lint-staged:generateTasks Generated task: 
  lint-staged:generateTasks {
  lint-staged:generateTasks   pattern: './packages/**/*',
  lint-staged:generateTasks   commands: [Function: ./packages/**/*],
  lint-staged:generateTasks   fileList: [ '/Users/trusktr/src/lume+lume+develop/packages/cli' ]
  lint-staged:generateTasks } +0ms
  lint-staged:makeCmdTasks Creating listr tasks for commands [Function: ./src/**/*] +0ms
  lint-staged:makeCmdTasks Creating listr tasks for commands [Function: ./packages/**/*] +0ms
  lint-staged:resolveTaskFn cmd: npm +0ms
  lint-staged:resolveTaskFn args: [ 'run', 'build' ] +0ms
  lint-staged:resolveTaskFn execaOptions: {
  cwd: '/Users/trusktr/src/lume+lume+develop',
  preferLocal: true,
  reject: false,
  shell: false
} +0ms
  lint-staged:resolveTaskFn cmd: git +0ms
  lint-staged:resolveTaskFn args: [ 'add', 'dist' ] +0ms
  lint-staged:resolveTaskFn execaOptions: {
  cwd: '/Users/trusktr/src/lume+lume+develop',
  preferLocal: true,
  reject: false,
  shell: false
} +0ms
  lint-staged:resolveTaskFn cmd: npm +0ms
  lint-staged:resolveTaskFn args: [ 'run', 'build' ] +0ms
  lint-staged:resolveTaskFn execaOptions: {
  cwd: '/Users/trusktr/src/lume+lume+develop',
  preferLocal: true,
  reject: false,
  shell: false
} +0ms
  lint-staged:resolveTaskFn cmd: git +0ms
  lint-staged:resolveTaskFn args: [ 'add', 'dist' ] +0ms
  lint-staged:resolveTaskFn execaOptions: {
  cwd: '/Users/trusktr/src/lume+lume+develop',
  preferLocal: true,
  reject: false,
  shell: false
} +0ms
  lint-staged:chunkFiles Resolved an argument string length of 49 characters from 1 files +2ms
  lint-staged:chunkFiles Creating 1 chunks for maxArgLength of 131072 +0ms
[STARTED] Preparing lint-staged...
  lint-staged:GitWorkflow Backing up original state... +0ms
  lint-staged:GitWorkflow Getting partially staged files... +0ms
  lint-staged:execGit Running git command [ 'status', '-z' ] +34ms
  lint-staged:GitWorkflow Found partially staged files: [] +178ms
  lint-staged:GitWorkflow Backing up merge state... +0ms
  lint-staged:file Reading file `/Users/trusktr/src/lume+lume+develop/.git/MERGE_HEAD` +0ms
  lint-staged:file Reading file `/Users/trusktr/src/lume+lume+develop/.git/MERGE_MODE` +0ms
  lint-staged:file Reading file `/Users/trusktr/src/lume+lume+develop/.git/MERGE_MSG` +0ms
  lint-staged:file File `/Users/trusktr/src/lume+lume+develop/.git/MERGE_HEAD` doesn't exist, ignoring... +0ms
  lint-staged:file File `/Users/trusktr/src/lume+lume+develop/.git/MERGE_MODE` doesn't exist, ignoring... +0ms
  lint-staged:file File `/Users/trusktr/src/lume+lume+develop/.git/MERGE_MSG` doesn't exist, ignoring... +0ms
  lint-staged:GitWorkflow Done backing up merge state! +0ms
  lint-staged:GitWorkflow Getting deleted files... +1ms
  lint-staged:execGit Running git command [ 'ls-files', '--deleted' ] +179ms
  lint-staged:GitWorkflow Found deleted files: [] +37ms
  lint-staged:execGit Running git command [ 'stash', 'create' ] +37ms
  lint-staged:execGit Running git command [
  'stash',
  'store',
  '--quiet',
  '--message',
  'lint-staged automatic backup',
  ''
] +54ms
[STARTED] Running tasks for staged files...
[SKIPPED] Running tasks for staged files...
[STARTED] Applying modifications from tasks...

[SKIPPED]   ✖ lint-staged failed due to a git error.
[STARTED] Cleaning up temporary files...

[SKIPPED]   ✖ lint-staged failed due to a git error.

  ✖ lint-staged failed due to a git error.
  Any lost modifications can be restored from a git stash:

    > git stash list
    stash@{0}: automatic lint-staged backup
    > git stash apply --index stash@{0}

In particular, notice this:

  lint-staged:execGit Running git command [
  'stash',
  'store',
  '--quiet',
  '--message',
  'lint-staged automatic backup',
  '' <--------------------------------- RIGHT HERE, something is missing
] +54ms

Basically this is a commit attempt with no changes in the repo, only an update of a git submodule commit.

Environment

  • OS: macOS
  • Node.js: 20
  • lint-staged: 14.0.1
@trusktr
Copy link
Author

trusktr commented Oct 31, 2023

Possibly related due to possible incorrect stash handling with presence of git submodules:

@trusktr
Copy link
Author

trusktr commented Oct 31, 2023

@iiroj
Copy link
Member

iiroj commented Nov 1, 2023

Sorry, did you open multiple issues about submodules and also linekd to an earlier issue which seems to be related? It would be easier to track if there was only a sigle issue.

There is this submodule test, how does your usage differ from it? https://github.com/lint-staged/lint-staged/blob/master/test/integration/git-submodules.test.js

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

No branches or pull requests

2 participants