pedroborges / kirby-autogit

⬢ Saves every change made via Kirby Panel to a Git repository
149 stars 23 forks source link

Files renamed by config hook don't get committed to git #30

Closed fitzage closed 7 years ago

fitzage commented 7 years ago

So I have my mp3 uploads getting renamed and dumped to S3 and ignored by git. I plan to eventually do the same thing with PDF files, but I'm currently uploading them and having a panel hook rename them, but leave them in place.

The problem is, the initial file upload is what gets committed to git, and if I then go look at the git status, it shows those files as being deleted and the new names not being committed.

Is there a way I can manually trigger autogit during my rename? Also, if there's a way to not get autogit to trigger until after the rename, that would be even better to avoid git history cruft.

pedroborges commented 7 years ago

Yes, you can call Auto Git's save method from inside the panel.file.rename hook:

kirby()->hook('panel.file.rename', function ($file) {
    // your logic

    autogit()->save('file.rename', $file->page()->uri().'/'.$file->filename());
});

You can the hooks file as a reference.

fitzage commented 7 years ago

Excellent, thanks. Did the trick.