Giter VIP home page Giter VIP logo

Comments (8)

alexmanase avatar alexmanase commented on September 5, 2024 1

That worked!

I've got the Permission denied error, but I fixed it with chmod 755 ./scripts/git-add-staged .

Thank you!

from whisky.

ProjektGopher avatar ProjektGopher commented on September 5, 2024

@alexmanase I've committed @faissaloux's PR and released a patch. If you composer update this should be fixed.

from whisky.

alexmanase avatar alexmanase commented on September 5, 2024

Thanks! It works now, but I think there is an issue. When I run commit and push the Git actions don't actually work. I mean the text is displayed in terminal as if the commit is working, but it's not.

image

As you can see the script is working, the changes are staged, but there is still the asterisks, which means that the changes are not actually staged.

image

When I run git status, it also looks like the changes from the pre-commit hook are not staged.

from whisky.

ProjektGopher avatar ProjektGopher commented on September 5, 2024

@alexmanase Can you paste in your whisky.json, as well as the exact commands being run? If you're running a linter, you'll have to re-add the staged files after they've been linted.

Thx for taking the time on making an issue, btw. This is super helpful for me.

from whisky.

alexmanase avatar alexmanase commented on September 5, 2024
{
  "disabled": [],
  "hooks": {
    "pre-commit": [
      "./vendor/bin/pint && blade-formatter --write './resources/**/*.blade.php'"
    ],
    "pre-push": [
      "composer test:all"
    ]
  }
}

have to re-add the staged files after they've been linted

I added them using git add . && git commit -m 'wip'.

Thx for taking the time on making an issue, btw. This is super helpful for me.

You're welcome. I'm glad I can help.

from whisky.

ProjektGopher avatar ProjektGopher commented on September 5, 2024

Did you add and commit once, or did you do it twice? Here's what would need to happen:

  1. save work, git add . && git commit -m 'wip'
  2. pint and blade-formatter then run, and write the files
  3. re-add those same files git add . && git commit -m 'formatting'
  4. git push

Even though pint and blade-formatter are being run pre-commit, those new writes wont be staged for the actual commit. It might be better to add the --test flag to pint, and if there's a similar one for blade-formatter I'd do that as well. That way the commit fails, and forces you to pass before the commit succeeds.

from whisky.

alexmanase avatar alexmanase commented on September 5, 2024

That way the commit fails, and forces you to pass before the commit succeeds.

Now it makes more sense and it works as intended then. Shouldn't this be added in the documentation with explanation and example?

and if there's a similar one for blade-formatter I'd do that as well

Unfortunately, there isn't.

Wouldn't be possible to stage the new writes from the hooks?

from whisky.

ProjektGopher avatar ProjektGopher commented on September 5, 2024

Shouldn't this be added in the documentation with explanation and example?

I agree. I should add this.

Wouldn't be possible to stage the new writes from the hooks?

Actually there is! In your project root, create a folder named scripts, and make a file named git-add-staged with the following contents:

#!/bin/bash

# Create a list of all staged files
# filter out deleted files
STAGED_FILES=$(git diff --name-only --cached --diff-filter=d)

# Pass that list of files to the following commands
if [ -n "$STAGED_FILES" ]; then
    # Re-stage the files that were just linted
    git add $STAGED_FILES
fi

This script will create a list of all the files that are already staged, and re-add them. That way you're not accidentally committing files that aren't ready for version control yet. The only downside is that it adds the whole file, so it doesn't allow you to just stage 'chunks'.

Then in your whisky.json, add a reference to that under the other command:

{
  "disabled": [],
  "hooks": {
    "pre-commit": [
      "./vendor/bin/pint && blade-formatter --write './resources/**/*.blade.php'",
      "./scripts/git-add-staged"
    ],
    "pre-push": [
      "composer test:all"
    ]
  }
}

OR if you'd rather just add all files every time you can skip all that and just add git add . instead of ./scripts/git-add-staged

from whisky.

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.