PeteBatin's avatar

Forking a Github Repo and Composer Update

Hi all,

It's not strictly/solely a Laravel question but I'm hoping the collective hive mind can help.

I'm using github . com/pionl/laravel-chunk-upload on a couple of projects and I've noticed there's a bit of a bug when it comes to it's clean up operations (deleting incomplete/old upload chunks). When it encounters a corrupted path due to characters in a previously uploaded file (unicode emojis) it fails the clean up operation and prevents it from continuing. I only realised this bug when the server came to a grinding halt due to the disk being almost entirely full with old chunks that weren't removed.

The bug has been reported and a Pull Request has been raised with a fix (hashing filenames instead of using original filenames) but it's not been implemented. Martin's a busy guy.

Obviously cannot make changes to the directory in vendors as it would get overwritten with composer update. So I've forked the repo and merged the pull request for the fix into it.

Now to install, how would one normally install a package that isn't available via composer?

I've considered publishing to packagist so that it's available to install via composer but within composer.json there are still references to the original package (pion/laravel-chunk-upload) so I'm wondering whether running composer update in the future would pull from the original repo instead of the one with the fix? Sorry the questions are a little naive, I'm fairly green when it comes to this.

All advice greatly appreciated. Thank you!

0 likes
4 replies
stayallive's avatar
Level 3

So this is an interesting one... normally the answer is to make the following changes to your composer.json. You tell composer where to find the repository and that you want the dev-<BRANCH>@dev (dev- prefix means that you want a branch and @dev suffix indicates composer is allowed to install a development dependency).

So like this:

{
    "require": {
        "pion/laravel-chunk-upload": "dev-fix-#143@dev"
    },
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/Janith-Umeda/laravel-chunk-upload"
        }
    ]
}

However... in this case this won't work since the author used a # in their branch name 🙈 Composer parses dev-fix-#143@dev as branch fix- with commit hash 143 which is not what you need. There seems to be no way around this too (see: https://github.com/composer/composer/issues/5420).

So what you can do, is fork the repo yourself and make a branch named something like fix-143 and commit the fix to that and then use the above changes to your composer.json to install it. But don't use any special characters (except for a /) in your branch name because that will probably confuse composer.

Long story but hopefully this helps!

PeteBatin's avatar

@stayallive thank you, it's helped just need to put it in place and have a little confusion.

So I already forked and merged the changes from fix#143 https://github.com/SDGPeteBatin/laravel-chunk-upload

But just for clarification, that won't work (in terms of installation) and to do below, let me know if I've got this right...

  • Fork the original again and leave that as is (let's say SDGPeteBatin/laravel-chunk-upload-new)
  • Create another branch of the one I just forked
  • Call the branch fix-143 and apply fix-#143 to that branch

Then in composer.json (is that my Laravel Projects composer.json?)

{
    "require": {
        "pion/laravel-chunk-upload": "dev-fix-143@dev"
    },
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/SDGPeteBatin/laravel-chunk-upload-new"
        }
    ]
}

And then presumably composer update?

stayallive's avatar

@PeteBatin that looks exactly right! But again, this is only needed because of the # in the branch name of the PR author, otherwise you could just use that repository and branch instead and you don't need yet another fork 😎

Please or to participate in this conversation.