Search code examples
gitgit-submodules

How is git bundle supposed to work with submodules ?


I am using git bundle to back up git repositories. In recent versions of git the repository metadata of a submodule are stored in .git/modules of the parent repository as opposed to before when it was stored in a .git directory right in the submodule.

When git-bundle is run in a submodule, it creates a bundle of the parent repo, omitting the submodules.

Anyone who can shed light on this?
How can I make a git bundle of a submodule?

reference: question on the git mailing list

edit:

After reading that for sschuberth it works, I wrote a script to test and can verify that it works. I have a backup script that relied on verifying the existence of a .git directory in order to know if it is in the top level dir of a repository and that thus broke when submodules started using .git files. If anyone knows what the recommended way is to garantee that you are in the top level folder of a repository, I'm interested. I don't know how I missed this.

Just in case it might interest someone who has to write test scripts for submodules, this is the script I used:

#!/bin/bash

git --version

mkdir super
mkdir subRemote

touch super/superFile.txt
touch subRemote/subFile.txt

cd super

   git init
   git add --all
   git commit -am"Initial commit"

cd ..


cd subRemote

   git init
   git add --all
   git commit -am"Initial commit"

cd ..


cd super

   git submodule add ../subRemote/.git
   git add --all
   git commit -am"added submodule"
   git submodule update
   echo -e "\ngit log in super:"
   git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative --all


   cd subRemote

      echo -e "\ngit bundle:"
      git bundle create ../../submoduleBundle --all --remotes

   cd ..

cd ..


git clone --mirror submoduleBundle bundledSub/.git

cd bundledSub

   git config core.bare false
   git config core.logallrefupdates true
   git remote rm origin
   git checkout

cd ..


#------------------------------------------------

cd super

   echo -e "\nfiles in super":
   ls -alh

cd ..


cd super/subRemote

   echo -e "\nfiles in super/subRemote":
   ls -alh

cd ../..


cd bundledSub

   echo -e "\nfiles in bundledSub":
   ls -alh

cd ..

Solution

  • Are you sure that running git submodule update succeeded and the .git file (not directory) in the submodule exists? In my tests bundling submodules works fine with version 1.7.9.6.

    If it still fails for you for some reason, a work-around would be to clone the submodule's repository into its own working tree and run git bundle from there (for the commit as shown by git submodule status in the superproject).