Using version control with non-hierarchical code?

拥有回忆 提交于 2020-01-14 09:54:08

问题


I am looking at putting a code base that runs several website into version control. There are several instance of this code base running websites on different virtual servers.

The problem I'm grappling with is that each of these separate instances of more or less the same code have sub-directories with site-specific functions. But it seems that version control systems want to control the entire directory hierarchy.

For instance, each instance has the directory

/www/smarty/libs/plugins/

Where you'll find site-specific functions for smarty. When we are ready to put it into version control, the folder /www would be the root.

So one option is to have all the site-specific functions going out to all sites. I don't see a problem in and of itself, but it seems somehow architecturally 'wrong'. There would be a bunch of files that only belong to one deployment.

Another option is to have a separate repository for each site's specific files within the code base. But that sounds like it could quickly become a nightmare when trying to get new sites deployed properly.

What's the best way to do this? The version control system we're looking at is subversion.


回答1:


Generally, source control systems should be used to control source. They are not at their best completely controlling file hierarchies, permissions, and other related things. These are best left to deployment configuration.

How about having each of the projects and directories you need represented once in the version control system. Then, in a separate directory (perhaps called /build/), have the various configuration layouts. You might have an ant file that builds each site, or maven. Or you can use tools like Capistrano or Fabric to have more control over each deployment.




回答2:


The tools are made to be flexible (generally), so here are some suggestions:

  1. Most VCS' allow you to ignore files and directories through some mechanism (e.g. Mercurial .hg ignore file), so you should be able to target what you want/should control versus what shouldn't be.

  2. Separate the files/directories into common resource project and site-specific projects and then use a build system to integrate them to create a deployable package. The build system can be as simple as a shell script or a more sophisticated framework. If its a really simple integration, the VCS may have some basic features for merging bases (e.g. Mercurial subrespositories).




回答3:


With subversion, you could have a bunch of repositories:

  • www be in a general repository
  • plugins each be in a site-specific repository

Then have nested working copies:

svn co http://www_repo www
cd www/smarty/libs
svn co http://foo_plugins_repo plugins

Tip: add plugins to svn:ignore property of www/smarty/libs

svn propset svn:ignore "plugins" www/smarty/libs

You could certainly do that with git too (through .gitignore), and probably with other version control systems but I don't know them.

(Alternatively you could skip the nested working copy part (which can freak some people out) and check out stuff side by side, but use a symlink in lieu of smarty/libs/plugins, while ignore still pertains)




回答4:


You're missing a "build" step, which whould take the source in source control and create the deployment bundles for the different sites. Only one source package is needed, different build configurations create the different deployment packages. Don't try to directly put the deplyoment set into source control, it is not the source!




回答5:


I believe the best thing to do would be to create a top level directory in your repository for each site (Site-01, Site-02, etc) and inside those directories put the source tree. Then you can checkout the projects separately. I think it's acceptable and somewhat standard to use the same repository for all the projects your company is involved with.

My terminology might be off kilter, but the fundamental idea is sound, I believe.



来源:https://stackoverflow.com/questions/4852124/using-version-control-with-non-hierarchical-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!