Search code examples
gitgitosis

Auto creating repository from stub with gitosis


Using gitosis to configure repositories works quite well.

However, manually creating every repository is quite cumbersome, especially as it has to be done on command line. (git init, git remote add, git commit, git push) As the majority of our projects are OSGi-Bundles, we can use almost the same repository layout and pom-file for each project. So instead of creating all this every time we have to create a new bundle i'd like to do something like this:

  1. User configures repository in gitosis-admin [works already]
  2. User pushes changes to gitosis [works already]
  3. gitosis enables access to repository [works already]
  4. gitosis creates a repository from a stub (containing .gitignore, pom.xml, empty src/ directory) [NEEDS TO BE DONE]
  5. User clones repository. [works already]
  6. User imports working copy into eclipse [works already]

Is there already a solution/common way to solve step 4? I'm currently thinking on using a git-hook to detect repository configuration. However, it seems that is may be necessary to parse the gitosis.conf file every time post-update is called.

Ideally, I'd like to use some git information to fill the pom.xml file (Repository-Name as artifactID, repository description as artifact description, etc..)

Is there a more convenient/robust way to get information about configured but not yet created repositories?


Solution

  • You could create a template repository somewhere that looks like this:

    $ ls -A
    .gitignore
    pom.xml
    src/.gitignore
    setup-remote
    

    Then your workflow for new repositories looks like this:

    • Developer clones the template repository:

      $ git clone .../template.git my-new-repo
      
    • Developer runs the setup-remote script to configure access to the actual remote repository:

      $ cd my-new-repo
      $ ./setup-remote
      

    And the setup-remote script takes care of:

    git remote rm origin
    git remote add origin .../my-new-repo.git
    git push origin master
    

    This presumes that Gitosis has been configured such that the developer can push to the remote repository.