...
1#!/bin/bash
2
3# Copyright 2017 The Kubernetes Authors.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17
18# overall flow
19# 1. fetch the current level of k8s.io/kubernetes
20# 2. check out the k8s.io/kubernetes HEAD into a separate branch
21# 3. rewrite the history on that branch to *only* include staging/src/k8s.io/kube-aggregator
22# 4. locate all commits between the last time we sync'ed and now
23# 5. switch back to the starting branch
24# 6. for each commit, cherry-pick it (which will keep authorship) into current branch
25# 7. update metadata files indicating which commits we've sync'ed to
26
27set -e
28
29ROOT=$(dirname "${BASH_SOURCE}")/..
30dir=$(mktemp -d "${TMPDIR:-/tmp/}$(basename 0).XXXXXXXXXXXX")
31
32git remote add upstream-kube git@github.com:kubernetes/kubernetes.git || true
33git fetch upstream-kube
34
35currBranch=$(git rev-parse --abbrev-ref HEAD)
36previousKubeSHA=$(cat kubernetes-sha)
37previousBranchSHA=$(cat filter-branch-sha)
38
39git branch -D kube-sync || true
40git checkout upstream-kube/master -b kube-sync
41git reset --hard upstream-kube/master
42newKubeSHA=$(git log --oneline --format='%H' kube-sync -1)
43
44# this command rewrite git history to *only* include staging/src/k8s.io/kube-aggregator
45git filter-branch -f --subdirectory-filter staging/src/k8s.io/kube-aggregator HEAD
46
47newBranchSHA=$(git log --oneline --format='%H' kube-sync -1)
48git log --no-merges --format='%H' --reverse ${previousBranchSHA}..HEAD > ${dir}/commits
49
50git checkout ${currBranch}
51
52# we must reset Godeps.json to what it looked like BEFORE the last vendor sync so that any
53# new Godep.json changes from k8s.io/kubernetes will apply cleanly. Since its always auto-generated
54# it doesn't matter that we're removing it
55lastResyncCommit=$(git rev-list -n 1 --grep "sync: resync vendor folder" HEAD)
56cleanGodepJsonCommit=$(git rev-list -n 1 ${lastResyncCommit}^)
57git checkout ${cleanGodepJsonCommit} Godeps/Godeps.json
58git commit -m "sync: reset Godeps.json" -- Godeps/Godeps.json
59
60while read commitSHA; do
61 echo "working ${commitSHA}"
62 git cherry-pick ${commitSHA}
63done <${dir}/commits
64
65# update the vendored godeps
66${ROOT}/hack/godep-deps.sh
67
68# track the k8s.io/kubernetes commit SHA so we can always determine which level of kube this repo matches
69# track the filtered branch commit SHA so that we can determine which commits need to be picked
70echo ${newKubeSHA} > kubernetes-sha
71echo ${newBranchSHA} > filter-branch-sha
72git commit -m "sync(k8s.io/kubernetes): ${newKubeSHA}" -- kubernetes-sha filter-branch-sha
View as plain text