Brian Silverman | 2e99d0b | 2015-12-17 01:59:58 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # A wrapper around git-subtree which first filters to remove the stuff from |
| 4 | # allwpilib we don't want. |
| 5 | # Also simplifies the interface a bunch to just what we need. |
| 6 | |
| 7 | # The implementation running `git filter-branch` over allwpilib's entire history |
| 8 | # isn't the fastest thing ever, but it's not all that bad. |
| 9 | |
| 10 | # Example: ./doc/allwpilib_subtree.sh add third_party/allwpilib_2016 \ |
| 11 | # https://usfirst.collab.net/gerrit/allwpilib master |
| 12 | |
| 13 | set -e |
| 14 | set -u |
| 15 | set -o pipefail |
| 16 | |
| 17 | if [ $# -ne 4 ]; then |
| 18 | echo "Usage: $0 add|pull|filter prefix remote ref" >&2 |
| 19 | exit 1 |
| 20 | fi |
| 21 | |
| 22 | COMMAND="$1" |
| 23 | PREFIX="$2" |
| 24 | REMOTE="$3" |
| 25 | REF="$4" |
| 26 | |
| 27 | git fetch "${REMOTE}" "${REF}" |
| 28 | |
| 29 | readonly REMOVE_DIRECTORIES="ni-libraries wpilibj wpilibjIntegrationTests gradle" |
| 30 | readonly TREE_FILTER="$(for d in ${REMOVE_DIRECTORIES}; do |
| 31 | echo "if [ -d $d ]; then git rm -rf $d; fi && " |
| 32 | done)" |
| 33 | git filter-branch --tree-filter "${TREE_FILTER}true" FETCH_HEAD |
| 34 | |
| 35 | FILTERED_REF="$(git rev-parse FETCH_HEAD)" |
| 36 | |
| 37 | if [[ "${COMMAND}" = "filter" ]]; then |
| 38 | echo "Filtered ref is ${FILTERED_REF}" |
| 39 | exit 0 |
| 40 | fi |
| 41 | |
| 42 | exec git subtree "${COMMAND}" --squash --prefix="${PREFIX}" "${FILTERED_REF}" |