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