3 ## Take an existing, tar-based CiviCRM directory and convert it to a git working directory
7 ###########################################
8 ## usage: do_gitify <repo-url> <existing-dir> [git-checkout-options]
15 if [ -d "$TGT/.git" ]; then
16 echo "[[Already checked out git repo ($TGT) -- skip $REPO]]"
19 [ -d $TGT ] || mkdir
-p "$TGT"
20 [ -d $TMP ] && rm -rf "$TMP"
21 echo "[[Checkout $REPO ($TMP)]]"
22 echo "[git clone "$@
" "$REPO" "$TMP"]"
23 git clone
"$@" "$REPO" "$TMP"
25 echo "[[Swap metadata]]"
26 mv "$TMP/.git" "$TGT/.git"
28 echo "[[Remove local modifications]]"
29 pushd "$TGT" > /dev
/null
36 ###########################################
37 ## add hook shims to a repo
38 ## usage: do_hookify <canonical-repo-name> <repo-path> <relative-hook-path>
39 function do_hookify
() {
40 GIT_CANONICAL_REPO_NAME
="$1"
43 if [ -n "$CIVICRM_GIT_HOOKS" ]; then
44 echo "[[Install recommended hooks ($TGT)]]"
45 for HOOK
in commit-msg post-checkout post-merge pre-commit prepare-commit-msg post-commit pre-rebase post-rewrite
;do
46 cat << TMPL > "$TGT/.git/hooks/$HOOK"
48 if [ -f "\$GIT_DIR/${HOOK_DIR}/${HOOK}" ]; then
49 ## Note: GIT_CANONICAL_REPO_NAME was not provided by early hook-stubs
50 export GIT_CANONICAL_REPO_NAME="$GIT_CANONICAL_REPO_NAME"
51 source "\$GIT_DIR/${HOOK_DIR}/${HOOK}"
54 chmod +x
"$TGT/.git/hooks/$HOOK"
57 echo "[[Skip hook installation ($TGT) -- use \"--hooks\" to enable]]"
61 ###########################################
62 ## Create or update the URL of a git remote
63 ## usage: git_set_remote <local-repo-path> <remote-name> <remote-url>
64 function git_set_remote
() {
68 echo "[[Set remote ($REMOTE_NAME => $REMOTE_URL within $REPODIR)]]"
70 pushd "$REPODIR" >> /dev
/null
71 git remote set-url
"$REMOTE_NAME" "$REMOTE_URL" >/dev
/null
2>&1 || git remote add
"$REMOTE_NAME" "$REMOTE_URL"
75 ###########################################
76 ## usage: do_svnify <repo-url> <existing-dir>
77 function do_svnify
() {
82 if [ -d "$TGT/.svn" ]; then
83 echo "[[Already checked out SVN repo ($TGT) -- skip $REPO]]"
86 [ -d $TGT ] || mkdir
-p "$TGT"
87 [ -d $TMP ] && rm -rf "$TMP"
88 echo "[[Checkout $REPO ($TMP)]]"
90 echo "[svn co \"$REPO\" \"$TGT\"]"
94 ###########################################
95 ## usage: do_gencode <civicrm-path>
96 function do_gencode
() {
97 pushd "$1/xml" > /dev
/null
98 if [ -f "GenCode.php" ]; then
99 echo "[[Generate files]]"
102 echo "[[Skip \"Generate files\"]]"
107 ###########################################
108 ## config_repo <repo-name> <local-path> <default-branch> <git-scripts-path>
110 function config_repo
() {
111 do_gitify
"${UPSTREAM_GIT_BASE_URL}/${1}.git" "$2" -b "$3"
112 do_hookify
"$1" "$2" "$4"
113 ## doesn't work with http -- git ls-remote "git://github.com/civicrm/civicrm-drupalz.git" HEAD --exit-code &>- ; echo $?
114 if [ -n "$FORK_GIT_BASE_URL" ]; then
115 git_set_remote
"$2" upstream
"${UPSTREAM_GIT_BASE_URL}/${1}.git"
116 git_set_remote
"$2" origin
"${FORK_GIT_BASE_URL}/${1}.git"
118 git_set_remote
"$2" origin
"${UPSTREAM_GIT_BASE_URL}/${1}.git"
122 function check_dep
() {
123 if [ -z "`which git`" ]; then
124 echo "command not found: git"
127 if [ -z `which php` ]; then
128 echo "command not found: php"
132 ###########################################
133 #### Main: Parse arguments
141 CIVICRM_BRANCH
="master"
143 UPSTREAM_GIT_BASE_URL
="https://github.com/civicrm"
145 while [ -n "$1" ]; do
146 if [ "$1" == "--l10n" ]; then
148 elif [ "$1" == "--hooks" ]; then
149 CIVICRM_GIT_HOOKS
="$1"
150 elif [ "$1" == "--upstream" ]; then
152 UPSTREAM_GIT_BASE_URL
="$1"
153 elif [ "$1" == "--fork" ]; then
155 FORK_GIT_BASE_URL
="$1"
156 elif [ -z "$CIVICRM_CMS" ]; then
159 elif [ -z "$CIVICRM_ROOT" ]; then
163 echo "unrecognized argument: $1"
169 if [ -z "$CIVICRM_ROOT" -o ! -d "$CIVICRM_ROOT" -o -z "$UPSTREAM_GIT_BASE_URL" -o -z "$CIVICRM_CMS" ]; then
170 echo "Convert a directory into a set of CiviCRM git clones"
171 echo "usage: $0 <Drupal|Drupal6|Joomla|WordPress|all> <existing-civicrm-root> [--fork <base-url>] [--upstream <base-url>] [--l10n] [--hooks]"
172 echo " <cms-name>: one of: Drupal|Drupal6|Joomla|WordPress|all"
173 echo " <git-base-url>: a base URL shared by the desiried git repos (e.g. git://github.com/civicrm)"
174 echo " <existing-civicrm-root>: the main directory containing CiviCRM"
175 echo " --upstream <base-url>: specify the base URL for upstream repositories"
176 echo " --fork <base-url>: specify the base URL for your personal fork repositories"
177 echo " --l10n: optionally fetch localization data; currently requires svn"
178 echo " --hooks: optionally install recommended git hooks; the hooks are mostly"
179 echo " tested with git CLI under Linux and OSX; they haven't been"
180 echo " tested with git GUIs or Windows"
182 echo "Note: If pointing to a pre-existing directory, your local changes may be replaced by"
183 echo "the pristine code from git/svn. If you've made changes, then make sure there's a backup!"
185 echo "example: $0 Drupal /var/www/drupal7/sites/all/modules/civicrm"
186 echo " (checkout core code plus Drupal 7.x integration code)"
188 echo "example: $0 Drupal6 /var/www/drupal6/sites/all/modules/civicrm"
189 echo " (checkout core code plus Drupal 6.x integration code)"
191 echo "example: $0 all ~/src/civicrm --upstream git@github.com:civicrm --l10n"
192 echo " (checkout core code plus Drupal 7.x, Joomla, and WordPress integration code and l10n using SSH)"
196 ###########################################
197 #### Main: Update git repo metadata ####
200 ## config_repo <repo-name> <local-path> <default-branch> <git-scripts-path>
201 config_repo civicrm-core
"$CIVICRM_ROOT" "$CIVICRM_BRANCH" "../tools/scripts/git"
202 config_repo civicrm-packages
"$CIVICRM_ROOT/packages" "$CIVICRM_BRANCH" "../../tools/scripts/git"
203 case "$CIVICRM_CMS" in
205 config_repo civicrm-drupal
"$CIVICRM_ROOT/drupal" "7.x-$CIVICRM_BRANCH" "../../tools/scripts/git"
208 config_repo civicrm-drupal
"$CIVICRM_ROOT/drupal" "6.x-$CIVICRM_BRANCH" "../../tools/scripts/git"
211 config_repo civicrm-joomla
"$CIVICRM_ROOT/joomla" "$CIVICRM_BRANCH" "../../tools/scripts/git"
214 config_repo civicrm-wordpress
"$CIVICRM_ROOT/WordPress" "$CIVICRM_BRANCH" "../../tools/scripts/git"
217 config_repo civicrm-drupal
"$CIVICRM_ROOT/drupal" "7.x-$CIVICRM_BRANCH" "../../tools/scripts/git"
218 config_repo civicrm-joomla
"$CIVICRM_ROOT/joomla" "$CIVICRM_BRANCH" "../../tools/scripts/git"
219 config_repo civicrm-wordpress
"$CIVICRM_ROOT/WordPress" "$CIVICRM_BRANCH" "../../tools/scripts/git"
222 echo "Unrecognized CMS: $CIVICRM_CMS"
225 if [ "$CIVICRM_L10N" == "--l10n" ]; then
226 do_svnify
"http://svn.civicrm.org/l10n/trunk" "$CIVICRM_ROOT/l10n"
229 do_gencode
"$CIVICRM_ROOT"