@@ -28,6 +28,15 @@ requirements_check() {
28
28
# Prepare some essential configurations for the script.
29
29
# We read them from the current shell environment.
30
30
git_xy_env () {
31
+ GIT_XY_ENV_FILE=" ${GIT_XY_ENV_FILE:- git_xy.env} "
32
+ export GIT_XY_ENV_FILE
33
+ readonly GIT_XY_ENV_FILE
34
+
35
+ if [[ -f " ${GIT_XY_ENV_FILE} " ]]; then
36
+ log " INFO: Loading external configuration file: '$GIT_XY_ENV_FILE '"
37
+ source " $GIT_XY_ENV_FILE " || return
38
+ fi
39
+
31
40
GIT_XY_CONFIG=" ${GIT_XY_CONFIG:- git_xy.config} "
32
41
D_GIT_SYNC=" $HOME /.local/share/git_xy/"
33
42
GIT_XY_HOOKS=" ${GIT_XY_HOOKS-gh} "
@@ -107,6 +116,29 @@ git_pull() {
107
116
)
108
117
}
109
118
119
+ __pr_commit_message () {
120
+ cat << EOF
121
+ git_xy:
122
+ version: ${GIT_XY_VERSION}
123
+ src:
124
+ repo : $src_repo
125
+ branch : $src_branch
126
+ path : $o_src_path
127
+ commit : $src_commit_hash
128
+ subject : $src_commit_subject
129
+ dst:
130
+ repo : $dst_repo
131
+ branch : $dst_branch
132
+ path : $o_dst_path
133
+ commit : $dst_commit_hash
134
+ options:
135
+ rsync :
136
+ options: $rsync_opts
137
+ def: |
138
+ $( declare -f git_xy_rsync | awk ' {printf(" %s\n",$0)}' )
139
+ EOF
140
+ }
141
+
110
142
# Generate a Github pull request
111
143
# Will return 0 if there is an existing branch and/or
112
144
# there is not commits between two branches.
@@ -141,21 +173,7 @@ __hook_gh() {
141
173
--base " $dst_branch " \
142
174
--title " git_xy/sync from $src_repo ref=$src_branch path=$src_path " \
143
175
--body " \`\`\`
144
- git_xy:
145
- version: ${GIT_XY_VERSION}
146
- src:
147
- repo : $src_repo
148
- branch : $src_branch
149
- path : $o_src_path
150
- commit : $src_commit_hash
151
- subject : $src_commit_subject
152
- dst:
153
- repo : $dst_repo
154
- branch : $dst_branch
155
- path : $o_dst_path
156
- commit : $dst_commit_hash
157
- options:
158
- rsync : $rsync_opts
176
+ $( __pr_commit_message)
159
177
\`\`\` " \
160
178
| awk '
161
179
BEGIN{
@@ -202,21 +220,7 @@ __dst_commit_changes_if_any() {
202
220
git commit -a -m" git_xy/$src_repo branch $src_branch path $src_path
203
221
204
222
\`\`\`
205
- git_xy:
206
- version: ${GIT_XY_VERSION}
207
- src:
208
- repo : $src_repo
209
- branch : $src_branch
210
- path : $o_src_path
211
- commit : $src_commit_hash
212
- subject : $src_commit_subject
213
- dst:
214
- repo : $dst_repo
215
- branch : $dst_branch
216
- path : $o_dst_path
217
- commit : $dst_commit_hash
218
- options:
219
- rsync : $rsync_opts
223
+ $( __pr_commit_message)
220
224
\`\`\`
221
225
"
222
226
# shellcheck disable=SC2086
@@ -246,6 +250,11 @@ __last_error() {
246
250
last_error=" "
247
251
}
248
252
253
+ # A simple wrapper for rsync.
254
+ git_xy_rsync () {
255
+ rsync " ${@ } "
256
+ }
257
+
249
258
# The main program
250
259
git_xy () {
251
260
n_config=0
@@ -375,7 +384,7 @@ git_xy() {
375
384
# FIXED: as we may want to grab some configuration file (rsync_opts)
376
385
# FIXME: Better quoting handle for `rsync_opts`
377
386
# shellcheck disable=SC2086
378
- rsync -rap \
387
+ git_xy_rsync -rap \
379
388
$rsync_opts \
380
389
--exclude=" .git/*" \
381
390
" $src_local_full_path /$src_path " \
@@ -415,7 +424,7 @@ main() {
415
424
&& git_xy
416
425
}
417
426
418
- GIT_XY_VERSION=" 1.0 .0"
427
+ GIT_XY_VERSION=" 1.2 .0"
419
428
export GIT_XY_VERSION
420
429
421
430
declare -A GIT_XY_ERRORS
0 commit comments