+ if verbose cd "$d0/$d"; then
+ verbose "$@"
+ cd "$d0"
+ fi
+ done
+ ;;
+ save-patches)
+ outfile=$1
+ patchdir=`mktemp -d -t save-patches.XXXXXX`
+ for d in $repos; do
+ enter "$d0/$d" verbose
+ git branch -v -v | cut -c 3- | {
+ i=0
+ while read -r BRANCH REV UPSTREAM TEXT; do
+ case "$UPSTREAM" in
+ \[*)
+ UPSTREAM=${UPSTREAM#\[}
+ UPSTREAM=${UPSTREAM%\]}
+ UPSTREAM=${UPSTREAM%:*}
+ TRACK=true
+ ;;
+ *)
+ UPSTREAM=origin/"`repobranch "$d"`"
+ TRACK=false
+ ;;
+ esac
+ if [ x"$REV" = x"->" ]; then
+ continue
+ fi
+ if git format-patch -o "$patchdir/$i" "$UPSTREAM".."$BRANCH"; then
+ echo "$d" > "$patchdir/$i/info.txt"
+ echo "$BRANCH" >> "$patchdir/$i/info.txt"
+ echo "$UPSTREAM" >> "$patchdir/$i/info.txt"
+ echo "$TRACK" >> "$patchdir/$i/info.txt"
+ i=$(($i+1))
+ else
+ rm -rf "$patchdir/$i"
+ fi
+ done
+ }
+ done
+ ( cd "$patchdir" && tar cvzf - . ) > "$outfile"
+ rm -rf "$patchdir"
+ ;;
+ restore-patches)
+ infile=$1
+ patchdir=`mktemp -d -t restore-patches.XXXXXX`
+ ( cd "$patchdir" && tar xvzf - ) < "$infile"
+ # detach the head
+ for P in "$patchdir"/*/info.txt; do
+ D=${P%/info.txt}
+ exec 3<"$P"
+ read -r d <&3
+ read -r BRANCH <&3
+ read -r UPSTREAM <&3
+ read -r TRACK <&3
+ verbose git checkout HEAD^0
+ verbose git branch -D "$BRANCH"
+ if [ x"$TRACK" = x"true" ]; then
+ verbose git checkout --track -b "$BRANCH" "$UPSTREAM"
+ else
+ verbose git branch -b "$BRANCH" "$UPSTREAM"
+ fi
+ verbose git am "$D"
+ done
+ rm -rf "$patchdir"
+ ;;
+ admin-merge)
+ if [ "$#" = 1 ]; then
+ set -- "${1%%/*}" "${1#*/}"
+ fi
+ for d in $repos; do
+ enter "$d0/$d" verbose
+ git rev-parse "$1/$2" || continue
+ # 1. review
+ {
+ git log HEAD.."$1/$2"
+ git diff HEAD..."$1/$2"
+ } | less
+ if yesno "Merge \"$1/$2\" into `git symbolic-ref HEAD` of $d?"; then
+ git merge "$1/$2"
+ if "$SELF" compile && yesno "Still merge \"$1/$2\" into `git symbolic-ref HEAD` of $d? Maybe you want to test first."; then
+ git push origin HEAD
+ git push "$1" :"$2"
+ else
+ git reset --hard HEAD@{1}
+ fi
+ fi
+ done
+ ;;
+ admin-merge-2)
+ t=`mktemp`
+ for d in $repos; do
+ enter "$d0/$d" verbose
+ for ref in `git for-each-ref --format='%(refname)' refs/remotes/origin/`; do
+ case "${ref#refs/remotes/origin/}" in
+ "`repobranch "$d"`")
+ continue
+ ;;
+ HEAD|master)
+ continue
+ ;;
+ esac
+ echo "$ref"
+ if git notes --ref "refs/notes/admin-merge" show "$ref" 2>/dev/null; then
+ echo "Not merging, already had this one"
+ elif yesno "Branch \"$ref\" may want to get merged. Do it?" '{ git log HEAD.."$ref"; git diff HEAD..."$ref"; } | less'; then
+ org=`git rev-parse HEAD`
+ if ! git merge "$ref" 2>&1 | tee "$t"; then
+ git reset --hard "$org"
+ git notes --ref "refs/notes/admin-merge" add -m "Merge failed:
+`cat "$t"`" "$ref"
+ elif ! "$SELF" compile 2>&1 | tee "$t"; then
+ git reset --hard "$org"
+ git notes --ref "refs/notes/admin-merge" add -m "Compile failed:
+`cat "$t"`" "$ref"
+ elif ! yesno "Still merge \"$ref\" into `git symbolic-ref HEAD` of $d? Maybe you want to test first."; then
+ git reset --hard "$org"
+ git notes --ref "refs/notes/admin-merge" add "$ref"
+ else
+ git push origin HEAD
+ if yesno "Delete original branch \"$ref\"?"; then
+ git push origin :"${ref#refs/remotes/origin/}"
+ fi
+ fi
+ else
+ git notes --ref "refs/notes/admin-merge" add "$ref"
+ fi
+ done