@@ -15,6 +15,7 @@ git subsplit update
1515--
1616h,help show the help
1717q quiet
18+ debug show plenty of debug output
1819n,dry-run do everything except actually send the updates
1920work-dir directory that contains the subsplit working directory
2021
@@ -30,6 +31,7 @@ eval "$(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)"
3031
3132# We can run this from anywhere.
3233NONGIT_OK=1
34+ DEBUG=" :DEBUG >"
3335
3436PATH=$PATH :$( git --exec-path)
3537
@@ -47,9 +49,12 @@ SPLITS=
4749REPO_URL=
4850WORK_DIR=" ${PWD} /.subsplit"
4951HEADS=
52+ NO_HEADS=
5053TAGS=
54+ NO_TAGS=
5155REBUILD_TAGS=
5256DRY_RUN=
57+ VERBOSE=
5358
5459subsplit_main ()
5560{
@@ -58,6 +63,7 @@ subsplit_main()
5863 shift
5964 case " $opt " in
6065 -q) QUIET=1 ;;
66+ --debug) VERBOSE=1 ;;
6167 --heads) HEADS=" $1 " ; shift ;;
6268 --no-heads) NO_HEADS=1 ;;
6369 --tags) TAGS=" $1 " ; shift ;;
@@ -95,7 +101,8 @@ subsplit_main()
95101}
96102say ()
97103{
98- if [ -z " $QUIET " ]; then
104+ if [ -z " $QUIET " ];
105+ then
99106 echo " $@ " >&2
100107 fi
101108}
@@ -107,6 +114,11 @@ subsplit_require_work_dir()
107114 die " Working directory not found at ${WORK_DIR} ; please run init first"
108115 fi
109116
117+ if [ -n " $VERBOSE " ];
118+ then
119+ echo " ${DEBUG} pushd \" ${WORK_DIR} \" >/dev/null"
120+ fi
121+
110122 pushd " $WORK_DIR " > /dev/null
111123}
112124
@@ -119,6 +131,11 @@ subsplit_init()
119131
120132 say " Initializing subsplit from origin (${REPO_URL} )"
121133
134+ if [ -n " $VERBOSE " ];
135+ then
136+ echo " ${DEBUG} git clone -q \" ${REPO_URL} \" \" ${WORK_DIR} \" "
137+ fi
138+
122139 git clone -q " $REPO_URL " " $WORK_DIR " || die " Could not clone repository"
123140}
124141
@@ -135,12 +152,22 @@ subsplit_publish()
135152 then
136153 # If heads are not specified and we want heads, discover them.
137154 HEADS=" $( git ls-remote origin 2> /dev/null | grep " refs/heads/" | cut -f3- -d/) "
155+
156+ if [ -n " $VERBOSE " ];
157+ then
158+ echo " ${DEBUG} HEADS=\" ${HEADS} \" "
159+ fi
138160 fi
139161
140162 if [ -z " $TAGS " ] && [ -z " $NO_TAGS " ]
141163 then
142164 # If tags are not specified and we want tags, discover them.
143165 TAGS=" $( git ls-remote origin 2> /dev/null | grep -v " \^{}" | grep " refs/tags/" | cut -f3 -d/) "
166+
167+ if [ -n " $VERBOSE " ];
168+ then
169+ echo " ${DEBUG} TAGS=\" ${TAGS} \" "
170+ fi
144171 fi
145172
146173 for SPLIT in $SPLITS
@@ -149,28 +176,64 @@ subsplit_publish()
149176 REMOTE_URL=$( echo " $SPLIT " | cut -f2- -d:)
150177 REMOTE_NAME=$( echo " $SPLIT " | git hash-object --stdin)
151178
179+ if [ -n " $VERBOSE " ];
180+ then
181+ echo " ${DEBUG} SUBPATH=${SUBPATH} "
182+ echo " ${DEBUG} REMOTE_URL=${REMOTE_URL} "
183+ echo " ${DEBUG} REMOTE_NAME=${REMOTE_NAME} "
184+ fi
185+
152186 if ! git remote | grep " ^${REMOTE_NAME} $" > /dev/null
153187 then
154188 git remote add " $REMOTE_NAME " " $REMOTE_URL "
189+
190+ if [ -n " $VERBOSE " ];
191+ then
192+ echo " ${DEBUG} git remote add \" ${REMOTE_NAME} \" \" ${REMOTE_URL} \" "
193+ fi
155194 fi
156195
157196
158197 say " Syncing ${SUBPATH} -> ${REMOTE_URL} "
159198
160199 for HEAD in $HEADS
161200 do
201+ if [ -n " $VERBOSE " ];
202+ then
203+ echo " ${DEBUG} git show-ref --quiet --verify -- \" refs/remotes/origin/${HEAD} \" "
204+ fi
205+
162206 if ! git show-ref --quiet --verify -- " refs/remotes/origin/${HEAD} "
163207 then
164208 say " - skipping head '${HEAD} ' (does not exist)"
165209 continue
166210 fi
167211 LOCAL_BRANCH=" ${REMOTE_NAME} -branch-${HEAD} "
212+
213+ if [ -n " $VERBOSE " ];
214+ then
215+ echo " ${DEBUG} LOCAL_BRANCH=\" ${LOCAL_BRANCH} \" "
216+ fi
217+
168218 say " - syncing branch '${HEAD} '"
169219 git branch -D " $LOCAL_BRANCH " > /dev/null 2>&1
170220 git subtree split -q --prefix=" $SUBPATH " --branch=" $LOCAL_BRANCH " " origin/${HEAD} " > /dev/null
221+
222+ if [ -n " $VERBOSE " ];
223+ then
224+ echo " ${DEBUG} git branch -D \" $LOCAL_BRANCH \" >/dev/null 2>&1"
225+ echo " ${DEBUG} git subtree split -q --prefix=\" $SUBPATH \" --branch=\" $LOCAL_BRANCH \" \" origin/${HEAD} \" >/dev/null"
226+ fi
227+
171228 if [ $? -eq 0 ]
172229 then
173230 PUSH_CMD=" git push -q ${DRY_RUN} --force $REMOTE_NAME ${LOCAL_BRANCH} :${HEAD} "
231+
232+ if [ -n " $VERBOSE " ];
233+ then
234+ echo " ${DEBUG} $PUSH_CMD "
235+ fi
236+
174237 if [ -n " $DRY_RUN " ]
175238 then
176239 echo \# $PUSH_CMD
@@ -183,26 +246,61 @@ subsplit_publish()
183246
184247 for TAG in $TAGS
185248 do
249+ if [ -n " $VERBOSE " ];
250+ then
251+ echo " ${DEBUG} git show-ref --quiet --verify -- \" refs/tags/${TAG} \" "
252+ fi
253+
186254 if ! git show-ref --quiet --verify -- " refs/tags/${TAG} "
187255 then
188256 say " - skipping tag '${TAG} ' (does not exist)"
189257 continue
190258 fi
191259 LOCAL_TAG=" ${REMOTE_NAME} -tag-${TAG} "
260+
261+ if [ -n " $VERBOSE " ];
262+ then
263+ echo " ${DEBUG} LOCAL_TAG=" ${LOCAL_TAG} " "
264+ fi
265+
192266 if git branch | grep " ${LOCAL_TAG} $" > /dev/null && [ -z " $REBUILD_TAGS " ]
193267 then
194268 say " - skipping tag '${TAG} ' (already synced)"
195269 continue
196270 fi
271+
272+ if [ -n " $VERBOSE " ];
273+ then
274+ echo " ${DEBUG} git branch | grep \" ${LOCAL_TAG} $\" >/dev/null && [ -z \" ${REBUILD_TAGS} \" ]"
275+ fi
276+
197277 say " - syncing tag '${TAG} '"
198278 say " - deleting '${LOCAL_TAG} '"
199279 git branch -D " $LOCAL_TAG " > /dev/null 2>&1
280+
281+ if [ -n " $VERBOSE " ];
282+ then
283+ echo " ${DEBUG} git branch -D \" ${LOCAL_TAG} \" >/dev/null 2>&1"
284+ fi
285+
200286 say " - subtree split for '${TAG} '"
201287 git subtree split -q --annotate=" ${ANNOTATE} " --prefix=" $SUBPATH " --branch=" $LOCAL_TAG " " $TAG " > /dev/null
288+
289+ if [ -n " $VERBOSE " ];
290+ then
291+ echo " ${DEBUG} git subtree split -q --annotate=\" ${ANNOTATE} \" --prefix=\" $SUBPATH \" --branch=\" $LOCAL_TAG \" \" $TAG \" >/dev/null"
292+ fi
293+
202294 say " - subtree split for '${TAG} ' [DONE]"
203295 if [ $? -eq 0 ]
204296 then
205297 PUSH_CMD=" git push -q ${DRY_RUN} --force ${REMOTE_NAME} ${LOCAL_TAG} :refs/tags/${TAG} "
298+
299+ if [ -n " $VERBOSE " ];
300+ then
301+ echo " ${DEBUG} PUSH_CMD=\" ${PUSH_CMD} \" "
302+ fi
303+
206304 if [ -n " $DRY_RUN " ]
207305 then
208306 echo \# $PUSH_CMD
@@ -226,6 +324,12 @@ subsplit_update()
226324 git fetch -q origin
227325 git fetch -q -t origin
228326
327+ if [ -n " $VERBOSE " ];
328+ then
329+ echo " ${DEBUG} git fetch -q origin"
330+ echo " ${DEBUG} git fetch -q -t origin"
331+ fi
332+
229333 popd > /dev/null
230334}
231335
0 commit comments