I am assuming that when you are talking about 'folders' you mean the structure which individual items are exported into when you use your source control hooks, correct? To achieve this you need to loop over all items in the namespace and call the source-control related export on each of them.
The way we do that for our internal systems is to the the BaselineExport() method in the %Studio.SourceControl.ISC class. %Studio.SourceControl.ISC is our source control hooks class for Perforce, and I haven't tried calling BaselineExport() while another set of hooks are configured for the namespace, it may *just work*, especially if your GitLab hooks use the ^Sources global to describe the export structure. Give is a try and let us know if it help (if not, I can get you the code for that method and you could adopt it for your purposes)