git push origin foo:foo
{endcode}
to restore the branch.
+
+Here is the actual script:
+{code}
+#!/bin/bash
+
+GIT_DIR=/p/condor/repository/CONDOR_SRC.git
+export GIT_DIR
+
+bag_n_tag() {
+ trimmed_branch_name=$(echo $1 | sed 's|^refs/remotes/origin/||;s|^refs/heads/||')
+ origin_ref=refs/remotes/origin/${trimmed_branch_name}
+ cat <<TAGCOMMANDS
+git tag -a -m "Bag-n-tag branch ${trimmed_branch_name}" ${trimmed_branch_name}-tag "${origin_ref}" || { echo "Failed to create tag ${trimmed_branch_name}-tag"; exit 1; }
+git push origin tag ${trimmed_branch_name}-tag || { echo "Failed to push tag ${trimmed_branch_name}-tag to origin"; exit 1; }
+git push origin :refs/heads/${trimmed_branch_name} || { echo "Failed to delete branch ${trimmed_branch_name} from origin"; exit 1; }
+TAGCOMMANDS
+echo
+}
+
+ctime=$(date +'%s')
+ctime=$(( $ctime - 7776000 ))
+git for-each-ref refs/heads | while read sha1 type refname
+do
+# echo $refname
+ branchname=$(if test "$type" != "commit"; then
+ exit 0
+ fi
+# This should never happen, but being paranoid...
+ if echo "$refname" | grep -qE 'refs/tags'; then
+ exit 0;
+ fi
+ commitdate="$(git log --pretty=format:'%ct' -1 $sha1)"
+ if test "$commitdate" -gt "$ctime"; then
+ exit 0;
+ fi
+ echo $refname)
+ if test -n "$branchname"; then
+ bag_n_tag "$branchname"
+ fi
+done
+{endcode}