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"
11 # the maximum depth that the recursive functions will try to go below the starting directory.
14 # one unpleasantry to take care of first; cygwin barfs aggressively if the TMP directory
15 # is a DOS path, but we need it to be a DOS path for our GFFS testing, so that blows.
16 # to get past this, TMP gets changed below to a hopefully generic and safe place.
17 if [[ "$TMP" =~ .:.* ]]; then
18 echo "making weirdo temporary directory for PCDOS-style path."
19 export TMP=/tmp/rev_control_$USER
21 if [ ! -d "$TMP" ]; then
24 if [ ! -d "$TMP" ]; then
25 echo "could not create the temporary directory TMP in: $TMP"
26 echo "this script will not work properly without an existing TMP directory."
28 #hmmm: re-address the above code, since it doesn't make a lot of sense to me right now...
33 # checks the directory provided into the revision control system repository it belongs to.
36 local directory="$1"; shift
40 # make a nice echoer since we want to use it inside conditions below.
41 local nicedir="$directory"
42 if [ $nicedir == "." ]; then
45 local blatt="echo checking in '$nicedir'..."
47 local retval=0 # normally successful.
49 do_update "$directory"
51 test_or_die "repository update failed; this should be fixed before check-in."
53 pushd "$directory" &>/dev/null
54 if [ -f ".no-checkin" ]; then
55 echo "skipping check-in due to presence of .no-checkin sentinel file."
56 elif [ -d "CVS" ]; then
57 if test_writeable "CVS"; then
62 elif [ -d ".svn" ]; then
63 if test_writeable ".svn"; then
68 elif [ -d ".git" ]; then
69 if test_writeable ".git"; then
71 # snag all new files. not to everyone's liking.
75 # see if there are any changes in the local repository.
76 if ! git diff-index --quiet HEAD --; then
77 # tell git about all the files and get a check-in comment.
81 # catch if the diff-index failed somehow.
84 #push the changes to where? locally?
85 git push 2>&1 | grep -v "X11 forwarding request failed" | squash_first_few_crs
86 retval+=${PIPESTATUS[0]}
88 # upload any changes to the upstream repo so others can see them.
89 if [ "$(git_branch_name)" != "master" ]; then
90 git push origin "$(git_branch_name)" 2>&1 | grep -v "X11 forwarding request failed" | squash_first_few_crs
91 retval+=${PIPESTATUS[0]}
96 # nothing there. it's not an error though.
97 echo no repository in $directory
102 restore_terminal_title
107 # shows the local changes in a repository.
110 local directory="$1"; shift
114 pushd "$directory" &>/dev/null
115 local retval=0 # normally successful.
117 # only update if we see a repository living there.
118 if [ -d ".svn" ]; then
121 elif [ -d ".git" ]; then
124 elif [ -d "CVS" ]; then
131 restore_terminal_title
136 # reports any files that are not already known to the upstream repository.
137 function do_report_new
139 local directory="$1"; shift
143 pushd "$directory" &>/dev/null
144 local retval=0 # normally successful.
146 # only update if we see a repository living there.
147 if [ -f ".no-checkin" ]; then
148 echo "skipping reporting due to presence of .no-checkin sentinel file."
149 elif [ -d ".svn" ]; then
150 # this action so far only makes sense and is needed for svn.
151 bash $FEISTY_MEOW_SCRIPTS/rev_control/svnapply.sh \? echo
153 elif [ -d ".git" ]; then
160 restore_terminal_title
165 # checks in all the folders in a specified list.
166 function checkin_list()
168 # make the list of directories unique.
169 local list="$(uniquify $*)"
173 # turn repo list back into an array.
174 eval "repository_list=( ${REPOSITORY_LIST[*]} )"
178 for outer in "${repository_list[@]}"; do
179 # check the repository first, since it might be an absolute path.
180 if [[ $outer =~ /.* ]]; then
181 # yep, this path is absolute. just handle it directly.
182 if [ ! -d "$outer" ]; then continue; fi
184 test_or_die "running check-in on: $outer"
187 for inner in $list; do
188 # add in the directory component to see if we can find the folder.
189 local path="$inner/$outer"
190 if [ ! -d "$path" ]; then continue; fi
192 test_or_die "running check-in on: $path"
198 restore_terminal_title
201 # takes out the first few carriage returns that are in the input.
202 function squash_first_few_crs()
205 while read input_text; do
207 if [ $i -le 5 ]; then
208 echo -n "$input_text "
213 if [ $i -le 3 ]; then
214 # if we're still squashing eols, make sure we don't leave them hanging.
219 # a helpful method that reports the git branch for the current directory's
221 function git_branch_name()
223 echo "$(git branch | grep \* | cut -d ' ' -f2-)"
226 # gets the latest versions of the assets from the upstream repository.
229 directory="$1"; shift
233 # make a nice echoer since we want to use it inside conditions below.
234 local nicedir="$directory"
235 if [ $nicedir == "." ]; then
238 local blatt="echo retrieving '$nicedir'..."
240 local retval=0 # plan on success for now.
241 pushd "$directory" &>/dev/null
242 if [ -d "CVS" ]; then
243 if test_writeable "CVS"; then
245 cvs update . | squash_first_few_crs
246 retval=${PIPESTATUS[0]}
248 elif [ -d ".svn" ]; then
249 if test_writeable ".svn"; then
251 svn update . | squash_first_few_crs
252 retval=${PIPESTATUS[0]}
254 elif [ -d ".git" ]; then
255 if test_writeable ".git"; then
259 if [ "$(git_branch_name)" != "master" ]; then
260 git pull origin master 2>&1 | grep -v "X11 forwarding request failed" | squash_first_few_crs
261 retval+=${PIPESTATUS[0]}
264 git pull 2>&1 | grep -v "X11 forwarding request failed" | squash_first_few_crs
265 retval+=${PIPESTATUS[0]}
268 # this is not an error necessarily; we'll just pretend they planned this.
269 echo no repository in $directory
273 restore_terminal_title
278 # gets all the updates for a list of folders under revision control.
279 function checkout_list()
281 local list="$(uniquify $*)"
285 # turn repo list back into an array.
286 eval "repository_list=( ${REPOSITORY_LIST[*]} )"
290 for outer in "${repository_list[@]}"; do
291 # check the repository first, since it might be an absolute path.
292 if [[ $outer =~ /.* ]]; then
293 # yep, this path is absolute. just handle it directly.
294 if [ ! -d "$outer" ]; then continue; fi
296 test_or_die "running update on: $path"
299 for inner in $list; do
300 # add in the directory component to see if we can find the folder.
301 local path="$inner/$outer"
302 if [ ! -d "$path" ]; then continue; fi
304 test_or_die "running update on: $path"
310 restore_terminal_title
313 # provides a list of absolute paths of revision control directories
314 # that are located under the directory passed as the first parameter.
315 function generate_rev_ctrl_filelist()
317 local dir="$1"; shift
318 pushd "$dir" &>/dev/null
319 local dirhere="$( \cd "$(\dirname "$dir")" && /bin/pwd )"
320 local tempfile=$(mktemp /tmp/zz_checkins.XXXXXX)
322 local additional_filter
323 find $dirhere -follow -maxdepth $MAX_DEPTH -type d -iname ".svn" -exec echo {}/.. ';' >>$tempfile 2>/dev/null
324 find $dirhere -follow -maxdepth $MAX_DEPTH -type d -iname ".git" -exec echo {}/.. ';' >>$tempfile 2>/dev/null
325 # CVS is not well behaved like git and (now) svn, and we seldom use it anymore.
328 # see if they've warned us not to try checking in within vendor hierarchies.
329 if [ ! -z "NO_CHECKIN_VENDOR" ]; then
330 sed -i -e '/.*\/vendor\/.*/d' "$tempfile"
333 local sortfile=$(mktemp /tmp/zz_checkin_sort.XXXXXX)
334 sort <"$tempfile" >"$sortfile"
339 # iterates across a list of directories contained in a file (first parameter).
340 # on each directory name, it performs the action (second parameter) provided.
341 function perform_revctrl_action_on_file()
343 local tempfile="$1"; shift
344 local action="$1"; shift
348 while read -u 3 dirname; do
349 if [ -z "$dirname" ]; then continue; fi
350 pushd "$dirname" &>/dev/null
353 test_or_die "performing action $action on: $(pwd)"
358 restore_terminal_title