Using git and submodule, what's a good folder structure?

前端 未结 3 722
轮回少年
轮回少年 2021-01-12 03:19

I use git with submodules, and I\'ve hard time to figure out how to organize my files. I develop in PHP, and use unit testing. So right now, I use this organization for each

相关标签:
3条回答
  • 2021-01-12 03:57

    I would not have the tests in a separate module. Keep it in the same repository.

    0 讨论(0)
  • 2021-01-12 03:58

    Your folder layout is mostly irrelevant as long as the autoloader can find your files somehow. If you are using PEAR convention for mapping class names to their source files, you can add the src directory to the include path or stack a second autoloader. Then you dont have to add src to the class names.

    The alternative to PEAR convention would be to use a static mapping between files and classes. There is a tool that can automatically generate such an autoloader for you at GitHub.

    The static autoloader approach is also used in PHP Project Wizard. That tool will create src and tests folders, including your phpunit config and the build file to connect your project with Jenkins CI. It's a convenient package.

    As for including submodules, consider putting them into a lib or ext folder. An example of how that looks can be found in the phpdox project at GitHub. Make sure you also look at the main bootstrap file to see how to include the various autoloaders then.

    0 讨论(0)
  • 2021-01-12 04:06

    What I did when faced with this problem was to create a folder called vendors and place all the submodules into that. Then I symlinked using relative paths the directories to the locations I wanted them in my code. You can commit the symlinks to git and they will still work when other pull the repository. Of course this only works if you are using a *nix based OS.

    For example:

    modules/
    vendor/module1/src/
    

    Could be symlinked like so (from the modules directory):

    ln -s ../vendor/module1/src module1
    

    Not sure if this solves your problem or not.

    0 讨论(0)
提交回复
热议问题