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 #756

Closed
arcanis opened this issue Dec 16, 2019 · 11 comments
Closed

MERGE_HEAD is lost #756

arcanis opened this issue Dec 16, 2019 · 11 comments
Milestone

Comments

@arcanis
Copy link

arcanis commented Dec 16, 2019

Description

I'm trying to change the behaviour of one of our postinstall scripts when the commit is done through a merge rather than a typical standalone commit. This doesn't seem possible at the moment, because lint-staged (10.0.0-beta.8) removes the MERGE_HEAD file and doesn't seem to restore it.

Steps to reproduce

git merge
(abort during the commit)
git merge --continue

Environment

  • lint-staged: 10.0.0-beta.8
@iiroj
Copy link
Member

iiroj commented Dec 16, 2019

Thanks for the report! This should be handled by lint-staged automatically, but it appears broken for you.

Can you post the debug logs by running lint-staged with the --debug flag?

@arcanis
Copy link
Author

arcanis commented Dec 16, 2019

Sure, here are the relevant logs. After this, my commands start to run but if I open a new terminal and inspect the .git folder the MERGE_* files are gone.

Preparing... [started]
  lint-staged:git Backing up original state... +0ms
  lint-staged:file Trying to access `/my/repo/.git/MERGE_HEAD` +0ms
  lint-staged:file Successfully accesses file `/my/repo/.git/MERGE_HEAD` +1ms
  lint-staged:git Detected current merge mode! +1ms
  lint-staged:git Backing up merge state... +0ms
  lint-staged:file Reading buffer from file `/my/repo/.git/MERGE_HEAD` +1ms
  lint-staged:file Reading buffer from file `/my/repo/.git/MERGE_MODE` +0ms
  lint-staged:file Reading buffer from file `/my/repo/.git/MERGE_MSG` +0ms
  lint-staged:file Done reading buffer from file `/my/repo/.git/MERGE_MODE`! +0ms
  lint-staged:file Done reading buffer from file `/my/repo/.git/MERGE_MSG`! +0ms
  lint-staged:file Done reading buffer from file `/my/repo/.git/MERGE_HEAD`! +0ms
  lint-staged:git Done backing up merge state! +1ms
  lint-staged:git Running git command [ 'stash', 'save', '--quiet', '--include-untracked', '--keep-index', 'lint-staged automatic backup' ] +116ms
  lint-staged:git Running git command [ 'ls-files', '--others', '--exclude-standard' ] +1s
  lint-staged:git Running git command [ 'stash', 'list' ] +225ms
  lint-staged:git Running git command [ 'diff', '--binary', '--unified=0', '--no-color', '--no-ext-diff', '--patch', 'stash@{0}', '-R' ] +49ms
  lint-staged:git Done backing up original state! +2s
Preparing... [completed]
Running tasks... [started]

@okonet
Copy link
Collaborator

okonet commented Dec 16, 2019

How do you abort during the commit?

@arcanis
Copy link
Author

arcanis commented Dec 16, 2019

When I abort I press ^C. However note that my actual problem is that the files aren't there while the commands are running (so for example writing back the file after the abort wouldn't fix it).

Is there a reason why the files aren't written back right after the stash in the prepare step?

@iiroj
Copy link
Member

iiroj commented Dec 16, 2019

@arcanis I think after the recent refactoring we only stash once, and indeed the files should be safe to add back right after! Let me try it...

@iiroj
Copy link
Member

iiroj commented Dec 16, 2019

I was able to restore MERGE_HEAD earlier in f8ddfc2, just after creating the backup stash and before running tasks. It still needs to be done in the previous step in case there are errors, since then we reset to original state by running git reset --hard and git stash pop. I added a second test for this scenario.

EDIT:

Released in v10.0.0-beta.9

@okonet
Copy link
Collaborator

okonet commented Dec 19, 2019

I just experienced it with the beta.12:

To reproduce I made several commits and then I ran git rebase -i master. Ended up with the following log after rewording the first commit:

husky > pre-commit (node v10.15.3)
No staged files match any of provided globs.
[detached HEAD 81c616a] Chore: Add homebridge config to the repo
 Date: Thu Dec 19 11:57:19 2019 +0100
 2 files changed, 20 insertions(+)
 create mode 100644 homebridge/config.json
husky > pre-commit (node v10.15.3)
  ✔ Preparing...
  ✔ Running tasks...
  ✔ Applying modifications...
  ✔ Cleaning up...
fatal: could not read log file '.git/MERGE_MSG': No such file or directory
Could not apply 39af0fc... Add development section to README

@iiroj
Copy link
Member

iiroj commented Dec 19, 2019

Thanks @okonet, I’ll check it out. The test does a rebase of two branches after a merge, maybe there’s an edge case.

@iiroj
Copy link
Member

iiroj commented Dec 20, 2019

@okonet I believe your fail was because I was only backing up the state when MERGE_HEAD was found. I separated handling of the the three MERGE_HEAD, MERGE_MSG and MERGE_ MODE from each other to hopefully fix this.

I also improved error handling in the case that there are errors during the first step (such as this).

Released in v10.0.0-beta.13

@okonet
Copy link
Collaborator

okonet commented Dec 20, 2019

Cool I’ll test it

@iiroj iiroj added this to the v10 milestone Dec 20, 2019
@iiroj
Copy link
Member

iiroj commented Jan 19, 2020

v10.0.0 has been released so this should be closed from the milestone.

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

No branches or pull requests

3 participants