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

Error when settings diff.submodule to anything other than "short" #902

Closed
abrioy opened this issue Aug 6, 2020 · 2 comments · Fixed by #901
Closed

Error when settings diff.submodule to anything other than "short" #902

abrioy opened this issue Aug 6, 2020 · 2 comments · Fixed by #901

Comments

@abrioy
Copy link

abrioy commented Aug 6, 2020

Description

Hello,

I am unable to commit a change to my submodule if there is no other modifications to commit.
lint-staged doesn't work when the git configuration diff.submodule is set to anything other than "short".

It would be nice if the tool could force this setting to the only value it can handle when running git diff.

https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---submoduleltformatgt

Steps to reproduce

  • Have a repository with a submodule
  • Set git config diff.submodule diff
  • Create a new commit in the submodule
  • Do not change any other file in the main repository
  • Stage only the now modified submodule
  • Commit this change in the main repository
  • lint-staged will throw an error

Debug Logs

expand to view
$ git commit -m test
husky > pre-commit (node v10.20.1)
  lint-staged:bin Running `lint-staged@10.2.11` +0ms
  lint-staged:bin Options parsed from command-line: { allowEmpty: false,
  concurrent: true,
  configPath: undefined,
  debug: true,
  maxArgLength: 65536,
  stash: false,
  quiet: false,
  relative: false,
  shell: false,
  verbose: true } +2ms
  lint-staged Loading config using `cosmiconfig` +0ms
  lint-staged Successfully loaded config from `/PROJECT/.lintstagedrc`:
  lint-staged { 'src/app/SUBMODULE': './dev/validate-commons-branch.js',
  lint-staged   'src/assets/i18n/*.json': 'sort-json',
  lint-staged   '*.{ts,html,scss}': 'prettier --write' } +32ms
  lint-staged:cfg Validating config +0ms
Running lint-staged with the following config:
{
  'src/app/SUBMODULE': './dev/validate-commons-branch.js',
  'src/assets/i18n/*.json': 'sort-json',
  '*.{ts,html,scss}': 'prettier --write'
}
  lint-staged Unset GIT_LITERAL_PATHSPECS (was `undefined`) +1ms
  lint-staged:run Running all linter scripts +0ms
  lint-staged:resolveGitRepo Resolving git repo from `/PROJECT` +0ms
  lint-staged:resolveGitRepo Unset GIT_DIR (was `undefined`) +0ms
  lint-staged:resolveGitRepo Unset GIT_WORK_TREE (was `undefined`) +0ms
  lint-staged:git Running git command [ 'rev-parse', '--show-toplevel' ] +0ms
  lint-staged:resolveGitRepo Resolved git directory to be `/PROJECT` +10ms
  lint-staged:resolveGitRepo Resolved git config directory to be `/PROJECT/.git` +0ms
  lint-staged:git Running git command [ 'log', '-1' ] +10ms
⚠ Skipping backup because `--no-stash` was used.

  lint-staged:git Running git command [ 'diff', '--staged', '--diff-filter=ACMR', '--name-only', '-z' ] +7ms
  lint-staged:run Loaded list of staged files in git:
  lint-staged:run [ 'src/app/SUBMODULE' ] +24ms
  lint-staged:chunkFiles Resolved an argument string length of 52 characters from 1 files +0ms
  lint-staged:chunkFiles Creating 1 chunks for maxArgLength of 65536 +0ms
  lint-staged:gen-tasks Generating linter tasks +0ms
  lint-staged:gen-tasks Generated task: 
  lint-staged:gen-tasks { pattern: 'src/app/SUBMODULE',
  lint-staged:gen-tasks   commands: './dev/validate-commons-branch.js',
  lint-staged:gen-tasks   fileList: [ '/PROJECT/src/app/SUBMODULE' ] } +3ms
  lint-staged:gen-tasks Generated task: 
  lint-staged:gen-tasks { pattern: 'src/assets/i18n/*.json',
  lint-staged:gen-tasks   commands: 'sort-json',
  lint-staged:gen-tasks   fileList: [] } +1ms
  lint-staged:gen-tasks Generated task: 
  lint-staged:gen-tasks { pattern: '*.{ts,html,scss}',
  lint-staged:gen-tasks   commands: 'prettier --write',
  lint-staged:gen-tasks   fileList: [] } +1ms
  lint-staged:make-cmd-tasks Creating listr tasks for commands './dev/validate-commons-branch.js' +0ms
  lint-staged:task cmd: ./dev/validate-commons-branch.js +0ms
  lint-staged:task args: [] +0ms
  lint-staged:task execaOptions: { preferLocal: true, reject: false, shell: false } +0ms
  lint-staged:make-cmd-tasks Creating listr tasks for commands 'sort-json' +2ms
  lint-staged:task cmd: sort-json +1ms
  lint-staged:task args: [] +0ms
  lint-staged:task execaOptions: { preferLocal: true, reject: false, shell: false } +0ms
  lint-staged:make-cmd-tasks Creating listr tasks for commands 'prettier --write' +0ms
  lint-staged:task cmd: prettier +0ms
  lint-staged:task args: [ '--write' ] +0ms
  lint-staged:task execaOptions: { preferLocal: true, reject: false, shell: false } +0ms
  lint-staged:chunkFiles Resolved an argument string length of 52 characters from 1 files +7ms
  lint-staged:chunkFiles Creating 1 chunks for maxArgLength of 65536 +0ms
[STARTED] Preparing...
  lint-staged:git Backing up original state... +0ms
  lint-staged:git Getting partially staged files... +0ms
  lint-staged:git Running git command [ 'status', '-z' ] +18ms
  lint-staged:git Found partially staged files: [ 'src/app/SUBMODULE' ] +18ms
  lint-staged:git Running git command [ 'diff',
  '--binary',
  '--unified=0',
  '--no-color',
  '--no-ext-diff',
  '--src-prefix=a/',
  '--dst-prefix=b/',
  '--patch',
  '--output',
  '/PROJECT/.git/lint-staged_unstaged.patch',
  '--',
  'src/app/SUBMODULE' ] +18ms
[SUCCESS] Preparing...
[STARTED] Hiding unstaged changes to partially staged files...
  lint-staged:git Running git command [ 'checkout', '--force', '--', 'src/app/SUBMODULE' ] +17ms
[SUCCESS] Hiding unstaged changes to partially staged files...
[STARTED] Running tasks...
[STARTED] Running tasks for src/app/SUBMODULE
[STARTED] Running tasks for src/assets/i18n/*.json
[STARTED] Running tasks for *.{ts,html,scss}
[SKIPPED] No staged files match src/assets/i18n/*.json
[SKIPPED] No staged files match *.{ts,html,scss}
[STARTED] ./dev/validate-commons-branch.js
[SUCCESS] ./dev/validate-commons-branch.js
[SUCCESS] Running tasks for src/app/SUBMODULE
[SUCCESS] Running tasks...
[STARTED] Applying modifications...
  lint-staged:git Adding task modifications to index... +93ms
  lint-staged:git Running git command [ 'add',
  '--',
  '/PROJECT/src/app/SUBMODULE' ] +76ms
  lint-staged:git Done adding task modifications to index! +12ms
  lint-staged:git Running git command [ 'diff', '--name-only', '--cached' ] +12ms
[SUCCESS] Applying modifications...
[STARTED] Restoring unstaged changes to partially staged files...
  lint-staged:git Restoring unstaged changes... +7ms
  lint-staged:git Running git command [ 'apply',
  '-v',
  '--whitespace=nowarn',
  '--recount',
  '--unidiff-zero',
  '/PROJECT/.git/lint-staged_unstaged.patch' ] +7ms
  lint-staged:git Error while restoring changes: +5ms
  lint-staged:git Error: error: unrecognised input
  lint-staged:git     at execGit (/PROJECT/node_modules/lint-staged/lib/execGit.js:24:11)
  lint-staged:git     at process._tickCallback (internal/process/next_tick.js:68:7) +0ms
  lint-staged:git Retrying with 3-way merge +0ms
  lint-staged:git Running git command [ 'apply',
  '-v',
  '--whitespace=nowarn',
  '--recount',
  '--unidiff-zero',
  '--3way',
  '/PROJECT/.git/lint-staged_unstaged.patch' ] +5ms
  lint-staged:git Error while restoring unstaged changes using 3-way merge: +4ms
  lint-staged:git Error: error: unrecognised input
  lint-staged:git     at execGit (/PROJECT/node_modules/lint-staged/lib/execGit.js:24:11)
  lint-staged:git     at process._tickCallback (internal/process/next_tick.js:68:7) +0ms
[FAILED] Unstaged changes could not be restored due to a merge conflict!

  ✖ lint-staged failed due to a git error.

ℹ ./dev/validate-commons-branch.js:
> git rev-parse --abbrev-ref HEAD
husky > pre-commit hook failed (add --no-verify to bypass)
FAIL: 1

Environment

$ git --version    
git version 2.25.1
  • OS:
  • Node.js:
  • lint-staged:
@iiroj
Copy link
Member

iiroj commented Aug 10, 2020

Hello,

thanks for the issue. Can you try editing your local lint-staged to add the required option, to see if it helps?
As you can see here in lint-staged/lib/gitWorkflow.js, we already set some settings for diffing:

https://github.com/okonet/lint-staged/blob/86c9ed2bde1245a702635b42a57b92b809340b0e/lib/gitWorkflow.js#L48-L56

If you add --submodule=short to that list, does it start working as expectedly?

@abrioy
Copy link
Author

abrioy commented Aug 31, 2020

It works wonderfully now. Thank you for the fix.

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

Successfully merging a pull request may close this issue.

2 participants