trilbymedia / grav-plugin-git-sync

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

Sync only with master branch? #56

Closed aalyokhin closed 6 years ago

aalyokhin commented 7 years ago

Hi guys.

I'm fighting with this for the whole day already. Got tired of manual content sync and decided to give git-sync a shot. But it's just not working for me. Details:

I need to set-up separate branch (like content-sync), so the plugin could sync the content with it and then I'll merge the changes where I need to. But it looks like it works only when remote branch is set to master. I have already tried a lot of times to set up it from scratch but the result is the same - when I click save after filling all options:

error: src refspec content-sync does not match any. error: failed to push some refs to 'https://aalyokhin:{password}@bitbucket.org/aalyokhin/reponame.git'

When I set it to master it works like a charm. Tried it with Bitbucket and VS Team services repos - all the same, master works, branch doesn't. What I'm missing? Syncing with master is redicilous...

Logs:

[2017-06-18 11:08:19] grav.NOTICE: gitsync[command]: LC_ALL=en_US.UTF-8 /usr/local/cpanel/3rdparty/bin/git -C '/home/offsfjni/_sites/qa.reponame.com/user/' config user.name "GitSync" 2>&1 [] []
[2017-06-18 11:08:20] grav.NOTICE: gitsync[output]:  [] []
[2017-06-18 11:08:20] grav.NOTICE: gitsync[command]: LC_ALL=en_US.UTF-8 /usr/local/cpanel/3rdparty/bin/git -C '/home/offsfjni/_sites/qa.reponame.com/user/' config user.email "git-sync@trilby.media" 2>&1 [] []
[2017-06-18 11:08:20] grav.NOTICE: gitsync[output]:  [] []
[2017-06-18 11:08:21] grav.NOTICE: gitsync[command]: LC_ALL=en_US.UTF-8 /usr/local/cpanel/3rdparty/bin/git -C '/home/offsfjni/_sites/qa.reponame.com/user/' remote get-url "origin" 2>&1 [] []
[2017-06-18 11:08:21] grav.NOTICE: gitsync[output]: https://bitbucket.org/aalyokhin/reponame.git [] []
[2017-06-18 11:08:21] grav.NOTICE: gitsync[command]: LC_ALL=en_US.UTF-8 /usr/local/cpanel/3rdparty/bin/git -C '/home/offsfjni/_sites/qa.reponame.com/user/' remote set-url origin "https://bitbucket.org/aalyokhin/reponame.git" 2>&1 [] []
[2017-06-18 11:08:21] grav.NOTICE: gitsync[output]:  [] []
[2017-06-18 11:08:22] grav.NOTICE: gitsync[command]: LC_ALL=en_US.UTF-8 /usr/local/cpanel/3rdparty/bin/git -C '/home/offsfjni/_sites/qa.reponame.com/user/' status 2>&1 [] []
[2017-06-18 11:08:22] grav.NOTICE: gitsync[output]: On branch master nothing to commit, working tree clean [] []
[2017-06-18 11:08:23] grav.NOTICE: gitsync[command]: LC_ALL=en_US.UTF-8 /usr/local/cpanel/3rdparty/bin/git -C '/home/offsfjni/_sites/qa.reponame.com/user/' remote get-url "origin" 2>&1 [] []
[2017-06-18 11:08:23] grav.NOTICE: gitsync[output]: https://bitbucket.org/aalyokhin/reponame.git [] []
[2017-06-18 11:08:23] grav.NOTICE: gitsync[command]: LC_ALL=en_US.UTF-8 /usr/local/cpanel/3rdparty/bin/git -C '/home/offsfjni/_sites/qa.reponame.com/user/' remote set-url origin "https://aalyokhin:{password}@bitbucket.org/aalyokhin/reponame.git" 2>&1 [] []
[2017-06-18 11:08:23] grav.NOTICE: gitsync[output]:  [] []
[2017-06-18 11:08:24] grav.NOTICE: gitsync[command]: LC_ALL=en_US.UTF-8 /usr/local/cpanel/3rdparty/bin/git -C '/home/offsfjni/_sites/qa.reponame.com/user/' fetch origin content-sync 2>&1 [] []
[2017-06-18 11:08:25] grav.NOTICE: gitsync[output]: From https://bitbucket.org/aalyokhin/reponame  * branch            content-sync -> FETCH_HEAD [] []
[2017-06-18 11:08:25] grav.NOTICE: gitsync[command]: LC_ALL=en_US.UTF-8 /usr/local/cpanel/3rdparty/bin/git -C '/home/offsfjni/_sites/qa.reponame.com/user/' pull --allow-unrelated-histories -X theirs origin content-sync 2>&1 [] []
[2017-06-18 11:08:26] grav.NOTICE: gitsync[output]: From https://bitbucket.org/aalyokhin/reponame  * branch            content-sync -> FETCH_HEAD Already up-to-date. [] []
[2017-06-18 11:08:26] grav.NOTICE: gitsync[command]: LC_ALL=en_US.UTF-8 /usr/local/cpanel/3rdparty/bin/git -C '/home/offsfjni/_sites/qa.reponame.com/user/' push origin content-sync:content-sync 2>&1 [] []
[2017-06-18 11:08:26] grav.NOTICE: gitsync[output]: error: src refspec content-sync does not match any. error: failed to push some refs to 'https://aalyokhin:{password}@bitbucket.org/aalyokhin/reponame.git' [] []

Thanks in advance!

karfau commented 7 years ago

Hey @aalyokhin ,

what is the output when doing git branch on the server that you are trying this with? From the log output it looks like the branch content-sync doesn't exist locally, as in has never been checked out?

Best Christian

aalyokhin commented 7 years ago

@karfau thanks a lot for your answer and for pointing me to right direction.

Indeed, git branch gave me On branch master. I've checked out needed branch manually and it worked. I'm updating the site manually by uploading new version to a server and then unpacking it there. Does it mean, that every time I'm uploading new site version, I will have to use SSH to checkout content-sync branch in the console? I'm wondering why the plugin does not do it by itself, as it makes sense to checkout the branch which is set in the options, by pressing Save button after configuring it...

karfau commented 7 years ago

Glad this solved your problem. Not sure what you mean by unpack. I would expect that you are always keeping the branch checked out. If you are uploading content manually to the directory under version control you would need to also commit those changes using ssh, right?

What about just commiting and pushing your changes to the content-sync branch when developing, and then just doing a git pull via ssh? (actually the git-sync plugin also does that when it "synchronizes" (I believe there is a button in the configuration page of the plugin?), if this is good enough when editing both in the admin panel and on your developer machine, is something for you to find out. You should also be able to configure the webhook as described in the wizard, to automaticall sync your changes whenever you push something to the repo.

I agree the plugin could/should make sure the configured branch is checked out, so it commits to the right one. I guess currently it just assumes that the branch you configure is already checked out... yes, this plugin still has some rough edges :)

w00fz commented 7 years ago

Good catch here guys. I think nowhere in the execution of the sync a 'checkout' is happening. It should do a git checkout <branch_in_config> every time it begins, to ensure it is on the right one.

@aalyokhin when you manually switched to content-sync, it didn't ever revert back to master correct?