Coder Social home page Coder Social logo

Comments (18)

veewee avatar veewee commented on June 19, 2024

Hello @keradus,

Glad you enjoy our tool!
About your problem: this has been reported before.
Please take a look at issue: #67

This is not something that can be fixed, since phpcsfixer is running on the actual file. At the point of the last commit, the file has no CS issues and therefor you are able to commit.

from grumphp.

keradus avatar keradus commented on June 19, 2024

2 (alternative) hints then:

  • fail PHP CS Fixer task for file if file is in both stage and unstage status
  • pass content of staged version to stdin (PHP CS Fixer could work on stdin, no need to work on drive)

from grumphp.

veewee avatar veewee commented on June 19, 2024

The first hint is a bit strange. Both the staged as unstaged changes can succeed or fail.
The second one will be pretty hard. php-cs-fixer supports stdin, but other tools don't.

Maybe it's a better option to create a new task that can be enabled that checks files that are both in staged as non staged status. This way you can tell GrumPHP that an error can be triggered.
If you want it to just notify when a file exists in both statuses, you can disable the future blocking flag.
(see: #17)

What do you think of this solution?

(any other ideas @aderuwe ?)

from grumphp.

keradus avatar keradus commented on June 19, 2024

Does this behaviour occur on every task that run on files, like phpmd, composer etc?


Notify is not enough for me, and new task could do the trick, but wouldn't be the prettiest solution.

from grumphp.

keradus avatar keradus commented on June 19, 2024

Oh, and then... what about:

  • git stash
  • run tasks
  • git stash pop

?

from grumphp.

veewee avatar veewee commented on June 19, 2024

Yes, the behaviour applies to most tasks.
The stash idea is actually pretty nice.

I expect that the changes only have to be stashed during pre-commit and not at commit-msg level.
Not sure if stash works as expected during pre-commit. I will have to investigate this a bit further.
If it works, it's pretty easy to implement in the actual git-hook.
(However, this means that the grumphp git:pre-commit cli tool will pass in your case...)

Thanks for the hint :)

from grumphp.

keradus avatar keradus commented on June 19, 2024

Yeah, I have no idea would it work on commit hooks, but it would be extra cool ;)
If not then indeed the stage/unstage task will help as last solution.

Thank you for your support ;)

from grumphp.

aderuwe avatar aderuwe commented on June 19, 2024

in the case of stash and pop, we should probably either document it well or make it opt-in - if grumphp tasks take a long time to complete, this actually changes what users see in their working dir for some time?

from grumphp.

veewee avatar veewee commented on June 19, 2024

yes, that is indeed another consideration we'll have to make. Good point!
I think it's best to first find out if this stash idea will work. If it works we can add a well documented flag like ignore_unstaged_changes. This means that the logic has to be added to the git:pre-commit command.

If the stash idea doesn't work, an additional task as described above would be a solution.

Sounds pretty good for now right?

from grumphp.

aderuwe avatar aderuwe commented on June 19, 2024

Yup, I prefer the stash solution over the task, too.

from grumphp.

keradus avatar keradus commented on June 19, 2024

works in pre-commit hook

git stash -q --keep-index
call-tools
git stash pop -q

from grumphp.

veewee avatar veewee commented on June 19, 2024

Great, I just started creating an event subscriber for this functionality. Stay tuned :)

from grumphp.

veewee avatar veewee commented on June 19, 2024

Question: should this feature be enabled by default ?
It comes with some risks ... When PHP crashes in one of the tasks e.g., the changes are stored in git stash but the user might think that they are lost ...
Maybe it's best to disable it by default?

from grumphp.

veewee avatar veewee commented on June 19, 2024

I created a first version. All remarks more then welcome!

from grumphp.

keradus avatar keradus commented on June 19, 2024

For me having it disabled by default is risky - tool say everything is fine, and push the changes, and then see that i have sth not staged. But its to late, the damages were done.

you just run separated process for external tool CLI, if it will blow out you will know it from process informations

from grumphp.

veewee avatar veewee commented on June 19, 2024

I understand that this is strange behaviour. But when we just start to stash changes and something goes wrong, the user might think that his code is gone. That's not something that we want to happen.

Not all tasks run in a separated process. For example: the linters run in the actual GrumPHP process. So if for example you try to validate an XML of X MB, it might be possible that you run into a fatal error because of a memory limit or something.

It might be an idea to register a shutdown function in the listener to make sure that the popStash() method will be called. Not a big fan of those shutdown methods, but in this case it might be the solution?

from grumphp.

veewee avatar veewee commented on June 19, 2024

Fixed in #103.
Thanks @keradus for providing the git stash solution!

from grumphp.

keradus avatar keradus commented on June 19, 2024

Great to hear @veewee ! Thank you for all the work ;)
I will update my grumphp and work on new version from now, so I will report any issues, if they occur ;)

from grumphp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.