Skip to content

Commit

Permalink
Running update-server-info for submodules
Browse files Browse the repository at this point in the history
This allows new repositories to successfully use and deploy submodules.
Previously this has not been working.

See also discussion at: trebuchet-deploy/trigger#27

Change-Id: I8e32956652901ea3b66459c675a1cadd8d7b669f
  • Loading branch information
ottomata committed May 13, 2014
1 parent 0498dc1 commit 594b001
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions modules/deployment/files/modules/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import urllib
import os
import json
import pwd
import salt


Expand Down Expand Up @@ -189,6 +190,42 @@ def deployment_server_init():
status = __salt__['cmd.retcode'](cmd, runas=deploy_user,
umask=002,
cwd=config['location'])

# http will likely be used as deploy targets' remote transport.
# submodules don't know how to work properly via http
# remotes unless info/refs and other files are up to date.
# This will call git update-server-info for each of the
# checkouts inside of the .git/modules/<modulename> directory.
cmd = ("""git submodule foreach --recursive """
"""'cd $(sed "s/^gitdir: //" .git) && """
"""git update-server-info'""")

status = __salt__['cmd.retcode'](cmd, runas=deploy_user,
umask=002,
cwd=config['location'])

# Install a post-checkout hook to run update-server-info
# for each submodule. This command needs to be run
# every time the repository is changed.
hook_directory = os.path.join(
config['location'], '.git', 'hooks'
)
post_checkout_path = os.path.join(
hook_directory, 'post-checkout'
)
post_checkout = open(post_checkout_path, 'w')
post_checkout.write(cmd + "\n")
post_checkout.close()
os.chmod(post_checkout_path, 775)

# we should run this on post-commit too, so just symlink
# post-commit to post-checkout
post_commit_path = os.path.join(hook_directory, 'post-commit')
os.symlink(post_checkout_path, post_commit_path)
# chown the hooks to the deploy_user
deploy_uid = pwd.getpwnam(deploy_user).pw_uid
os.chown(post_checkout_path, deploy_uid, -1)
os.lchown(post_commit_path, deploy_uid, -1)
else:
cmd = '/usr/bin/git init %s' % (config['location'])
status = __salt__['cmd.retcode'](cmd, runas=deploy_user,
Expand Down

0 comments on commit 594b001

Please sign in to comment.