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

How to restore stash files into workspace when lint-staged error #1366

Open
quxiaodong opened this issue Dec 1, 2023 · 2 comments
Open

How to restore stash files into workspace when lint-staged error #1366

quxiaodong opened this issue Dec 1, 2023 · 2 comments

Comments

@quxiaodong
Copy link

I use git add ., and then git commit -m "test", it start to run the task as below

✔ Preparing lint-staged...
⚠ Running tasks for staged files...
  ❯ package.json — 8 files
    ❯ ./src/**/* — 1 file
      ✖ eslint --fix [FAILED]
      ◼ prettier --write
↓ Skipped because of errors from tasks.
✔ Reverting to original state because of errors...
✔ Cleaning up temporary files...

but the files still stay on stash area , I want to move the files into workspace automaticlly

nodejs: 20.9.0
npm: 10.1.0
macos: 14.1.1 (23B81)
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx lint-staged
{
   "lint-staged": {
    "./src/**/*": [
      "eslint --fix",
      "prettier --write"
    ]
  },
  "devDependencies": {
    "@commitlint/cli": "^18.4.3",
    "@commitlint/config-conventional": "^18.4.3",
    "@typescript-eslint/eslint-plugin": "^6.13.1",
    "@typescript-eslint/parser": "^6.13.1",
    "@vitejs/plugin-vue": "^4.5.0",
    "eslint": "^8.54.0",
    "eslint-config-prettier": "^9.0.0",
    "eslint-plugin-prettier": "^5.0.1",
    "husky": "^8.0.3",
    "lint-staged": "^15.1.0",
    "prettier": "^3.1.0",
    "typescript": "^5.2.2",
    "vite": "^5.0.0",
    "vue-tsc": "^1.8.22"
  }
}
@iiroj
Copy link
Member

iiroj commented Dec 1, 2023

Hello,

this should already be the behavior. Basically, the end result for staged files should be the same as before running lint-staged. This line in the output indicates that reverting by restoring the stash was successful:

✔ Reverting to original state because of errors...

Can you post some more logs by adding the --debug flag into your git hook for lint-staged, so it becomes:

npx lint-staged --debug

@quxiaodong
Copy link
Author

Hello,

this should already be the behavior. Basically, the end result for staged files should be the same as before running lint-staged. This line in the output indicates that reverting by restoring the stash was successful:

✔ Reverting to original state because of errors...

Can you post some more logs by adding the --debug flag into your git hook for lint-staged, so it becomes:

npx lint-staged --debug

Hello:

if I use npx lint-staged before git add ., it shows the erors that No staged files found.,

quxiaodong@quxiaodongdeMacBook-Pro scenic-map-old % git add .
quxiaodong@quxiaodongdeMacBook-Pro scenic-map-old % git commit -m "test"
  lint-staged:bin Running `lint-staged@15.1.0` on Node.js v20.9.0 (darwin) +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
} +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/quxiaodong/Documents/online-offline/scenic-map-old` +0ms
  lint-staged:resolveGitRepo Resolving git repo from `/Users/quxiaodong/Documents/online-offline/scenic-map-old` +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/quxiaodong/Documents/online-offline/scenic-map-old` +7ms
  lint-staged:resolveGitRepo Resolved git config directory to be `/Users/quxiaodong/Documents/online-offline/scenic-map-old/.git` +0ms
  lint-staged:execGit Running git command [ 'log', '-1' ] +6ms
  lint-staged:execGit Running git command [ 'diff', '--name-only', '-z', '--diff-filter=ACMR', '--staged' ] +5ms
  lint-staged:runAll Loaded list of staged files in git:
  lint-staged:runAll [
  lint-staged:runAll   '/Users/quxiaodong/Documents/online-offline/scenic-map-old/.eslintrc.json',
  lint-staged:runAll   '/Users/quxiaodong/Documents/online-offline/scenic-map-old/.husky/pre-commit',
  lint-staged:runAll   '/Users/quxiaodong/Documents/online-offline/scenic-map-old/src/main.ts'
  lint-staged:runAll ] +17ms
  lint-staged:searchConfigs Searching for configuration files... +0ms
  lint-staged:execGit Running git command [ 'ls-files', '-z', '--full-name' ] +5ms
  lint-staged:execGit Running git command [ 'ls-files', '-z', '--full-name', '--others', '--exclude-standard' ] +1ms
  lint-staged:searchConfigs Found possible config files: [
  '/Users/quxiaodong/Documents/online-offline/scenic-map-old/package.json'
] +5ms
  lint-staged:loadConfig Loading configuration from `/Users/quxiaodong/Documents/online-offline/scenic-map-old/package.json`... +0ms
  lint-staged:loadConfig Successfully loaded config from `/Users/quxiaodong/Documents/online-offline/scenic-map-old/package.json`:
  lint-staged:loadConfig {
  lint-staged:loadConfig   'src/**/*.{vue,js,ts,jsx,tsx}': [ 'eslint --fix', 'prettier --write' ]
  lint-staged:loadConfig } +1ms
  lint-staged:validateConfig Validating config from `/Users/quxiaodong/Documents/online-offline/scenic-map-old/package.json`... +0ms
  lint-staged:validateConfig Validated config from `/Users/quxiaodong/Documents/online-offline/scenic-map-old/package.json`: +0ms
  lint-staged:validateConfig {
  lint-staged:validateConfig   'src/**/*.{vue,js,ts,jsx,tsx}': [
  lint-staged:validateConfig     'eslint --fix',
  lint-staged:validateConfig     'prettier --write'
  lint-staged:validateConfig   ]
  lint-staged:validateConfig } +0ms
  lint-staged:searchConfigs Found 1 config files +1ms
  lint-staged:groupFilesByConfig Grouping 3 files by 1 configurations +0ms
  lint-staged:chunkFiles Resolved an argument string length of 218 characters from 3 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/**/*.{vue,js,ts,jsx,tsx}',
  lint-staged:generateTasks   commands: [ 'eslint --fix', 'prettier --write' ],
  lint-staged:generateTasks   fileList: [
  lint-staged:generateTasks     '/Users/quxiaodong/Documents/online-offline/scenic-map-old/src/main.ts'
  lint-staged:generateTasks   ]
  lint-staged:generateTasks } +1ms
  lint-staged:makeCmdTasks Creating listr tasks for commands [ 'eslint --fix', 'prettier --write' ] +0ms
  lint-staged:resolveTaskFn cmd: eslint +0ms
  lint-staged:resolveTaskFn args: [ '--fix' ] +0ms
  lint-staged:resolveTaskFn execaOptions: {
  cwd: '/Users/quxiaodong/Documents/online-offline/scenic-map-old',
  preferLocal: true,
  reject: false,
  shell: false
} +0ms
  lint-staged:resolveTaskFn cmd: prettier +0ms
  lint-staged:resolveTaskFn args: [ '--write' ] +0ms
  lint-staged:resolveTaskFn execaOptions: {
  cwd: '/Users/quxiaodong/Documents/online-offline/scenic-map-old',
  preferLocal: true,
  reject: false,
  shell: false
} +0ms
  lint-staged:chunkFiles Resolved an argument string length of 69 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' ] +9ms
  lint-staged:GitWorkflow Found partially staged files: [] +6ms
  lint-staged:GitWorkflow Backing up merge state... +0ms
  lint-staged:file Reading file `/Users/quxiaodong/Documents/online-offline/scenic-map-old/.git/MERGE_HEAD` +0ms
  lint-staged:file Reading file `/Users/quxiaodong/Documents/online-offline/scenic-map-old/.git/MERGE_MODE` +0ms
  lint-staged:file Reading file `/Users/quxiaodong/Documents/online-offline/scenic-map-old/.git/MERGE_MSG` +0ms
  lint-staged:file File `/Users/quxiaodong/Documents/online-offline/scenic-map-old/.git/MERGE_HEAD` doesn't exist, ignoring... +0ms
  lint-staged:file File `/Users/quxiaodong/Documents/online-offline/scenic-map-old/.git/MERGE_MODE` doesn't exist, ignoring... +0ms
  lint-staged:file File `/Users/quxiaodong/Documents/online-offline/scenic-map-old/.git/MERGE_MSG` doesn't exist, ignoring... +0ms
  lint-staged:GitWorkflow Done backing up merge state! +1ms
  lint-staged:GitWorkflow Getting deleted files... +0ms
  lint-staged:execGit Running git command [ 'ls-files', '--deleted' ] +7ms
  lint-staged:GitWorkflow Found deleted files: [] +4ms
  lint-staged:execGit Running git command [ 'stash', 'create' ] +4ms
  lint-staged:execGit Running git command [
  'stash',
  'store',
  '--quiet',
  '--message',
  'lint-staged automatic backup',
  '4535f338f521d45e0dd9e5daf50501f0242a5fcc'
] +12ms
  lint-staged:GitWorkflow Done backing up original state! +18ms
[COMPLETED] Preparing lint-staged...
[STARTED] Running tasks for staged files...
[STARTED] package.json — 3 files
[STARTED] src/**/*.{vue,js,ts,jsx,tsx} — 1 file
[STARTED] eslint --fix
[FAILED] eslint --fix [FAILED]
[FAILED] eslint --fix [FAILED]
[COMPLETED] Running tasks for staged files...
[STARTED] Applying modifications from tasks...
[SKIPPED] Skipped because of errors from tasks.
[STARTED] Reverting to original state because of errors...
  lint-staged:GitWorkflow Restoring original state... +623ms
  lint-staged:execGit Running git command [ 'reset', '--hard', 'HEAD' ] +629ms
  lint-staged:execGit Running git command [ 'stash', 'list' ] +8ms
  lint-staged:execGit Running git command [ 'stash', 'apply', '--quiet', '--index', '0' ] +8ms
  lint-staged:GitWorkflow Restoring merge state... +46ms
  lint-staged:GitWorkflow Done restoring merge state! +0ms
  lint-staged:file Removing file `/Users/quxiaodong/Documents/online-offline/scenic-map-old/.git/lint-staged_unstaged.patch` +691ms
  lint-staged:file File `/Users/quxiaodong/Documents/online-offline/scenic-map-old/.git/lint-staged_unstaged.patch` doesn't exist, ignoring... +0ms
  lint-staged:GitWorkflow Done restoring original state! +0ms
[COMPLETED] Reverting to original state because of errors...
[STARTED] Cleaning up temporary files...
  lint-staged:GitWorkflow Dropping backup stash... +1ms
  lint-staged:execGit Running git command [ 'stash', 'list' ] +31ms
  lint-staged:execGit Running git command [ 'stash', 'drop', '--quiet', '0' ] +8ms
  lint-staged:GitWorkflow Done dropping backup stash! +13ms
[COMPLETED] Cleaning up temporary files...

✖ eslint --fix:

/Users/quxiaodong/Documents/online-offline/scenic-map-old/src/main.ts
  6:5  error  'a' is defined but never used  @typescript-eslint/no-unused-vars

✖ 1 problem (1 error, 0 warnings)

husky - pre-commit hook exited with code 1 (error)

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