10

I have a PHP Cartridge that is operating normally, except I can't find a straightforward way to get OpenShift to (recursively) push the files for my git submodules when/after it pushes my core repo files.

This seems like it should be a super straightforward and common use-case. Am I overlooking something?

I could probably ssh into my server and pull them manually, but I'd like to automate this completely, so that if I update the submodule's reference in my repo these changes will be reflected when I deploy.

Murray Rowan
  • 3,597
  • 2
  • 19
  • 32

2 Answers2

7

For a parent repo (which contains submodules), you should only have to push the parent repo itself: it includes the gitlink (special entries in the index) referencing the right SHA1 for each submodule.

Once pushed, a post-receive hook can trigger a:

git submodule update --init --recursive

That would update each submodule to the right SHA1.

The post-receive hook is in the parent bare repo: /path/to/parent.git/hooks/post-receive with:

#! /bin/bash
cd /path/to/non-bare/parent
git --git-dir=/path/to/parent.git checkout 
git --git-dir=/path/to/parent.git submodule update --init --recursive
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Could you add how to do this, exactly, to your answer? (add the post-receive hook, that is) – Murray Rowan Sep 10 '14 at 17:16
  • Sorry, I'm still confused as to how I could apply this to my OpenShift repos; I'm afraid I'm new to the concept of bare repos and don't quite know which files to edit where and how. Have you done this fix specifically with OpenShift's setup or is this advice generally applicable? – Murray Rowan Sep 16 '14 at 23:36
  • `git-submodule cannot be used without a working tree`? – OJFord Dec 18 '16 at 20:29
  • @OllieFord yes, asubmodule command needs a working tree to operate on (ie checkout the right fies). Hence the `cd /path/to/non-bare/parent` line. – VonC Dec 18 '16 at 20:35
  • @VonC But what is non-bare parent? My checkout location isn't currently a git repo. Just using `git --work-tree=... --git-dir=... checkout -f`, fine without submodules. – OJFord Dec 18 '16 at 20:42
  • @OllieFord `git --work-tree=... --git-dir=... checkout -f` is the same as `cd /path/to/non-bare/parent && git --git-dir=... checkout -f`: it is the path of a checked out repo, where all the files are visible. – VonC Dec 18 '16 at 20:43
  • @VonC Well, it reports as "Not a git repository", and submodule commands fail per above. – OJFord Dec 18 '16 at 20:46
  • @OllieFord not a git repository means the `--git-dir` parameter does not reference a `.git` folder. – VonC Dec 18 '16 at 20:57
  • @VonC It's referencing the bare repo, parent of `hooks` that the file's in. – OJFord Dec 18 '16 at 21:00
  • @OllieFord the it should work: could you post more details in a new question? – VonC Dec 18 '16 at 21:02
  • @VonC Yep, was about to hit 'submit' when you first replied. http://stackoverflow.com/questions/41212850 – OJFord Dec 18 '16 at 21:03
7

Ok, I'll take a stab at this for 50 extra points ;)

Here are the steps that I followed:

1.) Create php-5.3 application on OpenShift on clone to local machine.
2.) Create public git repository on github to use as the submodule.
3.) Add the github repository to the OpenShift application using the following commands, make sure that you use the https url instead of the git@ url, or you will get private key issues when OpenShift Online tries to checkout the sub-module.

 cd into your locally cloned openshift application directory  
 git submodule add https://github.com/developercorey/somesubmodule.git ./directory_name
 git add .
 git commit -am "adding a submodule"
 git push

If you don't see any errors in your git push, then everything should have worked correctly. if you see an error like this

remote: Host key verification failed.
remote: fatal: Could not read from remote repository.
remote: 
remote: Please make sure you have the correct access rights
remote: and the repository exists.

That means you used the git@ url instead of the https url to add your git submodule, or you are trying to access a private repository. Now you can ssh into your application using the rhc ssh command and cd into your ~/app-root/runtime/repo directory and you should see your submodule directory there with the files from that repository inside.

If that doesn't work for you, please let me know what the output of your git push is and we'll go from there.