trilbymedia / grav-plugin-git-sync

Collaboratively Synchronize your Grav `user` folder hosted on GitHub, BitBucket or GitLab
Apache License 2.0
243 stars 58 forks source link

Integrated "hasChangesToCommit" method. Resolves Issue #101. #102

Closed ScottHamper closed 6 years ago

ScottHamper commented 6 years ago

See Issue #101 for background.

Let me know if there's anything else I can do to make integrating this change easier/faster for you all.

ScottHamper commented 6 years ago

Hey All,

Any chance this can get merged soon? :(

w00fz commented 6 years ago

Sorry this took so long @ScottHamper . Thanks for reporting and exhaustively explaining the issue. I was trying to replicate what you mentioned but I am not getting the error you mentions. I only have pages setup for my folders and I was following your instructions by creating a test.txt dummy file via command line under user/pages.

After saving I did get the successful save banner but I haven't gotten the error message.

Am I missing something?

ScottHamper commented 6 years ago

Hey @w00fz ,

Thanks! To reproduce the issue, move test.txt into the root user folder. The repo should look something like:

/.git
...
/pages
/plugins
/themes
...
test.txt
w00fz commented 6 years ago

I tried that too and the file is completely ignored. Do you have folders configured differently other than pages?

w00fz commented 6 years ago

Also which version of git are you running and what's in your sparse-checkout file (user/.git/info/sparse-checkout)?

The thing that confuses me is that anything at the root that is not what's in sparse-checkout shouldn't be caught as changes at all. So when I drop any file at the root of user and then I git status, there is no change detected (as expected).

ScottHamper commented 6 years ago

Hey @w00fz ,

I've put together a more robust proof-of-concept in its own repo that you can play with.

Steps to reproduce:

  1. Clone the repo.
  2. Run sh deploy, or manually enter the following commands from the project root:
    1. composer build
    2. cp -r .git build/user
    3. git -C build/user checkout master
  3. cd build/user
  4. git commit
  5. echo $?

Step four results in the following output:

On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
        deleted:    .gitignore
        deleted:    .htaccess
        deleted:    LICENSE.txt
        deleted:    README.md
        deleted:    composer.json
        deleted:    deploy
        deleted:    web.config

Untracked files:
        config/media.yaml
        config/security.yaml
        config/streams.yaml
        plugins/
        themes/

no changes added to commit

The removed/untracked files cause isWorkingCopyClean to return false, so GitSync then runs git commit.

Step five shows that the git commit command exits with a status code of 1. This is where the guard clause in GitSync's execute method throws an exception and causes an error message to be displayed. I'm running Git version 2.13.2.windows.1, but I'll try upgrading and report back if it changes things.

The composer.json and deploy scripts are based on my real-world scripts. I needed a reasonable way to have the entire site be version controlled, with consistent/reproducible builds (grav/plugins pinned to specific versions) and still allow non-devs to edit pages without knowing Git. This was the solution I came up with.

EDIT: Updated to Git 2.18.0.windows.1 and get the same behavior.

w00fz commented 6 years ago

Thank you very much @ScottHamper that’s quite useful! I will try these steps out in the next few days and report back.