Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a git repository as a shared dependency of another git repository?

I need something akin to submodules, but which exist outside the main repository as a dependency.

Here's the problem:

I'm trying to use Git (in a REALLY awkward way) to manage design files for a CAD tool (Cadsoft Eagle), and I'm having a hard time figuring out if there is a way to use git submodules to manage each project's dependency upon the CAD tool's shared library.

I'm using a folder structure like this:

~/eagle/ <-- Main library used by multiple projects
    .git/     
    <library files>

~/projects/ <-- Projects folder
    Proj0/
        .git/
        <design files>
    Proj1/
        .git/
         <design files>

In this case, it doesn't make sense to add the eagle.git repository as a git submodule for each project.

However, I still need a way to snapshot the current state of the "eagle.git" repository so that if the library is updated in the future, it can be rolled back to access the specific revision of the library files which were being used when the Proj[x] was committed.

Ideally, I'd like something like the following:

~/eagle/ <-- Main library used by multiple projects
    .git/     
    <library files>

~/projects/ <-- Projects folder
    Proj0/
        .git/
        <design files>
        **eagle** <-- something that acts like a submodule  
                      but which actually points to ~/eagle/
    Proj1/
        .git/
         <design files>
         **eagle** <-- something that acts like a submodule  
                       but which actually points to ~/eagle/

I'd like to be able to:

cd ~/projects/Proj0
git submodule update

and have the ~/eagle/ directory automatically roll back to the revision checked into Proj0.

Anybody know of anything in Git that could allow for this kind of behavior?

like image 392
cdwilson Avatar asked Jul 27 '10 19:07

cdwilson


People also ask

How do I add a repository to a dependency on GitHub?

To npm install a public project that is hosted on Github, and not the NPM registry, add the Github repo to package. json dependencies using the username/repo#branch-name format. Run npm install and npm will download the project and save it into your /node_modules/ folder.

Can a Git repository contain another Git repository?

Submodules allow you to keep a Git repository as a subdirectory of another Git repository. This lets you clone another repository into your project and keep your commits separate.

How do I create a collaborative Git repository?

Click on the “Settings” tab of your rep, then “Collaborators” then search for Github users and add them by clicking “Add Collaborator”: They'll receive an email letting them know you added them and will be listed as a collaborator.


1 Answers

For each project, add .git/hooks/pre-commit (and make sure it's executable):

#!/bin/sh
git --git-dir=~/eagle/.git log -1 --pretty=format:%H >.eagle_rev
git add .eagle_rev

Then, for each project:

git config alias.update-eagle '!git --git-dir=~/eagle/.git --work-tree=~/eagle checkout -q $(<.eagle_rev)'

When you make a commit, it will record the current HEAD of ~/eagle, and git update-eagle will check out that commit in ~/eagle. (Then just make sure you git checkout <branch> in ~/eagle before you make any changes to it.)

like image 127
mkarasek Avatar answered Oct 16 '22 12:10

mkarasek