git restore submodules - submodule directory created but empty

Viewed 734

When pushing to production the submodules are not updated. The submodule root directory is created but no files inside

post-receive

#/bin/sh
cd /var/www/repo
git --work-tree=. --git-dir=/var/git_repos/repo.git checkout master -f
git --work-tree=. --git-dir=/var/git_repos/repo.git git submodule update --init --recursive

When browsing through github the submodules are present and linked with latest version

When I run git push production master from remote I get this

# git push production master
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 284 bytes | 284.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0), pack-reused 0
remote: Already on 'master'
remote: git: 'git' is not a git command. See 'git --help'.
remote:
remote: The most similar command is
remote:         init
To ssh://domain.com/var/git_repos/repo.git
   a710c83..6d75702  master -> master
1 Answers

As I mentioned in our discussion, I would first use git submodule update, because it will:

  • update the registered submodules to match what the superproject expects by cloning missing submodules,
  • fetch missing commits in submodules and
  • update the working tree of the submodules.

The second point "fetch missing commits in submodules" is the missing step which triggers, when you push to your base repo, the error message

remote: fatal: failed to unpack tree object d09a53c53a7bd222df4869e66b9e45acee45e094
remote: error: Submodule 'php/repo/utils' could not be updated.

So try with the script:

#/bin/sh
cd /var/www/repo
git --work-tree=. --git-dir=/var/git_repos/repo.git checkout master -f
git --work-tree=. --git-dir=/var/git_repos/repo.git submodule update --remote
                                                  ^^^^
                                                (no git there)
Related