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

[Solved] - how to add the user/themes dir to the sync #21

Closed
OvidiuS opened this issue Feb 14, 2017 · 6 comments
Closed

[Solved] - how to add the user/themes dir to the sync #21

OvidiuS opened this issue Feb 14, 2017 · 6 comments

Comments

@OvidiuS
Copy link

OvidiuS commented Feb 14, 2017

Awesome plugin, but I was surprised that it only syncs the user/pages folder. Why not have an option to sync the user/themes folder too, that would be very welcome during theme development when working with a team (so we won't have to set up another git repo with commit hooks for that).

Thank you for the awesome work!

@OvidiuS
Copy link
Author

OvidiuS commented Feb 14, 2017

Ok, I found a way to do it! It was already there but hidden, for some reason.

Here's how I enabled it, I hope others will find it useful too:

I poked around in the plugin files to see if there was a way to achieve this, and sure enough, in /user/plugins/git-sync/blueprint.yaml I found this hidden gem:

folders
  type: hidden
  multiple: true
  size: medium
  label: Sync Folders
  classes: fancy
  default: ['pages']
  options:
    pages: Pages
    themes: Themes
  validate:
    type: commalist

Changed it to:

folders
  type: selectize
  multiple: true
  size: medium
  label: Sync Folders
  classes: fancy
  default: ['pages','themes']
  options:
    pages: Pages
    themes: Themes
  validate:
    type: commalist

... and this made the hidden option appear in the plugin settings in the admin module.

It still wasn't pushing the templates folder to the GitHub repo though. I enabled logging the git commands and got an error message about how a .gitignore file is excluding templates folder. Sure enough, the user/.gitignore file was only allowing the pages folder to be pushed.

So I changed user/.gitignore to:

  !/pages  
  !/themes

And presto! It now syncs the themes folder too 😸

Why on earth was this hidden? And there's no mention of it in the docs. Recent addition I guess?

Again, thanks a lot for the awesome work!

@OvidiuS OvidiuS changed the title Add the user/themes dir to the sync? [Solved] - how to add the user/themes dir to the sync Feb 14, 2017
@w00fz
Copy link
Member

w00fz commented Feb 14, 2017

It's hidden because there are some implications when using anything but pages.

Themes for instance is not something that can be automatically synced (same goes for plugins). If you do themes changes most likely you are developing it by creating files or editing CSS, etc. there is no event on grav to trigger any synchronization based on those changes and so you have to manually sync yourself which will make it somewhat useless in one way.
On the other way, it is very useful if the change happens on the repository. Since the repository will trigger your site and pull the themes changes, it would make for a great collaborative theme development.
However because there is no automatic push of your changes to the repository but only automatic pulls, you will find out soon it's quite easy to end up with merge conflicts. I'm curious to know if you and your team are doing theme development with this option enabled, how does it go.

Config/Data/Accounts could be detected by grav events and they are but I have huge concerns on allowing those. Both can be containers of sensitive data like passwords, users, tokens, addresses, phone numbers, etc etc. this is all fine and good if you are aware and know what you are doing, especially if you are dealing with a private repository. However this could go wrong so easy in so many different ways that I'm just very hesitant about allowing the plugin to sync those folders.

That explains why the feature is hidden but functional. It's been implemented since the beginning, any folder under user Is supported for synchronization with all the pro and cons of above. In my opinion the most valuable of all is and will remain pages.

I still have plans on exposing those fields , I just want to add proper warnings and concerns around it.

Hope that answers your questions 🙂

@OvidiuS
Copy link
Author

OvidiuS commented Feb 16, 2017

On the other way, it is very useful if the change happens on the repository. Since the repository will trigger your site and pull the themes changes, it would make for a great collaborative theme development.
However because there is no automatic push of your changes to the repository but only automatic pulls, you will find out soon it's quite easy to end up with merge conflicts.

That's exactly the scenario I had in mind. One should be developing locally anyway, not on the server :) But the client will edit the content on the server, via the admin plugin, so it gets pushed to the git repo and synced down to our local environments.

I'm curious to know if you and your team are doing theme development with this option enabled, how does it go.

So far I'm the only one learning Grav in our team, but I'm spreading the good word and will collaborate with a teammate on a project soon. Will let you know 😄

Thanks for your answer!

@Raboo
Copy link

Raboo commented Jun 4, 2017

Hmm, well I would like to see a solution where you can git sync your entire site(user folder) except users and sensitive data.
Maybe have a cron job that runs or something that occasionally syncs everything when you edit a page, it can do a git status to see if everything is synced.

@biocarl
Copy link

biocarl commented Jun 18, 2017

HOW TO INCLUDE OTHER FOLDERS THAN PAGES TO THE REPO

I also wanted to sync the whole user folder so I changed some config-files and now it works (bi-directional). Note that as @w00fz pointed out, for other dirs other than pages the changes will be not automatically pushed.

1. Change to the installation folder of grav (e.g. grav-admin)
2. Run the following script:

#Add gitignore
echo '' >> user/.gitignore
echo '!/accounts' >> user/.gitignore
echo '!/config' >> user/.gitignore
echo '!/data' >> user/.gitignore
echo '!/plugins' >> user/.gitignore
echo '!/themes' >> user/.gitignore

#Add config/git-sync file
sed -i '5i \ \ - accounts' user/config/plugins/git-sync.yaml
sed -i '5i \ \ - config' user/config/plugins/git-sync.yaml
sed -i '5i \ \ - data' user/config/plugins/git-sync.yaml
sed -i '5i \ \ - plugins' user/config/plugins/git-sync.yaml
sed -i '5i \ \ - themes' user/config/plugins/git-sync.yaml

#Add to git checkout
echo '' >> user/.git/info/sparse-checkout
echo 'accounts/' >> user/.git/info/sparse-checkout
echo 'accounts/' >> user/.git/info/sparse-checkout
echo 'config/' >> user/.git/info/sparse-checkout
echo 'config/
' >> user/.git/info/sparse-checkout
echo 'data/' >> user/.git/info/sparse-checkout
echo 'data/' >> user/.git/info/sparse-checkout
echo 'plugins/' >> user/.git/info/sparse-checkout
echo 'plugins/
' >> user/.git/info/sparse-checkout
echo 'themes/' >> user/.git/info/sparse-checkout
echo 'themes/*' >> user/.git/info/sparse-checkout

3. This is working for GitSync v1.0.3 and might not working any more if the logic of configuration files was changed

PS: To manually commit changes cd to your root/user dir and do git add -A && git commit -m "manual commit" && git push. This should work.

@andrewscofield
Copy link

I think this makes the most sense if you use the most common git strategy, which is the use feature branches and then merge into a master or staging branch.

The way I set this plugin up is to include the almost the entire user folder, just like @biocarl did. And I set the production site to sync with master and my dev machines to sync a feature-specific branch or develop branch. That way my live site's theme and theme css doesn't get updated until I merge my develop branch into master. Using this method you can even technically have staging/beta servers setup as well. And everything can stay in sync and developers always have the latest content from production whenever they sync their master branch.

But I do understand that not everyone may have this setup in mind. It would be nice if it was easier to enable all the user folders to sync though.

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

No branches or pull requests

5 participants