blob: aa83d0ce3993b20a4c6a23cdf006d4ebe6a0b4be [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
10# Example: ./doc/allwpilib_subtree.sh add third_party/allwpilib_2016 \
11# https://usfirst.collab.net/gerrit/allwpilib master
12
13set -e
14set -u
15set -o pipefail
16
17if [ $# -ne 4 ]; then
Brian Silvermanfaba72c2016-02-20 20:36:04 -050018 echo "Usage: $0 add|merge|filter prefix remote ref" >&2
Brian Silverman2e99d0b2015-12-17 01:59:58 -050019 exit 1
20fi
21
22COMMAND="$1"
23PREFIX="$2"
24REMOTE="$3"
25REF="$4"
26
27git fetch "${REMOTE}" "${REF}"
28
29readonly REMOVE_DIRECTORIES="ni-libraries wpilibj wpilibjIntegrationTests gradle"
30readonly TREE_FILTER="$(for d in ${REMOVE_DIRECTORIES}; do
31 echo "if [ -d $d ]; then git rm -rf $d; fi && "
32done)"
33git filter-branch --tree-filter "${TREE_FILTER}true" FETCH_HEAD
34
35FILTERED_REF="$(git rev-parse FETCH_HEAD)"
36
37if [[ "${COMMAND}" = "filter" ]]; then
38 echo "Filtered ref is ${FILTERED_REF}"
39 exit 0
40fi
41
42exec git subtree "${COMMAND}" --squash --prefix="${PREFIX}" "${FILTERED_REF}"