hack/move-upstream.sh
ac1086ba
 #!/bin/bash
 
 # See HACKING.md for usage
3fc0cf9b
 # To apply all the kube UPSTREAM patches to a kubernetes git directory, you can
 #  1. Set UPSTREAM_DIR for your kube working directory
 #  2. Set TARGET_BRANCH for the new branch to work in
 #  3. In your kube git directory, set the current branch to the level to want to apply patches to
 #  4. Run `hack/move-upstream.sh master...<commit hash you want to start pulling patches from>`
614bf6cc
 source "$(dirname "${BASH_SOURCE}")/lib/init.sh"
ac1086ba
 
cf28c106
 repo="${UPSTREAM_REPO:-k8s.io/kubernetes}"
 package="${UPSTREAM_PACKAGE:-pkg/api}"
 
2aa915b2
 patch="${TMPDIR:-/tmp}/patch"
439fde0a
 rm -rf "${patch}"
 mkdir -p "${patch}"
2aa915b2
 relativedir="${UPSTREAM_REPO_LOCATION:-../../../${repo}}"
cf28c106
 if [[ ! -d "${relativedir}" ]]; then
   echo "Expected ${relativedir} to exist" 1>&2
ac1086ba
   exit 1
 fi
 
 if [[ -z "${NO_REBASE-}" ]]; then
2dc39df8
   if [[ "${package}" != "." ]]; then
     out="${repo}/${package}"
   else
     out="${repo}"
   fi
   lastrev="$(go run ${OS_ROOT}/tools/godepversion/godepversion.go ${OS_ROOT}/Godeps/Godeps.json ${out})"
ac1086ba
 fi
 
3fc0cf9b
 branch="${TARGET_BRANCH:-$(git rev-parse --abbrev-ref HEAD)}"
ac1086ba
 selector="origin/master...${branch}"
 if [[ -n "${1-}" ]]; then
   selector="$1"
 fi
 
cf28c106
 echo "++ Generating patch for ${selector} onto ${lastrev} ..." 2>&1
439fde0a
 index=0
f0eadcca
 for commit in $(git log --no-merges --format="%H" --reverse "${selector}" -- "vendor/${repo}/"); do
   git format-patch --raw --start-number=${index} --relative="vendor/${repo}/" "${commit}^..${commit}" -o "${patch}"
439fde0a
   let index+=10
 done
 
 # remove all commits that had no entries
 find "${patch}" -type f -size 0 -exec rm {} \;
ac1086ba
 
cf28c106
 pushd "${relativedir}" > /dev/null
ac1086ba
 os::build::require_clean_tree
 
 # create a new branch
cf28c106
 git checkout -b "${branch}" "${lastrev}"
ac1086ba
 
 # apply the changes
439fde0a
 if ! git am -3 --ignore-whitespace ${patch}/*.patch; then
ac1086ba
   echo 2>&1
439fde0a
   echo "++ Patches do not apply cleanly, continue with 'git am' in ${relativedir}" 2>&1
ac1086ba
   exit 1
 fi
 
 echo 2>&1
439fde0a
 echo "++ All patches applied cleanly upstream" 2>&1