0

I would like to create a simple script, that will download plugins from remote repositories into directory. I have an array of URLs, to git files on remote server - like this one from GitHub https://github.com/nette/sandbox.git. GitHub has support for downloading ZIP archives but I have plugins from many other repositories which doesn't offer this option.

Back to my question - is there any option how to get the archive instead of downloading full repository and exporting archive from it using git in command line? I have found this question - Do a "git export" (like "svn export")? - but this wouldn't be possible using PHP.

Community
  • 1
  • 1
Northys
  • 1,305
  • 3
  • 16
  • 32

1 Answers1

0

this post gives you details about exporting git in the way you mentioned .

git archive HEAD --format=zip > archive.zip

You can also archive a remote using the --remote= option. Just be aware that this does not work with GitHub remotes, as they encourage you to use the download button instead. With any other remote it should work fine though, and check the manpage if you’re having issues.

but the problem with this method is when i tried it with both github and bitbuck i got remote doesn't support protocol error .


i just wrote code for a generic solution on my machine and its working for me . let me share it with you . you can execute shell command using php using shell_exec .

<?php 

//clearing a folder named test if it exist(avoiding git errors) 
shell_exec('rm -rf test');

//cloning into test folder
shell_exec('git clone https://github.com/nette/sandbox.git test');

//archiving
shell_exec('cd test && git archive HEAD --format=zip > archive.zip');

//copying to root folder
shell_exec('cp test/archive.zip archive.zip');

//removing the temp test folder we created
shell_exec('rm -rf test');

?>

shell_exec won't work if php safemode is turned on . you might require setting appropriate permissions for the script etc . but i think this an idea to start with php, for getting what you want.

Sojan Jose
  • 3,168
  • 6
  • 33
  • 52