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

MERGE_HEAD is lost when repository is using submodules feature #768

Closed
armata007 opened this issue Jan 20, 2020 · 3 comments · Fixed by #769
Closed

MERGE_HEAD is lost when repository is using submodules feature #768

armata007 opened this issue Jan 20, 2020 · 3 comments · Fixed by #769
Labels

Comments

@armata007
Copy link

Description

Some naming I use in issue below:

  1. path-to-repo is jjust some path
  2. repo is actual repository name (main repository)
  3. submodule - name of repository which is submodule of repo

After updating to v10.0.0 MERGE_* files are lost when merging branch with conflicts in case of repository with submodules. I think it is connected to #756 .

Normally when using git repository /Users/path-to-repo/repo/.git/ is a folder and MERGE_* files are created inside it. But when using submodules feature /Users/pathpath-to-repo/repo/submodule/.git is a file containing path to actual .git directory, for example
gitdir: ../.git/modules/submodule. So /Users/path-to-repo/repo/submodule/.git is a file, containing path to /Users/path-to-repo/repo/.git/modules/submodule/ which is a proper directory where all MERGE_* files are really kept.

From the debug logs I can see that lint-staged is reading MERGE_* files from wrong path:
lint-staged:file Reading buffer from file '/Users/path-to-repo/repo/submodule/.git/MERGE_HEAD'
but it should read it from /Users/path-to-repo/repo/.git/modules/submodule/MERGE_HEAD

Steps to reproduce

  1. Have repository which is using submodules
  2. In one of the modules merge branch with conflicts
  3. after lint-staged is run MERGE message and MERGE_HEAD are lost
  4. if you fill in commit message you should also get
    fatal: could not open '/Users/path-to-repo/repo/.git/modules/submodule/MERGE_HEAD' for reading: No such file or directory

Debug Logs

expand to view
lint-staged:run Running all linter scripts +0ms
  lint-staged:git Running git command [ 'rev-parse', '--show-toplevel' ] +0ms
  lint-staged:run Resolved git directory to be `/Users/path-to-repo/repo/submodule` +21ms
  lint-staged:git Running git command [ 'diff', '--staged', '--diff-filter=ACMR', '--name-only' ] +20ms
  lint-staged:run Loaded list of staged files in git:
  lint-staged:run [ 
  ... files
  ] +21ms
  lint-staged:chunkFiles Resolved an argument string length of 6920 characters from 64 files +0ms
  lint-staged:chunkFiles Creating 1 chunks for maxArgLength of 131072 +0ms
  lint-staged:gen-tasks Generating linter tasks +0ms
  lint-staged:gen-tasks Generated task:
  lint-staged:gen-tasks { pattern: '*.{less,css}',
  lint-staged:gen-tasks   commands: [ 'prettier --write' ],
  lint-staged:gen-tasks   fileList: [] } +9ms
  lint-staged:gen-tasks Generated task:
  lint-staged:gen-tasks { pattern: '*.{js,jsx,ts,tsx}',
  lint-staged:gen-tasks   commands:
  lint-staged:gen-tasks    [ 'prettier --write',
  lint-staged:gen-tasks      'eslint -c .eslintrc.fix.js --ext .js --ext .jsx --fix --ext .ts --ext .tsx --fix',
  lint-staged:gen-tasks      'eslint -c .eslintrc.js --ext .js --ext .jsx --fix --ext .ts --ext .tsx' ],
  lint-staged:gen-tasks   fileList:
  lint-staged:gen-tasks    [ ...files ] } +1ms
  lint-staged:make-cmd-tasks Creating listr tasks for commands [ 'prettier --write' ] +0ms
  lint-staged:task cmd: prettier --write  +0ms
  lint-staged:task execaOptions: { preferLocal: true, reject: false, shell: false } +0ms
  lint-staged:make-cmd-tasks Creating listr tasks for commands [ 'prettier --write', 'eslint -c .eslintrc.fix.js --ext .js --ext .jsx --fix --ext .ts --ext .tsx --fix', 'eslint -c .eslintrc.js --ext .js --ext .jsx --fix --ext .ts --ext .tsx' ] +4ms
  lint-staged:task cmd: prettier --write ...files +0ms
  lint-staged:task execaOptions: { preferLocal: true, reject: false, shell: false } +0ms
  lint-staged:task cmd: eslint -c .eslintrc.fix.js --ext .js --ext .jsx --fix --ext .ts --ext .tsx --fix ...files +1ms
  lint-staged:task execaOptions: { preferLocal: true, reject: false, shell: false } +43ms
  lint-staged:task cmd: eslint -c .eslintrc.js --ext .js --ext .jsx --fix --ext .ts --ext .tsx ...files +1ms
  lint-staged:task execaOptions: { preferLocal: true, reject: false, shell: false } +0ms
Preparing... [started]
  lint-staged:git Backing up original state... +0ms
  lint-staged:git Backing up merge state... +0ms
  lint-staged:file Reading buffer from file `/Users/path-to-repo/repo/submodule/.git/MERGE_HEAD` +0ms
  lint-staged:file Reading buffer from file `/Users/path-to-repo/repo/submodule/.git/MERGE_MODE` +0ms
  lint-staged:file Reading buffer from file `/Users/path-to-repo/repo/submodule/.git/MERGE_MSG` +0ms
  lint-staged:file Done reading buffer from file `/Users/path-to-repo/repo/submodule/.git/MERGE_HEAD`! +5ms
  lint-staged:file Done reading buffer from file `/Users/path-to-repo/repo/submodule/.git/MERGE_MODE`! +0ms
  lint-staged:file Done reading buffer from file `/Users/path-to-repo/repo/submodule/.git/MERGE_MSG`! +36ms
  lint-staged:git Done backing up merge state! +41ms
  lint-staged:git Running git command [ 'stash',
  'save',
  '--quiet',
  '--include-untracked',
  '--keep-index',
  'lint-staged automatic backup' ] +150ms
  lint-staged:git Restoring merge state... +1s
  lint-staged:git Done restoring merge state! +0ms
  lint-staged:git Running git command [ 'ls-files', '--others', '--exclude-standard' ] +1s
  lint-staged:git Running git command [ 'stash', 'list' ] +107ms
  lint-staged:git Running git command [ 'diff',
  '--binary',
  '--unified=0',
  '--no-color',
  '--no-ext-diff',
  '--patch',
  'stash@{0}',
  '-R' ] +290ms
  lint-staged:git Done backing up original state! +468m

Environment

  • OS: macOS Catalina
  • Node.js: v10.17.0
  • lint-staged: v10.0.0
@iiroj
Copy link
Member

iiroj commented Jan 20, 2020

Thanks for the good issue description, @armata007! I'll take a look. Should be straightforward as long as we can detect that the current dir is a submodule.

@iiroj
Copy link
Member

iiroj commented Jan 20, 2020

@armata007 Do you think you could manually test that my fix works? You can clone this GitHub repo locally, then check out the branch submodule-merge-conflict and then swap the lint-staged bin to point to the checked out repo like <repo_location>/bin/lint-staged.

So something like:

cd /path/to/github-repositories
git clone git@github.com:okonet/lint-staged.git
cd lint-staged
git checkout submodule-merge-conflict
yarn

After this edit your husky/whatever script to run /path/to/github-repositories/lint-staged/bin/lint-staged.

@okonet
Copy link
Collaborator

okonet commented Jan 20, 2020

🎉 This issue has been resolved in version 10.0.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging a pull request may close this issue.

3 participants