Commit | Line | Data |
---|---|---|
bed96570 TO |
1 | #!/bin/bash |
2 | ||
3 | ## Take an existing, tar-based CiviCRM directory and convert it to a git working directory | |
4 | ||
5 | #### Helpers #### | |
6 | ||
7 | ## usage: do_gitify <repo-url> <existing-dir> [git-checkout-options] | |
8 | function do_gitify() { | |
9 | REPO="$1" | |
10 | TGT="$2" | |
11 | TMP="${TGT}.tmp" | |
12 | shift 2 | |
13 | ||
14 | if [ -d "$TGT/.git" ]; then | |
15 | echo "[[Already checked out git repo ($TGT) -- skip $REPO]]" | |
16 | return | |
17 | fi | |
18 | [ -d $TGT ] || mkdir -p "$TGT" | |
19 | [ -d $TMP ] && rm -rf "$TMP" | |
20 | echo "[[Checkout $REPO ($TMP)]]" | |
21 | echo "[git clone "$@" "$REPO" "$TMP"]" | |
22 | git clone "$@" "$REPO" "$TMP" | |
23 | ||
24 | echo "[[Swap metadata]]" | |
25 | mv "$TMP/.git" "$TGT/.git" | |
26 | ||
27 | echo "[[Remove local modifications]]" | |
28 | pushd "$TGT" > /dev/null | |
29 | git checkout -- . | |
30 | popd > /dev/null | |
31 | ||
32 | rm -rf "$TMP" | |
33 | } | |
34 | ||
a32518b8 | 35 | ## add hook shims to a repo |
3e0f9f2e | 36 | ## usage: do_hookify <canonical-repo-name> <repo-path> <relative-hook-path> |
a32518b8 | 37 | function do_hookify() { |
3e0f9f2e TO |
38 | GIT_CANONICAL_REPO_NAME="$1" |
39 | TGT="$2" | |
40 | HOOK_DIR="$3" | |
a32518b8 TO |
41 | if [ -n "$CIVICRM_GIT_HOOKS" ]; then |
42 | echo "[[Install recommended hooks ($TGT)]]" | |
fb687a12 | 43 | for HOOK in commit-msg post-checkout post-merge pre-commit prepare-commit-msg post-commit pre-rebase post-rewrite ;do |
a32518b8 TO |
44 | cat << TMPL > "$TGT/.git/hooks/$HOOK" |
45 | #!/bin/bash | |
46 | if [ -f "\$GIT_DIR/${HOOK_DIR}/${HOOK}" ]; then | |
3e0f9f2e TO |
47 | ## Note: GIT_CANONICAL_REPO_NAME was not provided by early hook-stubs |
48 | export GIT_CANONICAL_REPO_NAME="$GIT_CANONICAL_REPO_NAME" | |
a32518b8 TO |
49 | source "\$GIT_DIR/${HOOK_DIR}/${HOOK}" |
50 | fi | |
51 | TMPL | |
52 | chmod +x "$TGT/.git/hooks/$HOOK" | |
53 | done | |
54 | else | |
55 | echo "[[Skip hook installation ($TGT) -- use \"--hooks\" to enable]]" | |
56 | fi | |
57 | } | |
58 | ||
bed96570 TO |
59 | ## usage: do_svnify <repo-url> <existing-dir> |
60 | function do_svnify() { | |
61 | REPO="$1" | |
62 | TGT="$2" | |
63 | shift 2 | |
64 | ||
65 | if [ -d "$TGT/.svn" ]; then | |
66 | echo "[[Already checked out SVN repo ($TGT) -- skip $REPO]]" | |
67 | return | |
68 | fi | |
69 | [ -d $TGT ] || mkdir -p "$TGT" | |
70 | [ -d $TMP ] && rm -rf "$TMP" | |
71 | echo "[[Checkout $REPO ($TMP)]]" | |
72 | ||
73 | echo "[svn co \"$REPO\" \"$TGT\"]" | |
74 | svn co "$REPO" "$TGT" | |
75 | } | |
76 | ||
77 | function check_dep() { | |
a32518b8 | 78 | if [ -z "`which git`" ]; then |
bed96570 | 79 | echo "command not found: git" |
a32518b8 | 80 | exit 3 |
bed96570 | 81 | fi |
e29a638a TO |
82 | if [ -z `which php` ]; then |
83 | echo "command not found: php" | |
84 | fi | |
bed96570 TO |
85 | } |
86 | ||
87 | #### Main #### | |
88 | ||
89 | set -e | |
90 | ||
a32518b8 TO |
91 | CIVICRM_CMS="" |
92 | GIT_BASE_URL="" | |
93 | CIVICRM_ROOT="" | |
94 | CIVICRM_L10N="" | |
95 | CIVICRM_GIT_HOOKS="" | |
bed96570 | 96 | CIVICRM_BRANCH="master" |
a32518b8 TO |
97 | |
98 | while [ -n "$1" ]; do | |
99 | if [ "$1" == "--l10n" ]; then | |
100 | CIVICRM_L10N="$1" | |
101 | elif [ "$1" == "--hooks" ]; then | |
102 | CIVICRM_GIT_HOOKS="$1" | |
103 | elif [ -z "$CIVICRM_CMS" ]; then | |
104 | ## First arg | |
105 | CIVICRM_CMS="$1" | |
106 | elif [ -z "$GIT_BASE_URL" ]; then | |
107 | ## Second arg | |
108 | GIT_BASE_URL="$1" | |
109 | elif [ -z "$CIVICRM_ROOT" ]; then | |
110 | ## Third arg | |
111 | CIVICRM_ROOT="$1" | |
112 | else | |
113 | echo "unrecognized argument: $1" | |
114 | exit 2 | |
115 | fi | |
116 | shift | |
117 | done | |
118 | ||
bed96570 TO |
119 | if [ -z "$CIVICRM_ROOT" -o ! -d "$CIVICRM_ROOT" -o -z "$GIT_BASE_URL" -o -z "$CIVICRM_CMS" ]; then |
120 | echo "Convert a directory into a set of CiviCRM git clones" | |
a32518b8 | 121 | echo "usage: $0 <Drupal|Drupal6|Joomla|WordPress|all> <git-base-url> <existing-civicrm-root> [--l10n] [--hooks]" |
bed96570 TO |
122 | echo " <cms-name>: one of: Drupal|Drupal6|Joomla|WordPress|all" |
123 | echo " <git-base-url>: a base URL shared by the desiried git repos (e.g. git://github.com/civicrm)" | |
124 | echo " <existing-civicrm-root>: the main directory containing CiviCRM" | |
a32518b8 TO |
125 | echo " --l10n: optionally fetch localization data; currently requires svn" |
126 | echo " --hooks: optionally install recommended git hooks; the hooks are mostly" | |
127 | echo " tested with git CLI under Linux and OSX; they haven't been" | |
128 | echo " tested with git GUIs or Windows" | |
bed96570 TO |
129 | echo "" |
130 | echo "Note: If pointing to a pre-existing directory, your local changes may be replaced by" | |
131 | echo "the pristine code from git/svn. If you've made changes, then make sure there's a backup!" | |
132 | echo "" | |
591a8a6b | 133 | echo "example: $0 Drupal git://github.com/civicrm /var/www/drupal7/sites/all/modules/civicrm" |
bed96570 TO |
134 | echo " (checkout core code plus Drupal 7.x integration code using Git's read-only protocol)" |
135 | echo "" | |
591a8a6b | 136 | echo "example: $0 Drupal6 https://github.com/civicrm /var/www/drupal6/sites/all/modules/civicrm" |
bed96570 TO |
137 | echo " (checkout core code plus Drupal 6.x integration code using read-only HTTP protocol)" |
138 | echo "" | |
591a8a6b | 139 | echo "example: $0 all git@github.com:civicrm ~/src/civicrm l10n" |
bed96570 TO |
140 | echo " (checkout core code plus Drupal 7.x, Joomla, and WordPress integration code and l10n using SSH)" |
141 | exit 1 | |
142 | fi | |
143 | ||
144 | check_dep | |
145 | do_gitify "${GIT_BASE_URL}/civicrm-core.git" "$CIVICRM_ROOT" -b "${CIVICRM_BRANCH}" | |
3e0f9f2e | 146 | do_hookify civicrm-core "$CIVICRM_ROOT" "../tools/scripts/git" |
bed96570 | 147 | do_gitify "${GIT_BASE_URL}/civicrm-packages.git" "$CIVICRM_ROOT/packages" -b "${CIVICRM_BRANCH}" |
3e0f9f2e | 148 | do_hookify civicrm-packages "$CIVICRM_ROOT/packages" "../../tools/scripts/git" |
bed96570 TO |
149 | case "$CIVICRM_CMS" in |
150 | Drupal) | |
0221d828 | 151 | do_gitify "${GIT_BASE_URL}/civicrm-drupal.git" "$CIVICRM_ROOT/drupal" -b "7.x-${CIVICRM_BRANCH}" |
3e0f9f2e | 152 | do_hookify civicrm-drupal "$CIVICRM_ROOT/drupal" "../../tools/scripts/git" |
bed96570 TO |
153 | ;; |
154 | Drupal6) | |
0221d828 | 155 | do_gitify "${GIT_BASE_URL}/civicrm-drupal.git" "$CIVICRM_ROOT/drupal" -b "6.x-${CIVICRM_BRANCH}" |
3e0f9f2e | 156 | do_hookify civicrm-drupal "$CIVICRM_ROOT/drupal" "../../tools/scripts/git" |
bed96570 TO |
157 | ;; |
158 | Joomla) | |
159 | do_gitify "${GIT_BASE_URL}/civicrm-joomla.git" "$CIVICRM_ROOT/joomla" -b "${CIVICRM_BRANCH}" | |
3e0f9f2e | 160 | do_hookify civicrm-joomla "$CIVICRM_ROOT/joomla" "../../tools/scripts/git" |
bed96570 TO |
161 | ;; |
162 | WordPress) | |
163 | do_gitify "${GIT_BASE_URL}/civicrm-wordpress.git" "$CIVICRM_ROOT/WordPress" -b "${CIVICRM_BRANCH}" | |
3e0f9f2e | 164 | do_hookify civicrm-wordpress "$CIVICRM_ROOT/WordPress" "../../tools/scripts/git" |
bed96570 TO |
165 | ;; |
166 | all) | |
0221d828 | 167 | do_gitify "${GIT_BASE_URL}/civicrm-drupal.git" "$CIVICRM_ROOT/drupal" -b "7.x-${CIVICRM_BRANCH}" |
3e0f9f2e | 168 | do_hookify civicrm-drupal "$CIVICRM_ROOT/drupal" "../../tools/scripts/git" |
bed96570 | 169 | do_gitify "${GIT_BASE_URL}/civicrm-joomla.git" "$CIVICRM_ROOT/joomla" -b "${CIVICRM_BRANCH}" |
3e0f9f2e | 170 | do_hookify civicrm-joomla "$CIVICRM_ROOT/joomla" "../../tools/scripts/git" |
bed96570 | 171 | do_gitify "${GIT_BASE_URL}/civicrm-wordpress.git" "$CIVICRM_ROOT/WordPress" -b "${CIVICRM_BRANCH}" |
3e0f9f2e | 172 | do_hookify civicrm-wordpress "$CIVICRM_ROOT/WordPress" "../../tools/scripts/git" |
bed96570 TO |
173 | ;; |
174 | *) | |
175 | echo "Unrecognized CMS: $CIVICRM_CMS" | |
176 | esac | |
177 | ||
178 | if [ "$CIVICRM_L10N" == "--l10n" ]; then | |
179 | do_svnify "http://svn.civicrm.org/l10n/trunk" "$CIVICRM_ROOT/l10n" | |
180 | fi | |
e29a638a TO |
181 | |
182 | pushd "$CIVICRM_ROOT/xml" > /dev/null | |
183 | if [ -f "GenCode.php" ]; then | |
184 | echo "[[Generate files]]" | |
185 | php GenCode.php | |
186 | else | |
187 | echo "[[Skip \"Generate files\"]]" | |
188 | fi | |
189 | popd > /dev/null |