trilbymedia / grav-plugin-git-sync

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

Syncs only with master #136

Closed goldjg closed 4 years ago

goldjg commented 5 years ago

I have a grav blog skeleton running on an Azure Web App (Windows) instance (running IIS) where I successfully installed git-sync from the grav admin dashboard and synchronised it with a bitbucket private repo (this was just a simple repo with one branch (master).

Happy this was working, I decided to set it up against the non-prod version of my blog, which uses the develop branch of my blog repo (live site uses master, funnily enough).

However, when I try to save and sync, I get this: error: src refspec develop does not match any. error: failed to push some refs

Is this because it's not master, or because this is not a new repo/new branch?

git-sync status from the plugin via the command line is as follows:


array:16 [
  "branch" => "develop"
  "enabled" => true
  "folders" => "['pages', 'themes', 'plugins', 'config', 'data']"
  "git" => array:5 [
    "author" => "gituser"
    "message" => "(Grav GitSync) Automatic Commit"
    "name" => "GitSync"
    "email" => "git-sync@trilby.media"
    "bin" => ""D:\Program Files\Git\bin\git.exe""
  ]
  "gitVersion" => "2.19.1.windows.1"
  "isGitInitialized" => true
  "logging" => true
  "password" => "for my eyes only :-)"
  "remote" => array:2 [
    "branch" => "develop"
    "name" => "origin"
  ]
  "repository" => "https://bitbucket.org/goldjg/cirrius-tech-blog.git"
  "repositoryPath" => "D:/home/site/wwwroot/user/"
  "sync" => array:5 [
    "on_save" => true
    "on_delete" => true
    "on_media" => true
    "cron_enable" => false
    "cron_at" => "0 12,23 * * *"
  ]
  "username" => "goldjg"
  "webhook" => "_git-sync-cfe6915c6c37"
  "webhook_enabled" => "0"
  "webhook_secret" => "for my eyes only :-)"
]
detect git workspace root:

  D:/home/site/wwwroot/user

local git config:

  core.repositoryformatversion=0

  core.filemode=false

  core.bare=false

  core.logallrefupdates=true

  core.symlinks=false

  core.ignorecase=true

  core.sparsecheckout=true

  user.name=GitSync

  user.email=git-sync@trilby.media

  remote.origin.url=https://goldjg:{password}@bitbucket.org/goldjg/cirrius-tech-blog.git

  remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*

Testing connection to repository(git ls-remote)...

  b75c849c758fb03a203d4e3caadf7945b9362d34  HEAD

  14d03ce1b1578fc1e80b3e5a6b1c5f2789db847d  refs/heads/develop

  b75c849c758fb03a203d4e3caadf7945b9362d34  refs/heads/master

Checking workspace status(git status)...

  On branch master

  nothing to commit, working tree clean

Looks good: use --fetch option to check for updates.
w00fz commented 5 years ago

@goldjg This is because GitSync is not that great at switching branches after the facts (initial setup). It requires checkouts and potentially stashing and reverting which is a dangerous territory I'd rather not get the plugin involved with.

I can see you properly set GitSync to point to origin develop but I can also see your user git folder is still checked out at master instead of develop (because of the issue mentioned above).

I think the easiest fix for you is to manually checkout the develop branch from CLI and do the initial sync (git fetch && git pull) yourself. After that, verify your git branch is pointing to * develop and if that's the case then you should be good to user GitSync again.

goldjg commented 5 years ago

I'm pretty sure that I never ever set master as the branch in git-sync. Though it's possible it came through from the master branch that I tested git-sync in first. Tried as you suggested and it still synced from master and complained about src refspecs same as above.

I noticed though that it depends where I issue git commands from - if I do as you suggested from the repository directory in the web app then issue a git branch, I can see the correct branch, and then if I issue from the user/plugins/git-sync directory, I can see it showing master as though I hadn't gone through the git checkout develop process.

Once I issued the same commands from plugin directory it worked and git-sync is now in sync.

So another peculiarity of the Azure Web App implementation to watch out for.

There's several key paths in Azure IIS web app: D:\home\site\wwwroot = the Webroot D:\home\site\repository = where the repo is initially fetched to via the Azure Deployment scripts and their Git webhook before the site is built/deployed D:\Program Files\Git\bin = the git binaries D:\home\site\wwwroot\user\plugins\git-sync = the plugin dir for git-sync, where you need to issue any git CLI commands needed for the correct installation/functioning of git-sync for non-standard setups (e.g. not using the master branch)

w00fz commented 5 years ago

That is quite bizarre, isn't the user folder the actual git repository and plugins jus a subfolder of it? Do you actually have a .git folder in both user and user/plugins ?

goldjg commented 5 years ago

Afraid not. Azure fetches to the D:\home\site\repository directory as part of deployment and then it builds the site inc repo contents into D:\home\site\wwwroot.

So there’s effectively two repos - the entire site one that Azure uses and the user one gitsync is using. Which I didn’t really appreciate until today as I was caught in a loop of upgrading Grav and plugins from the admin plugin, and then gitsync would sync, and then it was like I hadn’t upgraded - repeat ad-Infinitum. So my thought of using gitsync to backup the entire web app won’t fly!

aatmmr commented 4 years ago

I stumbled upon this issue today. My setup is a simple Linux webspace with FTP access and no SSH capability - so I am limited in terms of git commands on the server. The aim is to sync with a GitLab repo using a branch other than master, namely production.

As the remote branch name cannot be set during setup, I ran git init in the \user folder on my local machine and created and checked out the branch production. I copied the content of the \user folder via FTP to the server replacing the exiting content (including the .git folder) and set the respective local and remote branch names in the plugin settings to both production. The sync worked afterwards nicely.

@w00fz, I understand the hassle of changing the branch through the plugin after the first setup, however, would it be possible to get a text field during setup / in the wizard to set the wanted branch name?

w00fz commented 4 years ago

I know it's not that intuitive but you can already do that @aatmmr . If you cancel the wizard, you can change the branch in the advanced section and then resume the Wizard afterwards.

aatmmr commented 4 years ago

Hi @w00fz. I'd like to contribute that part to the docs as others might face this question as well. Is there any other place than the Readme intended for documentation?

w00fz commented 4 years ago

README is the only place for the moment. Thank you!