Permalink
Browse files

Replacing crappy scripts with the amazing git-subsplit

  • Loading branch information...
1 parent 3ec4ca0 commit 9f0a98cd9fab8744670b863c2800119703b67674 @igorw igorw committed Jul 14, 2012
Showing with 222 additions and 54 deletions.
  1. +1 −0 .gitignore
  2. +15 −0 scripts/do-split.sh
  3. +206 −0 scripts/git-subsplit.sh
  4. +0 −29 scripts/subtree-split.sh
  5. +0 −25 scripts/subtree-tag.sh
View
@@ -1 +1,2 @@
+.subsplit
vendor
View
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+GIT_SUBSPLIT=$(pwd)/$(dirname $0)/git-subsplit.sh
+
+$GIT_SUBSPLIT init https://github.com/react-php/react
+
+$GIT_SUBSPLIT update
+
+$GIT_SUBSPLIT publish "
+ src/React/EventLoop:git@github.com:react-php/event-loop.git
+ src/React/Stream/:git@github.com:react-php/stream.git
+ src/React/Socket/:git@github.com:react-php/socket.git
+ src/React/Http/:git@github.com:react-php/http.git
+ src/React/Espresso/:git@github.com:react-php/espresso.git
+" --heads=master
@@ -0,0 +1,206 @@
+#!/bin/bash
+#
+# git-subsplit.sh: Automate and simplify the process of managing one-way
+# read-only subtree splits.
+#
+# Copyright (C) 2012 Dragonfly Development Inc.
+#
+if [ $# -eq 0 ]; then
+ set -- -h
+fi
+OPTS_SPEC="\
+git subsplit init url
+git subsplit publish splits --heads=<heads> --tags=<tags> --splits=<splits>
+git subsplit update
+--
+h,help show the help
+q quiet
+n,dry-run do everything except actually send the updates
+work-dir directory that contains the subsplit working directory
+
+ options for 'publish'
+heads= only publish for listed heads instead of all heads
+no-heads do not publish any heads
+tags= only publish for listed tags instead of all tags
+no-tags do not publish any tags
+update fetch updates from repository before publishing
+"
+eval "$(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)"
+
+# We can run this from anywhere.
+NONGIT_OK=1
+
+PATH=$PATH:$(git --exec-path)
+
+. git-sh-setup
+
+ANNOTATE=
+QUIET=
+COMMAND=
+SPLITS=
+REPO_URL=
+WORK_DIR="${PWD}/.subsplit"
+HEADS=
+TAGS=
+DRY_RUN=
+
+subsplit_main()
+{
+ while [ $# -gt 0 ]; do
+ opt="$1"
+ shift
+ case "$opt" in
+ -q) QUIET=1 ;;
+ --heads) HEADS="$1"; shift ;;
+ --no-heads) NO_HEADS=1 ;;
+ --tags) TAGS="$1"; shift ;;
+ --no-tags) NO_TAGS=1 ;;
+ --update) UPDATE=1 ;;
+ -n) DRY_RUN="--dry-run" ;;
+ --dry-run) DRY_RUN="--dry-run" ;;
+ --) break ;;
+ *) die "Unexpected option: $opt" ;;
+ esac
+ done
+
+ COMMAND="$1"
+ shift
+
+ case "$COMMAND" in
+ init)
+ if [ $# -lt 1 ]; then die "init command requires url to be passed as first argument"; fi
+ REPO_URL="$1"
+ shift
+ subsplit_init
+ ;;
+ publish)
+ if [ $# -lt 1 ]; then die "publish command requires splits to be passed as first argument"; fi
+ SPLITS="$1"
+ shift
+ subsplit_publish
+ ;;
+ update)
+ subsplit_update
+ ;;
+ *) die "Unknown command '$COMMAND'" ;;
+ esac
+}
+say()
+{
+ if [ -z "$QUIET" ]; then
+ echo "$@" >&2
+ fi
+}
+
+subsplit_require_work_dir()
+{
+ if [ ! -e "$WORK_DIR" ]
+ then
+ die "Working directory not found at ${WORK_DIR}; please run init first"
+ fi
+
+ pushd "$WORK_DIR" >/dev/null
+}
+
+subsplit_init()
+{
+ if [ -e "$WORK_DIR" ]
+ then
+ die "Working directory already found at ${WORK_DIR}; please remove or run update"
+ fi
+
+ say "Initializing subsplit from origin (${REPO_URL})"
+
+ git clone -q "$REPO_URL" "$WORK_DIR" || die "Could not clone repository"
+}
+
+subsplit_publish()
+{
+ subsplit_require_work_dir
+
+ if [ -n "$UPDATE" ];
+ then
+ subsplit_update
+ fi
+
+ if [ -z "$HEADS" ] && [ -z "$NO_HEADS" ]
+ then
+ # If heads are not specified and we want heads, discover them.
+ HEADS="$(git ls-remote origin 2>/dev/null | grep "refs/heads/" | cut -f3- -d/)"
+ fi
+
+ if [ -z "$TAGS" ] && [ -z "$NO_TAGS" ]
+ then
+ # If tags are not specified and we want tags, discover them.
+ TAGS="$(git ls-remote origin 2>/dev/null | grep -v "^{}" | grep "refs/tags/" | cut -f3 -d/)"
+ fi
+
+ for SPLIT in $SPLITS
+ do
+ SUBPATH=$(echo "$SPLIT" | cut -f1 -d:)
+ REMOTE_URL=$(echo "$SPLIT" | cut -f2- -d:)
+ REMOTE_NAME=$(echo "$SPLIT" | git hash-object --stdin)
+
+ if ! git remote | grep "^${REMOTE_NAME}$" >/dev/null
+ then
+ git remote add "$REMOTE_NAME" "$REMOTE_URL"
+ fi
+
+
+ say "Syncing ${SUBPATH} -> ${REMOTE_URL}"
+
+ for HEAD in $HEADS
+ do
+ LOCAL_BRANCH="${REMOTE_NAME}-branch-${HEAD}"
+ say " - syncing branch ${HEAD}"
+ git branch -D "$LOCAL_BRANCH" >/dev/null 2>&1
+ git subtree split -q --prefix="$SUBPATH" --branch="$LOCAL_BRANCH" "origin/${HEAD}" >/dev/null 2>&1
+ if [ $? -eq 0 ]
+ then
+ PUSH_CMD="git push -q ${DRY_RUN} --force $REMOTE_NAME ${LOCAL_BRANCH}:${HEAD}"
+ if [ -n "$DRY_RUN" ]
+ then
+ echo \# $PUSH_CMD
+ $PUSH_CMD
+ else
+ $PUSH_CMD
+ fi
+ fi
+ done
+
+ for TAG in $TAGS
+ do
+ LOCAL_TAG="${REMOTE_NAME}-tag-${TAG}"
+ say " - syncing tag ${TAG}"
+ git branch -D "$LOCAL_TAG" >/dev/null 2>&1
+ git subtree split -q --annotate="${ANNOTATE}" --prefix="$SUBPATH" --branch="$LOCAL_TAG" "$TAG" >/dev/null 2>&1
+ if [ $? -eq 0 ]
+ then
+ PUSH_CMD="git push -q ${DRY_RUN} --force ${REMOTE_NAME} ${LOCAL_TAG}:refs/tags/${TAG}"
+ if [ -n "$DRY_RUN" ]
+ then
+ echo \# $PUSH_CMD
+ $PUSH_CMD
+ else
+ $PUSH_CM
+ fi
+ fi
+ done
+ done
+
+ popd >/dev/null
+}
+
+subsplit_update()
+{
+ subsplit_require_work_dir
+
+ say "Updating subsplit from origin"
+
+ git fetch -q origin
+ git fetch -q -t origin
+
+ popd >/dev/null
+}
+
+subsplit_main "$@"
@@ -1,29 +0,0 @@
-git clone https://github.com/react-php/react react-split
-cd react-split
-git checkout master
-git pull origin master
-
-git branch -D event-loop
-git subtree split --prefix=src/React/EventLoop/ -b event-loop
-git remote add event-loop git@github.com:react-php/event-loop.git
-git push -f event-loop event-loop:master
-
-git branch -D stream
-git subtree split --prefix=src/React/Stream/ -b stream
-git remote add stream git@github.com:react-php/stream.git
-git push -f stream stream:master
-
-git branch -D socket
-git subtree split --prefix=src/React/Socket/ -b socket
-git remote add socket git@github.com:react-php/socket.git
-git push -f socket socket:master
-
-git branch -D http
-git subtree split --prefix=src/React/Http/ -b http
-git remote add http git@github.com:react-php/http.git
-git push -f http http:master
-
-git branch -D espresso
-git subtree split --prefix=src/React/Espresso/ -b espresso
-git remote add espresso git@github.com:react-php/espresso.git
-git push -f espresso espresso:master
@@ -1,25 +0,0 @@
-# Clone all subtrees and create a tag in all of them
-# used for making a release
-#
-# Example usage:
-#
-# react/subtree-tag.sh v0.1.2
-
-VERSION="$@"
-
-if [ ! $VERSION ]; then
- echo "Usage: subtree-tag.sh VERSION"
- exit 1
-fi
-
-rm -rf react-tags
-mkdir react-tags
-cd react-tags
-
-for subtree in event-loop stream socket http espresso; do
- git clone git@github.com:react-php/$subtree.git
- cd $subtree
- git tag $VERSION
- git push origin $VERSION
- cd ..
-done

0 comments on commit 9f0a98c

Please sign in to comment.