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

fix: add --porcelain to git status --short #711

Merged
merged 1 commit into from
May 7, 2024

Conversation

110y
Copy link
Contributor

@110y 110y commented May 3, 2024

⚡ Summary

I faced an error like below (with LEFTHOOK_VERBOSE=true) when I partially added a file by git add -p and then executed git commit:

...
│ [lefthook] cmd: [git status --short]
│ [lefthook] dir: /path/to/my/repo
│ [lefthook] err: <nil>
│ [lefthook] out: MM xxx.yaml

│ [lefthook] saving partially staged files
│ [lefthook] cmd: [git diff --binary --unified=0 --no-color --no-ext-diff --src-prefix=a/ --dst-prefix=b/ --patch --submodule=short --output .git/info/lefthook-unstaged.patch -- 2mMM xxx.yaml]
│ [lefthook] dir: /path/to/my/repo
│ [lefthook] err: <nil>
│ [lefthook] out:
│ [lefthook] cmd: [git stash create]
│ [lefthook] dir: /path/to/my/repo
│ [lefthook] err: <nil>
│ [lefthook] out: ...

│ [lefthook] cmd: [git stash store --quiet --message lefthook auto backup ...]
│ [lefthook] dir: /path/to/my/repo
│ [lefthook] err: <nil>
│ [lefthook] out:
│ [lefthook] cmd: [git checkout --force -- 2mMM xxx.yaml]
│ [lefthook] dir: /path/to/my/repo
│ [lefthook] err: exit status 1
│ [lefthook] out: error: pathspec '2mM?[m?[31mM?[m xxx.yaml' did not match any file(s) known to git

Couldn't hide unstaged files: error in batch 0: exit status 1
...

As a result, the whole file has been committed unexpectedly.

Given that, this PR fixes the issue by adding --porcelain, an option that makes the output machine-readable, to git status command.
With this fix, I see now lefthook properly hides partially staged files as below:

│ [lefthook] cmd: [git status --short --porcelain]
│ [lefthook] dir: /path/to/my/repo
│ [lefthook] err: <nil>
│ [lefthook] out: MM xxx.yaml

│ [lefthook] saving partially staged files
│ [lefthook] cmd: [git diff --binary --unified=0 --no-color --no-ext-diff --src-prefix=a/ --dst-prefix=b/ --patch --submodule=short --output .git/info/lefthook-unstaged.patch -- xxx.yaml]
│ [lefthook] dir: /path/to/my/repo
│ [lefthook] err: <nil>
│ [lefthook] out:
│ [lefthook] cmd: [git stash create]
│ [lefthook] dir: /path/to/my/repo
│ [lefthook] err: <nil>
│ [lefthook] out: ...

│ [lefthook] cmd: [git stash store --quiet --message lefthook auto backup ...]
│ [lefthook] dir: /path/to/my/repo
│ [lefthook] err: <nil>
│ [lefthook] out:
│ [lefthook] cmd: [git checkout --force -- xxx.yaml]
│ [lefthook] dir: /path/to/my/repo
│ [lefthook] err: <nil>
│ [lefthook] out:
│ [lefthook] hide partially staged files: [xxx.yaml]

☑️ Checklist

  • Check locally
  • Add tests
  • Add documentation

@110y
Copy link
Contributor Author

110y commented May 7, 2024

@mrexox I appreciate if you could take a look this PR, thanks 🙏

@mrexox mrexox merged commit 5c6d8ae into evilmartians:master May 7, 2024
19 checks passed
@mrexox
Copy link
Member

mrexox commented May 7, 2024

Thank you for this PR!

@110y 110y deleted the status-porcelain branch May 8, 2024 01:12
@110y
Copy link
Contributor Author

110y commented May 8, 2024

@mrexox

Thank you for merging this!
Could you please cut a new release...? 🙏

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

Successfully merging this pull request may close these issues.

None yet

2 participants