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 | |
Brian Silverman | e48dbc1 | 2017-02-04 20:06:29 -0800 | [diff] [blame] | 10 | # Example: `./doc/allwpilib_subtree.sh add third_party/allwpilib_2017 https://github.com/wpilibsuite/allwpilib master` |
Brian Silverman | 2e99d0b | 2015-12-17 01:59:58 -0500 | [diff] [blame] | 11 | |
| 12 | set -e |
| 13 | set -u |
| 14 | set -o pipefail |
| 15 | |
| 16 | if [ $# -ne 4 ]; then |
Brian Silverman | faba72c | 2016-02-20 20:36:04 -0500 | [diff] [blame] | 17 | echo "Usage: $0 add|merge|filter prefix remote ref" >&2 |
Brian Silverman | 2e99d0b | 2015-12-17 01:59:58 -0500 | [diff] [blame] | 18 | exit 1 |
| 19 | fi |
| 20 | |
| 21 | COMMAND="$1" |
| 22 | PREFIX="$2" |
| 23 | REMOTE="$3" |
| 24 | REF="$4" |
| 25 | |
| 26 | git fetch "${REMOTE}" "${REF}" |
| 27 | |
Brian Silverman | e48dbc1 | 2017-02-04 20:06:29 -0800 | [diff] [blame] | 28 | readonly REMOVE_DIRECTORIES=( |
| 29 | ni-libraries |
| 30 | wpilibj |
| 31 | wpilibjIntegrationTests |
| 32 | gradle |
| 33 | simulation |
| 34 | myRobot |
| 35 | myRobotCpp |
| 36 | gen |
| 37 | test-scripts |
| 38 | ) |
| 39 | readonly TREE_FILTER="$(for d in "${REMOVE_DIRECTORIES[@]}"}; do |
Brian Silverman | 2e99d0b | 2015-12-17 01:59:58 -0500 | [diff] [blame] | 40 | echo "if [ -d $d ]; then git rm -rf $d; fi && " |
| 41 | done)" |
| 42 | git filter-branch --tree-filter "${TREE_FILTER}true" FETCH_HEAD |
| 43 | |
| 44 | FILTERED_REF="$(git rev-parse FETCH_HEAD)" |
| 45 | |
| 46 | if [[ "${COMMAND}" = "filter" ]]; then |
| 47 | echo "Filtered ref is ${FILTERED_REF}" |
| 48 | exit 0 |
| 49 | fi |
| 50 | |
| 51 | exec git subtree "${COMMAND}" --squash --prefix="${PREFIX}" "${FILTERED_REF}" |