3 # these are helper functions for doing localized revision control.
4 # this script should be sourced into other scripts that use it.
6 source "$FEISTY_MEOW_SCRIPTS/core/launch_feisty_meow.sh"
7 source "$FEISTY_MEOW_SCRIPTS/tty/terminal_titler.sh"
9 #hmmm: we need to dump all the outputs in this script into splitter
13 # the maximum depth that the recursive functions will try to go below the starting directory.
16 # use our splitter tool for lengthy output if it's available.
17 if [ ! -z "$(which splitter)" ]; then
18 TO_SPLITTER="$(which splitter)"
25 # one unpleasantry to take care of first; cygwin barfs aggressively if the TMP directory
26 # is a DOS path, but we need it to be a DOS path for our GFFS testing, so that blows.
27 # to get past this, TMP gets changed below to a hopefully generic and safe place.
28 if [[ "$TMP" =~ .:.* ]]; then
29 echo "making weirdo temporary directory for PCDOS-style path."
30 export TMP=/tmp/rev_control_$USER
32 if [ ! -d "$TMP" ]; then
35 if [ ! -d "$TMP" ]; then
36 echo "could not create the temporary directory TMP in: $TMP"
37 echo "this script will not work properly without an existing TMP directory."
39 #hmmm: re-address the above code, since it doesn't make a lot of sense to me right now...
44 # checks the directory provided into the revision control system repository it belongs to.
47 local directory="$1"; shift
51 # make a nice echoer since we want to use it inside conditions below.
52 local nicedir="$directory"
53 if [ $nicedir == "." ]; then
56 local blatt="echo checking in '$nicedir'..."
58 local retval=0 # normally successful.
60 do_update "$directory"
62 test_or_die "repository update failed; this should be fixed before check-in."
64 pushd "$directory" &>/dev/null
65 if [ -f ".no-checkin" ]; then
66 echo "skipping check-in due to presence of .no-checkin sentinel file."
67 elif [ -d "CVS" ]; then
68 if test_writeable "CVS"; then
73 elif [ -d ".svn" ]; then
74 if test_writeable ".svn"; then
79 elif [ -d ".git" ]; then
80 if test_writeable ".git"; then
82 # snag all new files. not to everyone's liking.
86 # see if there are any changes in the local repository.
87 if ! git diff-index --quiet HEAD --; then
88 # tell git about all the files and get a check-in comment.
92 # catch if the diff-index failed somehow.
95 local myself="$(my_branch_name)"
96 local parent="$(parent_branch_name)"
98 # upload any changes to the upstream repo so others can see them.
99 if [ "$myself" != "$parent" ]; then
100 git push origin "$(myself)" 2>&1 | grep -v "X11 forwarding request failed" | $TO_SPLITTER
101 retval+=${PIPESTATUS[0]}
103 # this branch is the same as the parent, so just push.
104 git push 2>&1 | grep -v "X11 forwarding request failed" | $TO_SPLITTER
105 retval+=${PIPESTATUS[0]}
110 # nothing there. it's not an error though.
111 echo no repository in $directory
116 restore_terminal_title
121 # shows the local changes in a repository.
124 local directory="$1"; shift
128 pushd "$directory" &>/dev/null
129 local retval=0 # normally successful.
131 # only update if we see a repository living there.
132 if [ -d ".svn" ]; then
135 elif [ -d ".git" ]; then
138 elif [ -d "CVS" ]; then
145 restore_terminal_title
150 # reports any files that are not already known to the upstream repository.
151 function do_report_new
153 local directory="$1"; shift
157 pushd "$directory" &>/dev/null
158 local retval=0 # normally successful.
160 # only update if we see a repository living there.
161 if [ -f ".no-checkin" ]; then
162 echo "skipping reporting due to presence of .no-checkin sentinel file."
163 elif [ -d ".svn" ]; then
164 # this action so far only makes sense and is needed for svn.
165 bash $FEISTY_MEOW_SCRIPTS/rev_control/svnapply.sh \? echo
167 elif [ -d ".git" ]; then
174 restore_terminal_title
179 # checks in all the folders in a specified list.
180 function checkin_list()
182 # make the list of directories unique.
183 local list="$(uniquify $*)"
187 # turn repo list back into an array.
188 eval "repository_list=( ${REPOSITORY_LIST[*]} )"
192 for outer in "${repository_list[@]}"; do
193 # check the repository first, since it might be an absolute path.
194 if [[ $outer =~ /.* ]]; then
195 # yep, this path is absolute. just handle it directly.
196 if [ ! -d "$outer" ]; then continue; fi
198 test_or_die "running check-in on: $outer"
201 for inner in $list; do
202 # add in the directory component to see if we can find the folder.
203 local path="$inner/$outer"
204 if [ ! -d "$path" ]; then continue; fi
206 test_or_die "running check-in on: $path"
212 restore_terminal_title
215 # takes out the first few carriage returns that are in the input.
216 function squash_first_few_crs()
219 while read input_text; do
221 if [ $i -le 5 ]; then
222 echo -n "$input_text "
227 if [ $i -le 3 ]; then
228 # if we're still squashing eols, make sure we don't leave them hanging.
233 # a helpful method that reports the git branch for the current directory's
235 function my_branch_name()
237 echo "$(git branch | grep \* | cut -d ' ' -f2)"
240 # this reports the upstream branch for the current repo.
241 function parent_branch_name()
243 echo "$(git branch -vv | grep \* | cut -d ' ' -f2)"
246 # gets the latest versions of the assets from the upstream repository.
249 directory="$1"; shift
253 # make a nice echoer since we want to use it inside conditions below.
254 local nicedir="$directory"
255 if [ $nicedir == "." ]; then
258 local blatt="echo retrieving '$nicedir'..."
260 local retval=0 # plan on success for now.
261 pushd "$directory" &>/dev/null
262 if [ -d "CVS" ]; then
263 if test_writeable "CVS"; then
265 cvs update . | squash_first_few_crs
266 retval=${PIPESTATUS[0]}
268 elif [ -d ".svn" ]; then
269 if test_writeable ".svn"; then
271 svn update . | squash_first_few_crs
272 retval=${PIPESTATUS[0]}
274 elif [ -d ".git" ]; then
275 if test_writeable ".git"; then
279 # from very helpful page:
280 # https://stackoverflow.com/questions/10312521/how-to-fetch-all-git-branches
281 git branch -r | grep -v '\->' |
282 while read remote; do
283 git branch --track "${remote#origin/}" "$remote"
284 # ensure we notice a failure when adding tracking.
287 retval+=${PIPESTATUS[0]}$?
289 git fetch --all 2>&1 | grep -v "X11 forwarding request failed" | $TO_SPLITTER
290 retval+=${PIPESTATUS[0]}
292 git pull --all 2>&1 | grep -v "X11 forwarding request failed" | $TO_SPLITTER
293 retval+=${PIPESTATUS[0]}
296 # this is not an error necessarily; we'll just pretend they planned this.
297 echo no repository in $directory
301 restore_terminal_title
306 # gets all the updates for a list of folders under revision control.
307 function checkout_list()
309 local list="$(uniquify $*)"
313 # turn repo list back into an array.
314 eval "repository_list=( ${REPOSITORY_LIST[*]} )"
318 for outer in "${repository_list[@]}"; do
319 # check the repository first, since it might be an absolute path.
320 if [[ $outer =~ /.* ]]; then
321 # yep, this path is absolute. just handle it directly.
322 if [ ! -d "$outer" ]; then continue; fi
324 test_or_die "running update on: $path"
327 for inner in $list; do
328 # add in the directory component to see if we can find the folder.
329 local path="$inner/$outer"
330 if [ ! -d "$path" ]; then continue; fi
332 test_or_die "running update on: $path"
338 restore_terminal_title
341 # provides a list of absolute paths of revision control directories
342 # that are located under the directory passed as the first parameter.
343 function generate_rev_ctrl_filelist()
345 local dir="$1"; shift
346 pushd "$dir" &>/dev/null
347 local dirhere="$( \cd "$(\dirname "$dir")" && /bin/pwd )"
348 local tempfile=$(mktemp /tmp/zz_checkins.XXXXXX)
350 local additional_filter
351 find $dirhere -follow -maxdepth $MAX_DEPTH -type d -iname ".svn" -exec echo {}/.. ';' >>$tempfile 2>/dev/null
352 find $dirhere -follow -maxdepth $MAX_DEPTH -type d -iname ".git" -exec echo {}/.. ';' >>$tempfile 2>/dev/null
353 # CVS is not well behaved like git and (now) svn, and we seldom use it anymore.
356 # see if they've warned us not to try checking in within vendor hierarchies.
357 if [ ! -z "NO_CHECKIN_VENDOR" ]; then
358 sed -i -e '/.*\/vendor\/.*/d' "$tempfile"
361 local sortfile=$(mktemp /tmp/zz_checkin_sort.XXXXXX)
362 sort <"$tempfile" >"$sortfile"
367 # iterates across a list of directories contained in a file (first parameter).
368 # on each directory name, it performs the action (second parameter) provided.
369 function perform_revctrl_action_on_file()
371 local tempfile="$1"; shift
372 local action="$1"; shift
376 while read -u 3 dirname; do
377 if [ -z "$dirname" ]; then continue; fi
378 pushd "$dirname" &>/dev/null
381 test_or_die "performing action $action on: $(pwd)"
386 restore_terminal_title